www.pudn.com > Samples-latest.zip > SHLighting.fx
//-----------------------------------------------------------------------------
// File: SHLighting.fx
//
// Desc: The effect file for the SHLighting sample.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
float4x4 g_mWorld; // World matrix for object
float4x4 g_mWorldViewProjection; // World * View * Projection matrix
float4 g_LightDir;
float4 g_LightingCoeff[4*4];
//-----------------------------------------------------------------------------
// Vertex shader output structure
//-----------------------------------------------------------------------------
struct VS_OUTPUT
{
float4 Position : POSITION; // vertex position
float4 Diffuse : COLOR0; // vertex diffuse color
};
//-----------------------------------------------------------------------------
// Name: RenderSceneVS
// Type: Vertex shader
// Desc: This shader computes standard transform and lighting
//-----------------------------------------------------------------------------
VS_OUTPUT RenderSceneVS( float4 vPos : POSITION,
float3 vNormal : NORMAL,
float4 vSHCoeff[4] : BLENDWEIGHT0 )
{
VS_OUTPUT Output;
// Transform the position from object space to homogeneous projection space
Output.Position = mul(vPos , g_mWorldViewProjection);
Output.Diffuse = float4( 0, 0, 0, 1 );
for ( int n = 0; n < 4; n++ )
{
Output.Diffuse.rgb += g_LightingCoeff[n * 4 + 0] * vSHCoeff[n].r;
Output.Diffuse.rgb += g_LightingCoeff[n * 4 + 1] * vSHCoeff[n].g;
Output.Diffuse.rgb += g_LightingCoeff[n * 4 + 2] * vSHCoeff[n].b;
Output.Diffuse.rgb += g_LightingCoeff[n * 4 + 3] * vSHCoeff[n].a;
}
return Output;
}
//-----------------------------------------------------------------------------
// Pixel shader output structure
//-----------------------------------------------------------------------------
struct PS_OUTPUT
{
float4 RGBColor : COLOR0; // Pixel color
};
//-----------------------------------------------------------------------------
// Name: RenderScenePS
// Type: Pixel shader
// Desc: This shader outputs the pixel's color by modulating the texture's
// color with diffuse material color
//-----------------------------------------------------------------------------
PS_OUTPUT RenderScenePS( VS_OUTPUT In )
{
PS_OUTPUT Output;
Output.RGBColor = In.Diffuse;
return Output;
}
//-----------------------------------------------------------------------------
// Name: RenderScene
// Type: Technique
// Desc: Renders scene to render target
//-----------------------------------------------------------------------------
technique RenderScene
{
pass P0
{
Cullmode = CCW;
VertexShader = compile vs_1_1 RenderSceneVS();
//PixelShader = compile ps_1_1 RenderScenePS();
ColorArg1[0] = DIFFUSE;
ColorOp[0] = SELECTARG1;
}
}