Sign in to follow this  
stona

problems with texture format D3DFMT_G16R16

Recommended Posts

i am passing a texture (type: D3DFMT_G16R16) to the pixel shader which is supposed to store the value 0.3 in the green channel of some texels. here is an excerpt from the pixel shader: PS_OUTPUT Main (PS_INPUT input) { ... output.accumulation.g = 0.3f; output.accumulation.r = 0.0f; ... return output; } in the next run of the pixel shader i pass the same texture (where some of the texels are set to 0.3) to the pixel shader again. lets say for example,depending if the current texel's value is 0.3, the output color of the pixel shader should be green, otherwise black. PS_OUTPUT Main (PS_INPUT input) { ... float4 a = tex2D(ReadTex, input.coords); ... if (a.g == 0.3f) { c.g = 1.0f; } else { // set c to black } return c; } MY PROBLEM is now, that the value in the texel, when comparing it with 0.3f, is not exactly 0.3f after reading it, it is somewhere between 0.299 and 0.3. so the pixel shader never gets to the point where he sets the color to black.. I also set the "Nearest point sampling" for this texture: pDevice->SetTexture (2, pReadTex); pDevice->SetSamplerState (2, D3DSAMP_MAGFILTER, D3DTEXF_POINT); pDevice->SetSamplerState (2, D3DSAMP_MINFILTER, D3DTEXF_POINT); does anybody know why? or have any idea? thanks .. [Edited by - stona on March 19, 2006 7:54:39 PM]

Share this post


Link to post
Share on other sites
It's generally considered taboo to compare two floats for equality, whether on the cpu or gpu. floats are subject to floating small errors, which is why you are getting .299. Basically you need to consider all the values in a small range, so for example:

if (a.g - .3 < .00001) {
c.g = 1.0f;
} else {
// set c to black
}

Share this post


Link to post
Share on other sites
Quote:
Original post by jamesw
It's generally considered taboo to compare two floats for equality, whether on the cpu or gpu. floats are subject to floating small errors, which is why you are getting .299. Basically you need to consider all the values in a small range, so for example:

if (a.g - .3 < .00001) {
c.g = 1.0f;
} else {
// set c to black
}


ok.. thats true.. but is there a way to create a texture that does not use floating point values to store the color value?

so that i could use a texel to store a value somewhere between 0 and 65535 for the r and g channel in that texture? so integer values instead of float values?

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
Considered D3DFMT_G16R16? [smile]

Alternatively pick a format from this list..

hth
Jack


yes.. first of all i wanted to use D3DFMT_L16.. but this one is not supported by my graphics adapter.. so i want to use the red channel from D3DFMT_G16R16 or D3DFMT_R32F instead..

the problem i want so solve is, that i want to store an counting variable in each texel (counting value between 0 and 4000).

since i have 4000 values, i calculated 1/4000 = 0.00025 (which would represent incrementing the count by "one"), so every time i run through the pixel shader i would do following on some texels:

struct PS_OUTPUT
{
float4 c : COLOR0;
};

PS_OUTPUT Main (PS_INPUT input)
{
...
output.c.r += 0.00025f;
...
return output;
}

QUESTION 1: but in order to avoid those calculations, can't i just use integer with the D3DFMT_G16R16 instead of float? as for example:

struct PS_OUTPUT
{
int4 c : COLOR0; //notice the integer - is that possible?
};

PS_OUTPUT Main (PS_INPUT input)
{
...
output.c.r = 25;
...
output.c.r += 1;
...
return output;
}

QUESTION 2: Or does the color semantic always have to be of type float4 and i'm limited to the "color range" that goes from 0.0f to 1.0f?

[Edited by - stona on March 16, 2006 11:27:48 AM]

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