Runtime Textures as Shader Data

Node-based Shader Editor

Runtime Textures as Shader Data

Postby Rob_Positomic » 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:
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) :)
Rob_Positomic
 
Posts: 5
Joined: Fri Jan 19, 2018 2:05 am

Re: Runtime Textures as Shader Data

Postby Amplify_Borba » Fri Jan 19, 2018 4:50 pm

Hello Rob, thank you for getting in touch and for your support!

Do you have sRGB (Color Texture) toggled on your texture?

image.png
image.png (5.8 KiB) Viewed 1596 times


I've tested using both Gamma to Linear and Linear to Gamma nodes and the results are consistent. Would it be possible for you to share a sample with us so that we can further investigate this on our side?

HeightBlend.jpg
HeightBlend.jpg (244.3 KiB) Viewed 1596 times


Regarding height blend, it's mostly used for texture layering as per the above image. We're going to need some further information regarding what you're intending to do and what are the expected results, preferably together with a sample which would be particularly useful in order for us to best help you.

Looking forward to your reply!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Runtime Textures as Shader Data

Postby Rob_Positomic » Sat Jan 20, 2018 2:54 am

Hi Borba,

Really appreciate your interest and response.

The texture that holds the heightmaps is generated when the game loads and is passed to the shader (into a texture object node/propery). It currently blends together two heightmaps, one using red values, and the other using blue to create the following texture. So I cant interact with its properties beforehand.

dataTexture.png
dataTexture.png (206.92 KiB) Viewed 1593 times


By default, tt seems to be using sRGB, going by the attributes at the bottom. I couldn't find the sRGB option in the script, so I tried using various TextureFormats as well (ARGB32 and RGBA32 off the top of my head) to ensure sRGB is applied, but the results didn't differ.

Linear to Gamma does seem to produce expected results; but I'm not sure given the floating point operations if the number I sent in (say 0.5f for something halfway) is the same number that comes out the other end, after it is 'converted' and then 'unconverted'. I've been looking for a node that I can use to debug that will just display the value it is passed but cant seem to find one. I'm aiming to avoid using "Linear to Gamma" so I have more confidence in the values.

Thank you for the HeightMap example, it looks very useful :) I would suggest to include it in the Wiki.

Best Regards,
-Rob.
Rob_Positomic
 
Posts: 5
Joined: Fri Jan 19, 2018 2:05 am

Re: Runtime Textures as Shader Data

Postby Amplify_Borba » Mon Jan 22, 2018 12:48 pm

Thank you for the additional information, have you run into any specific issues since we last spoke?

We'll definitely update the wiki with that screenshot as soon as possible.

Regarding displaying the passed value, it really depends on how the shader operates, it can be more complex than expected. Is there anything specific we could assist you with? I would be happy to help!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am


Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 73 guests

cron