Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDR EnvMap example with high quality, flexible PMREM Generator. #8237

Merged
merged 36 commits into from
Feb 27, 2016

Conversation

bhouston
Copy link
Contributor

I've cleaned up the earlier PR #7902 from @spidersharma03 that addressed issue #7402 in a number of ways:

  • it now uses the encodings on the textures for both input encodings and output encodings (which has been merged into dev except for the output encoding PR Output encoding #8232.)
  • it automatically sets appropriate encodings, and filters based on designed texture type, such for Unsigned Byte it uses RGBE, where as for Float and Half it uses LinearRGB.
  • I have pulled out a new file to make THREE.toHalf() accessible to others.
  • I have pulled out a THREE.Encoding class to allow for easy CPU-based encoding/decoding, although it only contains @spidersharma03's RGBE encoders for float and half.

To refresh from the other, this is based upon @spidersharma03's real-time filtered cubemap generator, that also creates single texture cube map hierarchy with both roughness levels and mipmaps. It is pretty awesome.

I do believe this is the critical missing piece (e.g. #7402) that completes @WestLangley's Standard material implementation.

The results this PR products look like this and it should look like this on all browsers (if there are not any bugs):

image

Interactive:

http://ci.threejs.org/api/pullrequests/8237/examples/index.html#webgl_materials_envmaps_hdr

PS. Anyone know how to get shadows working when using the effect compositor? There should be shadows here but I do not see any.

Ben Houston added 29 commits February 12, 2016 13:36
cube_uv_reflection map shader.  (written by @spidersharma03, modified by @bhouston)
…lors are not encoded and we need to get perfect blends.
# Conflicts:
#	src/renderers/shaders/ShaderLib.js
#	src/renderers/webgl/WebGLPrograms.js
@WestLangley
Copy link
Collaborator

Many thanks to @bhouston and @spidersharma03 for their work on improving MeshStandardMaterial!

Which PRs do you now want merged and which ones are outdated?

Also, what is still on the near-term to-do list, as far as you are concerned?

@bhouston
Copy link
Contributor Author

@WestLangley, this PR contains the non-merged PR #8232. Outstanding issues is to figure out if this new code, of which there is a fair bit, works on all devices. It is designed to render PBR with HDR IBL maps on all devices that are WebGL 1.0 compliant without any extensions.

I think it needs to auto-fallback to UnsignedByte when Float / Half textures are not available - which it does not do. We also have to test the UnsignedByte RGBE workflow to ensure there are no artifacts.

UPDATE: I was able to modify the PR so it always uses RGBE with UnsignedByte and it always looks good. Thus the main issue in this comment is addressed.

@bhouston
Copy link
Contributor Author

This PR does seem to work on Firefox, Chrome and IE with equivalent results:

image

It also works well on Chrome on OSX. Now I need to check mobile browsers, I suspect there will be some complications.

@bhouston
Copy link
Contributor Author

The latest changes to this PR ensure that it looks good and runs at fast frame rates on Nexus 5 and a Samsung Galaxy TabPRO as well as Ubuntu 15.04. I still need to test this on the iPad and iPhone as well as a few more mobile devices.

@bhouston
Copy link
Contributor Author

BTW @MiiBond this PR may be of interest.

@bhouston
Copy link
Contributor Author

BTW @spite, this PR may be of interest as well.

@bhouston
Copy link
Contributor Author

@WestLangley @mrdoob This PR also re-enables indirect light probe irradiance when you use it with the PMREM generated CubeUV layout because this PR gets rid of the seams on all devices:

https://github.com/mrdoob/three.js/pull/8237/files#diff-29f010d669a36f5263d5351f4702e64fR104

:)

@mrdoob
Copy link
Owner

mrdoob commented Feb 27, 2016

Super sweet! I can confirm that it works on iOS too! 😁

mrdoob added a commit that referenced this pull request Feb 27, 2016
HDR EnvMap example with high quality, flexible PMREM Generator.
@mrdoob mrdoob merged commit c2b8ba5 into mrdoob:dev Feb 27, 2016
@mrdoob
Copy link
Owner

mrdoob commented Feb 27, 2016

Many thanks!

@mrdoob
Copy link
Owner

mrdoob commented Feb 27, 2016

PS. Anyone know how to get shadows working when using the effect compositor? There should be shadows here but I do not see any.

They work if you enabled them 2cb798d 😉

@spite
Copy link
Contributor

spite commented Feb 27, 2016

This looks great! Congratulations! 👍

With HDR looks even better than what i was testing! https://www.clicktorelease.com/tmp/snapshot-fsk2-big.jpg

@bhouston
Copy link
Contributor Author

@spite, nice! Are those beautiful graphics using your code or this new code?

@bhouston
Copy link
Contributor Author

@spite, one need thing about the approach in this PR is that it requires zero extensions, while giving what should be near perfect results.

@spite
Copy link
Contributor

spite commented Feb 29, 2016

@bhouston those are snapshots from my tests, also without extensions. very cool stuff you've got there!

renderTarget.texture.minFilter = this.sourceTexture.minFilter;
renderTarget.texture.magFilter = this.sourceTexture.magFilter;
this.cubeLods.push( renderTarget );
size = Math.max( 16, size / 2 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benaadams @spidersharma03 Any particular reason the mipmaps are not any smaller than 16x16? Should this be configurable so that PMREMGenerator can be used as a general purpose cube map filtering tool? Right now it seems tailored toward the UV Packer (which may not be necessary in WebGL2).

@phtaylor
Copy link

phtaylor commented Mar 8, 2016

great stuff Ben!

@spidersharma03
Copy link
Contributor

@mattdesl @mrdoob, Restriction to 16x16 was done as there were artifacts with roughness maps lower than 16x16. The line::
this.numLods = Math.log2( cubeTextureLods[ 0 ].width ) - 2;
is used to calculate the number of roughness levels(0-1 range), for a given texture size. Yeah, right now it is tailored for packed CubeUV in a way that the above number of roughness levels are fitted in the cubeuv texture. However I created an example(attached here)where cube textures are directly used instead of cube uv. This is based on an older version, but I guess, should give some hints on how to use the convolved cubemaps directly. This example simply was made to test the convolved cube maps. Though, to be able to use the cube maps directly, all of them should be passed to the shader, and interpolation between two levels should be done inside the shader.
PMREM_Test.txt

Regarding the multiplication by 0.9 and some other stuff in the code::
More thought and work is needed here. Right now it's a kind of a hack to use the previously convolved map to convolve the current one. I tried to use the original map to convolve all the lods, but for many textures(specially the high frequency) even a high number of samples(1024) dosen't lead to satisfactory results.
By using the previous convolved maps, a lower number of samples are generally sufficient, however the math goes wrong as the distribution function tries to sample a larger area than what it should be. So I simply scaled the roughness by 0.9(totally empirical) to try to visually match the original result. The condition "if(i <5)" is also an attemt to make the result match the original result. This method requires the most amount of thinking I guess.
We will put more comments in the code where explanation is needed.

@bhouston bhouston deleted the pmrem4 branch March 14, 2016 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants