-
-
Save elliotwoods/2828967 to your computer and use it in GitHub Desktop.
basic hlsl shader used with 16bit depth texture from kinect as a way of thresholding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@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; | |
float4 PosW : TEXCOORD1; | |
float2 TexCd : TEXCOORD0; | |
}; | |
// -------------------------------------------------------------------------------------------------- | |
// VERTEXSHADERS | |
// -------------------------------------------------------------------------------------------------- | |
vs2ps VS( | |
float4 PosO : POSITION, | |
float4 TexCd : TEXCOORD0) | |
{ | |
//declare output struct | |
vs2ps Out; | |
//transform position | |
Out.Pos = mul(PosO, tWVP); | |
Out.PosW = mul(PosO, tW); | |
//transform texturecoordinates | |
Out.TexCd = mul(TexCd, tTex); | |
return Out; | |
} | |
// -------------------------------------------------------------------------------------------------- | |
// PIXELSHADERS: | |
// -------------------------------------------------------------------------------------------------- | |
float4 PS(vs2ps In): COLOR | |
{ | |
float4 col = tex2D(Samp, In.TexCd); | |
if (In.PosW.z < thresh) | |
{ | |
col.a =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