// ------------------------------------------------------------------------- // PARAMETERS: // ------------------------------------------------------------------------- //transforms float4x4 tW: WORLD; //the models world matrix float4x4 tV: VIEW; //view matrix as set via Renderer (DX9) float4x4 tP: PROJECTION; //projection matrix as set via Renderer (DX9) float4x4 tWVP: WORLDVIEWPROJECTION; //texture texture Tex ; 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 ; //creates a color pin with the default value black with alphachanel set to 1 //and with pinname "Color for Hello" float4 HelloColor : COLOR = { 0.0, 0.0, 0.0, 1.00000 }; //secound color input float4 HelloColor2 : COLOR = { 1, 1, 1, 1.00000 }; //pin for threshold float threshold = 0.01; //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 TexCd : TEXCOORD0; }; // -------------------------------------------------------------------------------------------------- // VERTEXSHADERS // -------------------------------------------------------------------------------------------------- vs2ps VS( float4 Pos : POSITION, float4 TexCd : TEXCOORD0) { //inititalize all fields of output struct with 0 vs2ps Out = (vs2ps)0; //transform position Out.Pos = mul(Pos, tWVP); //transform texturecoordinates Out.TexCd = mul(TexCd, tTex); return Out; } // ------------------------------------------------------------------------- // PIXELSHADERS: // ------------------------------------------------------------------------- //from "02 hello world in pink" float4 hello_01(vs2ps In): COLOR { //texture lookup to access the pixels of the texture float4 col = tex2D(Samp, In.TexCd); //if the pixels are white then overwrite them with HelloColor (above input color) //or do nothing //then return col if (col.r == 1 && col.g ==1 && col.b == 1) { col = HelloColor; } return col; } float4 tresholded(vs2ps In): COLOR { //texture lookup to access the pixels of the texture float4 col = tex2D(Samp, In.TexCd); //if the pixels are bigger threshold overwrite them with HelloColor //or do nothing //then return col if (col.r > threshold && col.g > threshold && col.b > threshold) { col = HelloColor; } return col; } float4 tresholded2(vs2ps In): COLOR { //texture lookup to access the pixels of the texture float4 col = tex2D(Samp, In.TexCd); //if the pixel is bigger threshold overwrite them with HelloColor //if the pixel is smaller threshold overwrite them with HelloColor2 //then return col if (col.r > threshold && col.g > threshold && col.b > threshold) { col = HelloColor; } else { col = HelloColor2; } return col; } // ------------------------------------------------------------------------- // TECHNIQUES: // ------------------------------------------------------------------------- technique HelloTresholded2Colors //name for the technique pin { pass P0 { VertexShader = compile vs_1_1 VS(); PixelShader = compile ps_2_0 tresholded2(); } } technique HelloTresholded //name for the technique pin { pass P0 { VertexShader = compile vs_1_1 VS(); PixelShader = compile ps_2_0 tresholded(); } } technique HelloInPink { pass P0 { VertexShader = compile vs_1_1 VS(); PixelShader = compile ps_2_0 hello_01(); } }