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

Added RGBM texture example #16432

Merged
merged 2 commits into from
May 15, 2019
Merged

Added RGBM texture example #16432

merged 2 commits into from
May 15, 2019

Conversation

WestLangley
Copy link
Collaborator

@WestLangley WestLangley commented May 14, 2019

As suggested in #16420 (comment).

Maybe we can convert memorial.hdr to RGBM16... EDIT: Done! Thanks @bhouston

@mrdoob
Copy link
Owner

mrdoob commented May 14, 2019

Maybe we can convert memorial.hdr to RGBM16...

Yeah, that'd help. I have yet to understand how to do it though.

@mrdoob mrdoob added this to the r105 milestone May 14, 2019
@looeee
Copy link
Collaborator

looeee commented May 14, 2019

Maybe we can convert memorial.hdr to RGBM16...

Yeah, that'd help. I have yet to understand how to do it though.

According to @bhouston #10652 (comment):

All the tools for converting between Linear/sRGB/RGBM/RGBD/RGBE/LogLUV, etc are in Three.JS. On textures you can set the encoding that it will use when reading that texture. On render targets you can set the encoding it will use when writing to that render target. To do a conversion between any encoding just load the source into a texture with its current encoding set properly, and then render it to a render target with the target encoding set. Then read the render target back and save as a bitmat and you've converted your stuff.

I also have yet to understand how that works though. As far as I can see RGBE -> RGBM16 is the most important of these conversions. Perhaps we could add an example showing how to do that?

@bhouston
Copy link
Contributor

bhouston commented May 14, 2019

I also have yet to understand how that works though. As far as I can see RGBE -> RGBM16 is the most important of these conversions. Perhaps we could add an example showing how to do that?

One can set the encoding on a texture, and then set it to one of a select map inputs on material: map, envMap, mapCap, emissive. During shader creation it will check for the encoding of that texture map and auto-decode from its encoding to linear:

mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),

There is also the concept of the output texture. Normally it is just a simplfed gammaOutput, but if you are writing to a render target texture, it will read the encoding of that texture and use that to encode the linear result into the output encoding.

outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),

Thus all transcoding of texture formats is done automatically by the program compiler via code injection. The injectors are here:

( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',

@WestLangley
Copy link
Collaborator Author

Maybe we can convert memorial.hdr to RGBM16...

I was referring to converting the file memorial.hdr to a PNG-formatted file with RGBM encoding.

@bhouston
Copy link
Contributor

RGBM16 PNG of the Memorial image:

memorial rgbm16

@WestLangley
Copy link
Collaborator Author

@bhouston Sweet! It works perfectly. Thanks!

@WestLangley
Copy link
Collaborator Author

@bhouston Since that image is so transparent as a PNG, RGBM7 may have been better if all the alphas are less than 0.5. I am not recommending a change, though. Mostly curious.

What utility did you use to convert that file?

@bhouston
Copy link
Contributor

What utility did you use to convert that file?

Unfortunately some closed source code in clara.io. But given that Three.JS has an exr and an hdr loader and the ability to save the render buffer as an image writing a generic conversion tool that can import these and save to any of our supported encodings isn't a lot of work -- it could be a new three.js example.

@mrdoob mrdoob merged commit d0a3f9a into mrdoob:dev May 15, 2019
@mrdoob
Copy link
Owner

mrdoob commented May 15, 2019

Thanks!

@WestLangley WestLangley deleted the dev_rgbm_texture branch May 16, 2019 00:05
@looeee
Copy link
Collaborator

looeee commented May 16, 2019

it could be a new three.js example.

Yes, that's what I was suggesting here.

It's great to have the ability to use RGBM16 textures, but I have yet to find any DCC tools that can create them. On the other hand, there's loads of free .HDR textures available, and they are relatively easy to create.

If we had an example where users can drag and drop .HDR textures and get RGBM16 pngs out, that would make this feature useful to a lot more people.

@WestLangley
Copy link
Collaborator Author

@mrdoob Since this PR replaces memorial.png with a file having a different encoding, webgl_hdr.html is no longer relevant and can be removed.

@TimvanScherpenzeel
Copy link

It's great to have the ability to use RGBM16 textures, but I have yet to find any DCC tools that can create them. On the other hand, there's loads of free .HDR textures available, and they are relatively easy to create.

Perhaps you could modify this IBL converter (MIT) https://github.com/oframe/ibl-converter

It has quite a nice drag and drop interface: https://oframe.github.io/ibl-converter/

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.

5 participants