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

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

얏호. 퍼 픽셀 라이팅을 단번에 성공.
아래와 같은 퍼 버텍스 라이팅에서 ,

폴리곤 추가없이 퍼 픽셀라이트로 전환만 했다.
이번엔 노말값도 픽셀셰이더로 넘기지 않는 공식을 완성한 것이 성과.
아래 하이라이트가 좀 더 섬세한 것을 알 수 있다.

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

//엠비언트

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

= { 0.5f, 0.5f, 0.5f };

//디퓨즈

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

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

//디퓨즈텍스쳐

texture D_t : DIFFUSEMAP
<
 string UIName = “DiffuseTexture”;

;

sampler2D D_tsampler = sampler_state
{
 texture = <D_t>;
 MinFilter = Linear;
 MagFilter = Linear;
 MipFilter = Linear;
};

//글로스 텍스쳐

texture Glossmap : GLOSSMAP
<
 string UIName = “Glosstexture”;

;

sampler2D Glosssampler = sampler_state
{
 texture = ;
 MinFilter = Linear;
 MagFilter = Linear;
 MipFilter = Linear; 
};

//스페큘러

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

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

// 라이트 디렉션
 
float3 LightDirection : DIRECTION
<
 string UIName = “DiffuseLight”;
 string Object = “Directionallight”;

;

void VS
(
 in float4 iPos   : POSITION,
 in float3 iNormal  : NORMAL,
 in float4 iTex   : TEXCOORD0,
 in float4 iTex1   : TEXCOORD1,
 out float4 oPos   : POSITION,
 out float4 oTex   : TEXCOORD0,
 out float3 ViewPos  : TEXCOORD1
)
{
 ViewPos = mul (iNormal, World); 
 oPos = mul ( iPos, WorldViewProj );
 oTex = iTex;
}

void PS
(
 in float4 iTex     : TEXCOORD0,
 in float3 ViewPos  : TEXCOORD1,
 
 out float4 oColor : COLOR
)
{
 float3 ViewNormal = normalize(ViewPos);
 float3 EyeDirection = normalize ( ViewI[3].xyz - ViewNormal.xyz );
 float3 Halfvector = normalize ( EyeDirection + LightDirection );
 float3 DiffuseLight = D_c *  max ( 0, dot( LightDirection , ViewNormal));
 float3 SpecularLight = S_c * pow ( max ( 0, dot( Halfvector,ViewNormal )),20 );
 float3 FinalColor = (tex2D ( D_tsampler, iTex ) * DiffuseLight + float4(A_c,1)) +
 SpecularLight * ( tex2D (Glosssampler, iTex)) ;
 
 
 oColor = float4(FinalColor,1);
}

Technique jp5
{
 pass p0
 {
  VertexShader = compile vs_2_0 VS();
  PixelShader = compile ps_2_0 PS();
 }
}

Hugo로 만듦
JimmyStack 테마 사용 중