Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct VertexToPixel
- {
- float4 Position : POSITION;
- float4 Color : COLOR0;
- float LightingFactor: TEXCOORD0;
- float2 TextureCoords: TEXCOORD1;
- };
- struct PixelToFrame
- {
- float4 Color : COLOR0;
- };
- //------- Constants --------
- float4x4 xView;
- float4x4 xProjection;
- float4x4 xWorld;
- float3 xLightDirection;
- float xAmbient;
- bool xEnableLighting;
- //------- Texture Samplers --------
- Texture xTexture;
- sampler TextureSampler = sampler_state { texture = <xTexture>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = Clamp; AddressV = Clamp;};
- //------- Technique: Colored --------
- VertexToPixel ColoredVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float4 inColor: COLOR)
- {
- VertexToPixel Output = (VertexToPixel)0;
- float4x4 preViewProjection = mul (xView, xProjection);
- float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
- Output.Position = mul(inPos, preWorldViewProjection);
- Output.Color = inColor;
- float3 Normal = normalize(mul(normalize(inNormal), xWorld));
- Output.LightingFactor = 1;
- if (xEnableLighting)
- Output.LightingFactor = dot(Normal, -xLightDirection);
- return Output;
- }
- PixelToFrame ColoredPS(VertexToPixel PSIn)
- {
- PixelToFrame Output = (PixelToFrame)0;
- Output.Color = PSIn.Color;
- Output.Color.rgb *= saturate(PSIn.LightingFactor) + xAmbient;
- return Output;
- }
- technique Colored
- {
- pass Pass0
- {
- VertexShader = compile vs_2_0 ColoredVS();
- PixelShader = compile ps_2_0 ColoredPS();
- }
- }
- //------- Technique: Textured --------
- VertexToPixel TexturedVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float2 inTexCoords: TEXCOORD0)
- {
- VertexToPixel Output = (VertexToPixel)0;
- float4x4 preViewProjection = mul (xView, xProjection);
- float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
- Output.Position = mul(inPos, preWorldViewProjection);
- Output.TextureCoords = inTexCoords;
- float3 Normal = normalize(mul(normalize(inNormal), xWorld));
- Output.LightingFactor = 1;
- if (xEnableLighting)
- Output.LightingFactor = dot(Normal, -xLightDirection);
- return Output;
- }
- PixelToFrame TexturedPS(VertexToPixel PSIn)
- {
- PixelToFrame Output = (PixelToFrame)0;
- Output.Color = tex2D(TextureSampler, PSIn.TextureCoords);
- Output.Color.rgb *= saturate(PSIn.LightingFactor) + xAmbient;
- return Output;
- }
- technique Textured
- {
- pass Pass0
- {
- VertexShader = compile vs_2_0 TexturedVS();
- PixelShader = compile ps_2_0 TexturedPS();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement