void vs_main(
in float4 Position : POSITION0,
in float2 Texcoord : TEXCOORD0,
in float3 Normal : NORMAL0,
out float4 Pos : POSITION0,
out float2 Tex : TEXCOORD0,
out float4 ViewDirection : TEXCOORD1,
out float4 LightDirection : TEXCOORD2,
out float4 Nor : TEXCOORD3,
uniform float4 fvLightPosition,
uniform float4 fvEyePosition,
uniform float4x4 matView,
uniform float4x4 matViewProjection)
{
Pos = mul( matViewProjection, Position );
Tex = Texcoord;
float4 fvObjectPosition = mul( matView, Position );
ViewDirection = fvEyePosition - fvObjectPosition;
LightDirection = fvLightPosition - fvObjectPosition;
Nor = mul( matView, Normal );
}
void ps_main(
in float2 Texcoord : TEXCOORD0,
in float4 ViewDirection : TEXCOORD1,
in float4 LightDirection: TEXCOORD2,
in float4 Normal : TEXCOORD3,
out float4 color : COLOR0,
uniform float4 komfvAmbient,
uniform float4 komfvDiffuse,
uniform float4 komfvSpecular,
uniform float komfSpecularPower,
uniform sampler2D kombaseMap : register(s0))
{
float4 fvLightDirection = normalize( LightDirection );
float4 fvNormal = normalize( Normal );
float fNDotL = saturate(dot( fvNormal.xyz, fvLightDirection.xyz ));
float4 fvReflection = normalize( ( ( 2.0f * fvNormal ) * ( fNDotL ) ) - fvLightDirection );
float4 fvViewDirection = normalize( ViewDirection );
float fRDotV = max( 0.0f, dot( fvReflection.xyz, fvViewDirection.xyz ) );
float4 fvBaseColor = tex2D( kombaseMap, Texcoord );
float4 fvTotalAmbient = komfvAmbient * fvBaseColor;
float4 fvTotalDiffuse = komfvDiffuse * fNDotL * fvBaseColor;
float4 fvTotalSpecular = komfvSpecular * pow( fRDotV, komfSpecularPower );
color = saturate(fvTotalAmbient + fvTotalDiffuse + fvTotalSpecular);
}
vertex_program Kom/VPhlsl hlsl
{
source kom.hlsl
entry_point vs_main
target vs_2_0
}
fragment_program Kom/FPhlsl hlsl
{
source kom.hlsl
entry_point ps_main
target ps_2_0
}
material Kom/Material
{
technique
{
pass
{
vertex_program_ref Kom/VPhlsl
{
param_named fvLightPosition float4 100.0 100.0 100.0 0
param_named fvEyePosition float4 0.0 0.0 -100.0 0
param_named_auto matView world_matrix
param_named_auto matViewProjection viewproj_matrix
}
fragment_program_ref Kom/FPhlsl
{
param_named komfvAmbient float4 0.3686 0.3686 0.3686 1.0
param_named komfvSpecular float4 0.4887 0.4887 0.4887 1.0
param_named komfvDiffuse float4 0.8850 0.8850 0.8850 1.0
param_named komfSpecularPower float 100.0
}
texture_unit
{
texture BeachStones.jpg
}
}
}
}
转载:http://hi.baidu.com/muyelian/item/e25132c2cfdc83330831c644