Runtime Textures as Shader Data
Posted: Fri Jan 19, 2018 2:31 am
Hi everyone,
I was unable to find any posts about this topic, but part of that may be because I'm new to Shaders and probably don't know the right terminology
I am attempting attempting to create a Shader that has a texture property populated when my game loads. This texture is being used effectively as a 2 dimensional array of information (a "data texture" for lack of a better term). Within the Shader, I pass in co-ordinates for a specific "index" in this array, separate R,G,B and A values which are then used as inputs in other areas of the shader; for example - blending of two textures, through a Lerp.
I had managed to get a working prototype using a custom expression, producing expected results. However, I then experimented with changing the color space of the project from Gamma to Linear. This had the expected effect of changing the aesthetics - but had the unexpected effect of somehow changing the output of what was returned from the data texture. In debugging, the lerp still operates; but at different thresholds - which seems to indicate that the value i'm getting from the data texture has been altered (keeping in mind the only thing that has changed is the color space). Also, eyeballing the generated texture in the properties of the material seem equivalent (at least to my untrained eye).
So a few questions:
- is color space the culprit; its the only thing I've changed but there may be other factors I'm unaware of? (edit: I've found the Linear to Gamma node which seems to correct the problem and indicate there's something in switching between these color spaces that modifies the values of the float4 i'm getting out of this code:
- if it is; is there a way to stop color space entirely from affecting a texture (seeing how Linear has affected the calculations, I now wonder if Gamma would effect them in other ways I have not observed).
- is there a better or more efficient way to achieve the same functionality I've overlooked - for example; I've seen the HeighMapMapTextureBlend node; which I suspect might be able to apply; however I do not understand how it works (the wiki page could benefit from an example for newbies like me)
I was unable to find any posts about this topic, but part of that may be because I'm new to Shaders and probably don't know the right terminology
I am attempting attempting to create a Shader that has a texture property populated when my game loads. This texture is being used effectively as a 2 dimensional array of information (a "data texture" for lack of a better term). Within the Shader, I pass in co-ordinates for a specific "index" in this array, separate R,G,B and A values which are then used as inputs in other areas of the shader; for example - blending of two textures, through a Lerp.
I had managed to get a working prototype using a custom expression, producing expected results. However, I then experimented with changing the color space of the project from Gamma to Linear. This had the expected effect of changing the aesthetics - but had the unexpected effect of somehow changing the output of what was returned from the data texture. In debugging, the lerp still operates; but at different thresholds - which seems to indicate that the value i'm getting from the data texture has been altered (keeping in mind the only thing that has changed is the color space). Also, eyeballing the generated texture in the properties of the material seem equivalent (at least to my untrained eye).
So a few questions:
- is color space the culprit; its the only thing I've changed but there may be other factors I'm unaware of? (edit: I've found the Linear to Gamma node which seems to correct the problem and indicate there's something in switching between these color spaces that modifies the values of the float4 i'm getting out of this code:
- Code: Select all
float4 sample = tex2D(dataTexture, coord);
- if it is; is there a way to stop color space entirely from affecting a texture (seeing how Linear has affected the calculations, I now wonder if Gamma would effect them in other ways I have not observed).
- is there a better or more efficient way to achieve the same functionality I've overlooked - for example; I've seen the HeighMapMapTextureBlend node; which I suspect might be able to apply; however I do not understand how it works (the wiki page could benefit from an example for newbies like me)