Sign in to follow this  

Accessing R32F from within shader

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
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];


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this