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]);
rotation function:
float4x4 Vrotate(float rotX, float rotY, float rotZ) { rotX *= TwoPi; rotY *= TwoPi; rotZ *= TwoPi; float sx = sin(rotX); float cx = cos(rotX); float sy = sin(rotY); float cy = cos(rotY); float sz = sin(rotZ); float cz = cos(rotZ); return float4x4( cz*cy+sz*sx*sy, sz*cx, cz*-sy+sz*sx*cy, 0, -sz*cy+cz*sx*sy, cz*cx, sz*sy+cz*sx*cy , 0, cx * sy ,-sx , cx * cy , 0, 0 , 0 , 0 , 1); }
use the function like this:
PosO = mul(PosO, Vrotate(Sampler.r, Sampler.g, Sampler.b)); NormO = mul(NormO, Vrotate(Sampler.r, Sampler.g, Sampler.b));
Sampler.rgb are the corresponding values from the texture
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
~2h ago
~2h ago
~3h ago
~7h ago
~7h ago
~7h ago
~8h ago
~10h ago
~13h ago
~13h ago