Jump to content
  • Advertisement
Sign in to follow this  
LTKeene

Accessing R32F from within shader

This topic is 3068 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, first a big Thanks to everyone on this forum. It's been really helpful. Now, on to the question: I've been accessing texture colors from within my pixel shader by using: InputColor = tex2D(theTextureSampler, theTextureCoords); I now need to pass some 32-bit floats to the shader to use as a lookup table and it's my understanding that I should use an R32F texture that I have loaded with the necessary values. How does one go about accessing the values in an R32F texture from within the shader program? I've looked online and haven't been able to find the answer so far. Thanks in advance. -L

Share this post


Link to post
Share on other sites
Advertisement
Do a texture look up like for an ordinary ARGB texture, but only read the red channel: float color = tex2D(theTextureSampler, theTextureCoords).r;

Share this post


Link to post
Share on other sites
I see, that's straight forward. I've written colors to a texture but never raw floats. Now that I'm looking at how to actually write the data to the texture, I see it's not as straight forward as I anticipated. Is this the correct approach?:



// Create texture/surface:
LUTtexture = new Texture(device, width, height, 1, 0, Format.R32F, Pool.Managed);
Surface LUTsurface = LUTtexture.GetSurfaceLevel(0);
SurfaceDescription desc = LUTtexture.GetLevelDescription(0);

// Lock texture for writing. Use overload without a "Rectangle" argument to indicate entire surface is to be locked, and use "LockFlags.Discard" since the entire surface is to be overwritten with the LUT data:
float[] textureData = (float)LUTsurface.LockRectangle(LockFlags.Discard);

textureData[0] = FloatValues[0];
textureData[1] = FloatValues[1];
etc...

LUTsurface.UnlockRectangle();


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!