blend states question

Started by
5 comments, last by eppo 11 years, 7 months ago
In this operation
OutputPixel = ( Sr.rgba * Sr.aaaa ) ADD ( De.rgba * (1,1,1,1) )
Does the OutputPixel values rgba will be, lets say:

Sr.r = 30.0f
Sr.a = -4.0f
De.r=3.0f

so
OutputPixel.r = (30*-4)+(3*1) = -117.0f
Is that the real output value or the values will be in some way converted to the rage from 0 to 1.
Advertisement
Hi lomateron!

It all depends on the formats of the textures.
For shaders and blending operations the values from the textures are first converted to floats, then comes the operation (or shader code) and then they are converted to the output format.

If you have DXGI_RGBA8_UNORM for instance, the 8 bits in the input slots (0..255) are converted to a float by scaling to 0.0f..1.0f (e.g. 127 is mapped to about 0.5f). If DXGI_RGBA8_UNORM is the output format it is the other way around. A 0.5f would be mapped to 127. (Note that the next shader or blending operation would read it as a 0.5f, again.) Besides, the input and output floats are always clamped to 0.0f and 1.0f. An operation like yours wouldn't be possible, since the input and output values would both be clamped.

If you would use a float texture, e.g. DXGI_R32G32B32A32_FLOAT, no conversion is necessary, thus the value 123.0f would still be 123.0f in the shader or blending operation. In that case, nothing is clamped. This means, any float value is possible for input and output!
Having said that, you would need a float format for your input and output textures and for your given sample values the operation should work just fine.

Best regards!
Another question
Sr=(-3,6,1)
De=(-1,5,1)

Op=( Sr.rgb) MIN ( De.rgb)

what happens there?
Op=(-3,5,1)?
Hi!


what happens there?
Op=(-3,5,1)?

Yes, that's correct!

Best regards
thinking on this but Cant find a way using the blending to make this:
when rendering to a pixel, when the pixel shader returns a float4 pix and
pix.w != 0 replace the pixel rendering to with pix
pix.w = 0 leave the pixel rendering to the same.

the pixel values arent used for displaying colors, they are vectors.
Hi!

I think this is not possible with the blend state alone.
The easiest way to achieve it would be to write a pixel shader. The following line would do the trick:
clip( input.color.a == 0 ? -1 : 1);
Clip discards a pixel if the argument is negative.

Best regards!
Under Direct3D 9 you can use fixed function alpha testing to skip pix.w == 0 pixels.
D3D10 and up require you to emulate this functionality by either outputting a zero alpha value or discard()-ing (don't use discard if you don't need to) the pixel.

This topic is closed to new replies.

Advertisement