Study/RenderMonkey - 2019년 백업

[RenderMonkey] Diffuse

김성인 2023. 12. 6. 23:06

[RenderMonkey] Diffuse


// Vertex Shader

struct VS_INPUT
{
	float4 mPosition : POSITION;
	float3 mNormal : NORMAL;
};

struct VS_OUTPUT
{
	float4 mPosition : POSITION;
	float3 mDiffuse : TEXCOORD1;
};

float4x4 gWorldMatrix;
float4x4 gViewMatrix;
float4x4 gProjectionMatrix;

float4 gWorldLightPosition;

VS_OUTPUT vs_main(VS_INPUT Input)
{
	VS_OUTPUT Output;

	Output.mPosition = mul(Input.mPosition, gWorldMatrix);

	float3 lightDir = Output.mPosition.xyz - gWorldLightPosition.xyz;
	lightDir = normalize(lightDir);

	Output.mPosition = mul(Output.mPosition, gViewMatrix);
	Output.mPosition = mul(Output.mPosition, gProjectionMatrix);

	float3 worldNormal = mul(Input.mNormal, (float3x3)gWorldMatrix);
	worldNormal = normalize(worldNormal);

	Output.mDiffuse = dot(-lightDir, worldNormal);

	return Output;
}

// Pixel Shader

struct PS_INPUT
{
	float3 mDiffuse : TEXCOORD1;
};

float4 ps_main(PS_INPUT Input) : COLOR
{
   float3 diffuse = saturate(Input.mDiffuse);

   return float4(diffuse, 1);
}

// Stream Mapping
// 정점버퍼의 법선 시맨틱 NORMAL 추가로 Usage > NORMAL, FLOAT3 추가

// gWorldLightPosition
// 광원의 위치

'Study > RenderMonkey - 2019년 백업' 카테고리의 다른 글

[RenderMonkey] Mapping  (1) 2023.12.06
[RenderMonkey] Specular, ambient  (1) 2023.12.06
[Render Monkey] Phong  (1) 2023.12.06
[RenderMonkey] Globe  (1) 2023.12.06
[RenderMonkey] Red Color  (0) 2023.12.06