Why reinvent the wheel? There're some handy little functions for the everyday HLSL writer. Please add your snippets in this wiki page.
float4x4 tPI: PROJECTIONINVERSE; float FarPlane = 1 / (tPI[2][3] + tPI[3][3]); float NearPlane = 1 / distance(tPI[2][3], tPI[3][3]);
still to come
rgb-inversion
col.rgb = 1 - col.rgb;
col.rgb = ((col.rgb - 0.5) * var) + 0.5;
if var > 1, the contrast is greater. var = 0 gives a grey picture
The 0.5 can be replaced with a variable to give a gamma or centre
point for the contrast as well, for more fine tuning...
const float4 lumcoeff = {0.299, 0.587, 0.114, 0}; col = dot(col, lumcoeff);
the dot product of the color (col) and the luminace coefficients results in a correct b&w image
const float4 lumcoeff = {0.299, 0.587, 0.114, 0}; float luma = length(dot(col, lumcoeff)); col.a = step(var, luma);
var is the keying amount. the rest works like the b&w conversion.
return(tex2D(Samp, float2(IN.TexCd.xy)).wwww);
Texture input must be in A8R8G8B8 format.
needs 2 passes so connect an iobox with 2 rows to the pass pin and fill it with 0,1
technique workingalpha { pass P0 { VertexShader = compile vs_1_0 VS(); PixelShader = compile ps_2_0 PS(); AlphaBlendEnable = false; AlphaTestEnable = true; AlphaFunc = Greater; AlphaRef = 245; ZEnable = true; ZWriteEnable = true; CullMode = None; } pass P1 { VertexShader = compile vs_1_0 VS(); PixelShader = compile ps_2_0 PS(); AlphaBlendEnable = true; SrcBlend = SrcAlpha; DestBlend = InvSrcAlpha; AlphaTestEnable = true; AlphaFunc = LessEqual; AlphaRef = 245; ZEnable = true; ZWriteEnable = false; CullMode = None; } }
anonymous user login
~17min ago
~26min ago
~2h ago
~4h ago
~9h ago
~21h ago
~24h ago
~2d ago
~2d ago