Skip to content

Instantly share code, notes, and snippets.

@mrboni
Created May 29, 2012 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrboni/2828957 to your computer and use it in GitHub Desktop.
Save mrboni/2828957 to your computer and use it in GitHub Desktop.
basic hlsl shader used with 16bit depth texture from kinect as a way of thresholding
//@author: vvvv group
//@help: this is a very basic template. use it to start writing your own effects. if you want effects with lighting start from one of the GouraudXXXX or PhongXXXX effects
//@tags:
//@credits:
// --------------------------------------------------------------------------------------------------
// PARAMETERS:
// --------------------------------------------------------------------------------------------------
//transforms
float4x4 tW: WORLD; //the models world matrix
float4x4 tV: VIEW; //view matrix as set via Renderer (EX9)
float4x4 tP: PROJECTION;
float4x4 tWVP: WORLDVIEWPROJECTION;
float thresh = 0;
//texture
texture Tex <string uiname="Texture";>;
sampler Samp = sampler_state //sampler for doing the texture-lookup
{
Texture = (Tex); //apply a texture to the sampler
MipFilter = LINEAR; //sampler states
MinFilter = LINEAR;
MagFilter = LINEAR;
};
//texture transformation marked with semantic TEXTUREMATRIX to achieve symmetric transformations
float4x4 tTex: TEXTUREMATRIX <string uiname="Texture Transform";>;
//the data structure: "vertexshader to pixelshader"
//used as output data with the VS function
//and as input data with the PS function
struct vs2ps
{
float4 Pos : POSITION;
float2 TexCd : TEXCOORD0;
};
// --------------------------------------------------------------------------------------------------
// VERTEXSHADERS
// --------------------------------------------------------------------------------------------------
vs2ps VS(
float4 PosO : POSITION,
float4 TexCd : TEXCOORD0)
{
//declare output struct
vs2ps Out;
//transform position
Out.Pos = mul(PosO, tWVP);
//transform texturecoordinates
Out.TexCd = mul(TexCd, tTex);
return Out;
}
// --------------------------------------------------------------------------------------------------
// PIXELSHADERS:
// --------------------------------------------------------------------------------------------------
float4 PS(vs2ps In): COLOR
{
float4 col = tex2D(Samp, In.TexCd);
if (col.r < thresh)
{
col.r =0;
}
return col;
}
// --------------------------------------------------------------------------------------------------
// TECHNIQUES:
// --------------------------------------------------------------------------------------------------
technique TSimpleShader
{
pass P0
{
//Wrap0 = U; // useful when mesh is round like a sphere
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_2_0 PS();
}
}
technique TFixedFunction
{
pass P0
{
//transforms
WorldTransform[0] = (tW);
ViewTransform = (tV);
ProjectionTransform = (tP);
//texturing
Sampler[0] = (Samp);
TextureTransform[0] = (tTex);
TexCoordIndex[0] = 0;
TextureTransformFlags[0] = COUNT2;
//Wrap0 = U; // useful when mesh is round like a sphere
Lighting = FALSE;
//shaders
VertexShader = NULL;
PixelShader = NULL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment