`
yellowcxx
  • 浏览: 2564 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

HLSL Shading for 3dsMax 02 - Diffuse Lighting

阅读更多
Purpose:
Create a Shader to Implement the Lambert's Cosine Law.

Solution:
1.Study of the Lambert's Cosine Law from <<Introduction to 3D Game Programming with DirectX 10>>



2.Shader Source

float4x4 wvp : WorldViewProjection <string UIWidget="None" ;>;
float4x4 w : World <string UIWidget="None";>;

float4 LightPosition : POSITION
<
	string UIName="Light Position";
	string Object="PointLight";
	string Space="World";
	int refID=0;
	
> =float4(100,100,100,0);

float4 LightColor: LIGHTCOLOR
<
	int LightRef=0;
> =float4(1,1,1,0);

struct VS_INPUT
{
	float4 Pos: POSITION;
	float4 Normal: NORMAL;
};

struct VS_OUTPUT
{
	float4 Pos : POSITION0;
	float3 L: TEXCOORD0;
	float3 N: TEXCOORD1;
};

VS_OUTPUT vs_main(VS_INPUT Input)
{
	VS_OUTPUT Result;
	Result.Pos = mul(Input.Pos,wvp);
	
	float4 worldPos=mul(Input.Pos,w);
	Result.L=LightPosition-worldPos;
	Result.N=mul(Input.Normal,w);
	
	return Result;
}

float4 ps_main(VS_OUTPUT Input):COLOR
{
	float3 N=normalize(Input.N);
	float3 L=normalize(Input.L);
	
	float NdotL=max(dot(N,L),0);
	float4 Result=NdotL*LightColor;
	return float4(Result.xyz,1);
}

technique DiffuseLighting
{
	pass Lambert
	{
		VertexShader = compile vs_2_0 vs_main();
		PixelShader  = compile ps_2_0 ps_main();
	}
};


3.Load the shader and add a Omi(Point) light to the scene.



4.try move the light around to see the effect








  • 大小: 83.6 KB
  • 大小: 148.5 KB
  • 大小: 124.7 KB
  • 大小: 141 KB
  • 大小: 143.7 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics