///////////////////////////////////////////////////////////////////////////// // Copyright (c) FrontFree_Studio. All rights reserved. ///////////////////////////////////////////////////////////////////////////// /**************** GLOABLE VARIABLES ****************/ float4 MtrlSpec = { 1.0f, 1.0f, 1.0f, 1.0f }; // material’s specular color, white float SpecPow = 8;
float3 OmniPos : POSITION = { 0.577, 0.577, -0.577 }; // lights (world space) float4 OmniColor = { 1.0f, 1.0 f, 1.0f, 1.0f }; // light’s color, white float4 AmbLight = { 0.9f, 0.9f, 0.9f, 0.9f }; // ambient light color; float3 CameraPos : CAMERAPOSITION = { 0.0f, 3.0f, 5.0f };
// camera (world space) float4x3 matWorld : WORLD; float4x4 matViewProj : VIEWPROJ; /***** vertex shader output structure *********/ struct VS_OUTPUT { float4 Pos : POSITION; float4 Intensity : COLOR0; float4 Spec : COLOR1; float3 Texcoord : TEXCOORD; }; /**************** VERTEX SHADER ****************/ VS_OUTPUT VS( float3 InPos : POSITION, float3 InNormal : NORMAL,
float2 InTexcoord : TEXCOORD ) { VS_OUTPUT Out = (VS_OUTPUT)0; //Calculate the output color by per-pixel lighting // first, calculate the diffuse component float3 P_World = mul(float4(InPos, 1), matWorld); // position to world space float3 ToLight = normalize( P_World – OmniPos ); float3 Normal = normalize( InNormal ); float4 Diff = dot( ToLight, Normal ) * OmniColor; Out.Intensity = Diff + AmbLight; // then, the specular component float3 Reflection = reflection( -ToLight, Normal ); float3 ToEye = normalize( CameraPos – P_World ); float4 Spec = pow( dot( Reflection, ToEye ), SpecPow ) * MtrlSpec * OmniColor; Out.Spec = Spec; // Output the position, texture coordination Out.Pos = mul(float4(P_World, 1), matViewProj); Out.Texcoord = InTexcoord; return Out; } |