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

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

뭐 일단 디퓨즈색상+엠비언트 색상 + 스페큘러 색상에
+디퓨즈 텍스쳐 + 글로스니스 텍스쳐 추가 상태입니다.
지금까지 배운것을 총망라해 넣어 놓은 것.

그래도 최고는 아직 아닌것이, 퍼픽셀 라이팅이 아니라 퍼 버텍스 라이팅 계산법으로 때린 거라서요….

폴리곤이 많을 때에는 이렇지만

폴리곤이 적어지면 이렇게 되지요
헐헐헐
모처럼의 휴일인데, 셰이더 프로그래밍의 매력에 빠져서 쥘쥘쥘…
다음엔 퍼 픽셀 라이팅으로 바꿔볼까나..

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 float3 DiffuseLight : COLOR0,
 out float3 SpecularLight : COLOR1,
 out float4 oTex   : TEXCOORD0 
)
{
 float3 ViewNormal = normalize( mul (iNormal, World));
 float3 EyeDirection = normalize ( ViewI[3].xyz - ViewNormal.xyz );
 float3 Halfvector = normalize ( EyeDirection + LightDirection );
 
 
 oPos = mul ( iPos, WorldViewProj );
 DiffuseLight = D_c *  max ( 0, dot( LightDirection , ViewNormal));
 SpecularLight = S_c * pow ( max ( 0, dot( Halfvector,ViewNormal )),20 );
 
 oTex = iTex;
 
}

void PS
(
 in float4 DiffuseLight  : COLOR0,
 in float4 SpecularLight : COLOR1,
 in float4 iTex     : TEXCOORD0,

 out float4 oColor : COLOR
)
{
 oColor = (tex2D ( D_tsampler, iTex ) * DiffuseLight + float4(A_c,1)) +
 SpecularLight * ( tex2D (Glosssampler, iTex)) ;
}

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

Hugo로 만듦
JimmyStack 테마 사용 중