» ShaderSnippets
This site relies heavily on Javascript. You should enable it if you want the full experience. Learn more.

ShaderSnippets

Why reinvent the wheel? There're some handy little functions for the everyday HLSL writer. Please add your snippets in this wiki page.

General snippets

get clipping planes of a Perspective Projection

float4x4 tPI: PROJECTIONINVERSE;
float FarPlane = 1 / (tPI[2][3] + tPI[3][3]);
float NearPlane = 1 / distance(tPI[2][3], tPI[3][3]);

VertexShader snippets

still to come

PixelShader snippets for Image processing

invert

rgb-inversion

col.rgb = 1 - col.rgb;

contrast

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...

black&white

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

lumakey

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.

scene alpha

return(tex2D(Samp, float2(IN.TexCd.xy)).wwww);

Texture input must be in A8R8G8B8 format.

working alpha channel in 3d

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

Shoutbox

~17min ago

karistouf: Yet another show with vvvv and whitecat http://t.ymlp269.net/uhsaaaewsearaeemagau/click.php

~26min ago

tekcor: hm how do i create a single mesh from primitive geometrys and spreaded transform?

~4h ago

graphicuserinterface: @zepi:skynet is becoming self aware

~21h ago

flateric: Thanks devvvvs, I owe you a few bananas next time we meet :)

~2d ago

kiilo: @rexmtl im going to foulab later ...

~2d ago

kiilo: @wxmtl YES im in Montreal please contact me in the IRC chat or skype