Featured image of post 셰이더 프로그래밍 기본공부 13

셰이더 프로그래밍 기본공부 13

그동안의 공식이 잘못되어 있었다는 것을 깨달았습니다.
울고 불며 짜도 소용없습니다.

float4x4 WorldViewProj : WORLDVIEWPROJ ;
float4x4 World     : WORLD;
float4x4 ViewI     : VIEWI;

float3 AmbientColor : AMBIENT
<
 string UIName = “AmbientColor”;

= { 0.0f, 0.0f, 0.0f } ;

float3 DiffuseColor : DIFFUSE
<
 string UIName = “DiffuseColor”;

= { 1.0f, 1.0f, 1.0f } ;

float3 SpecularColor : SPECULAR
<
 string UIName = “SpecularColor”;

= { 1.0f, 1.0f, 1.0f } ;

float3 LightDirection : DIRECTION
<
 string UIName = “DirectLight”;
 string Object = “Directionallight”;
 string Space = “WORLD”;
 int refID = 0;

;

void VS
(

 in float4 iPos : POSITION,
 in float3 iNormal : NORMAL,
 
 out float4 oPos : POSITION,
 out float4 WorldPos : TEXCOORD0,
 out float3 WorldNormal : TEXCOORD1
 
)
{
 WorldPos = mul( iPos, World );
 //포지션의 월드좌표화. 포지션은 4x4를 쓴다.
 WorldNormal =  mul ( iNormal, (float3x3)World );
 //노말의 월드좌표화. 로테이션은 3x3만 쓰기 때문에 이렇게 했다.
 
 
 oPos = mul( iPos, WorldViewProj );
}

void PS
(
 in float4 WorldPos : TEXCOORD0,
 in float3 WorldNormal : TEXCOORD1,

 out float4 oColor : COLOR
)
{
 float3 SurfaceNormal = normalize ( WorldNormal ) ;
 // 월드 좌표계의 서피스 노말
 float3 EyeDirection = normalize ( ViewI[3].xyz - WorldPos.xyz );
 // 시선 벡터 노말
 float3 HalfVector = normalize ( EyeDirection + LightDirection );
 // 시선 벡터와 라이트 벡터의 덧셈
 
 
 float3 Diffuse = DiffuseColor * max( 0, dot( LightDirection, SurfaceNormal ) );
 // 빛 벡터와 서피스벡터의 닷 연산
 float3 Specular = SpecularColor * pow ( max ( 0, dot ( SurfaceNormal, HalfVector ) ), 20 ) ;
 // 하프벡터와 서피스벡터의 닷 연산
 float3 FinalColor = Diffuse + AmbientColor + Specular ;
 
 
 oColor = float4( FinalColor, 1 );
}

Technique jp11
{
 pass p0
 {
  vertexshader = compile vs_2_0 VS();
  pixelshader = compile ps_2_0 PS();
 }
}

Hugo로 만듦
JimmyStack 테마 사용 중