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

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

허무하리만큼 간단한 엠비언트 추가 ;;;

float4x4 WorldViewProj : WORLDVIEWPROJ ;
float4x4 World : WORLD ;

texture basemap : DIFFUSEMAP
<
 string UIName = “base”;
 int Texcoord = 0;
 int MapChannel =1; 

;

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

float3 lightdirection : DIRECTION
<
 string UIName = “라이트 디렉션”;
 string Object = “Directionallight”;
 string Space = “World”;
 int refID = 0;

;

float3 lightambient
<
 string UIName = “Ambient Color”;

;

float3 lightcolor : LIGHTCOLOR
<
 int lightRef =0;
 string UIWidget = “none”;

;

void VS
(
 in float4 ipos : POSITION,
 in float3 inormal : NORMAL,
 in float2 itex : TEXCOORD0,
 out float4 opos : POSITION,
 out float2 otex : TEXCOORD0,
 out float3 olight : TEXCOORD1 
)
{
 float3 -normal = normalize(mul(inormal,(float3x3)World));
 opos = mul(ipos,WorldViewProj);
 otex = itex;
 olight = lightambient + lightcolor * max(0,dot(onormal,lightdirection));
}

void PS
(
 in float2 otex : TEXCOORD0,
 in float4 olight : TEXCOORD1,
 out float4 ocolor : COLOR 
)
{
 ocolor = tex2D(basesampler, otex)* olight;
}

technique jp1
{
 pass p0
 {
  vertexshader = compile vs_2_0 VS();
  pixelshader = compile ps_2_0 PS();
 }
}

/////////////////// 중간에 라이트 계산에서 float4 자리수 맞추는 부분에 오류가 있어서 동작이 제대로 안되었었을겁니다.
////////////////// 아래는 수정한것.

float4x4 WorldViewProj : WORLDVIEWPROJ ;
float4x4 World : WORLD ;

texture basemap : DIFFUSEMAP
<
 string UIName = “base”;
 int Texcoord = 0;
 int MapChannel =1;

;

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

float3 lightdirection : DIRECTION
<
 string UIName = “라이트 디렉션”;
 string Object = “Directionallight”;
 string Space = “World”;
 int refID = 0;

;

float3 lightambient
<
 string UIName = “Ambient Color”;

;

float3 lightcolor : LIGHTCOLOR
<
 int lightRef =0;
 string UIWidget = “none”;

;

void VS
(
 in float4 ipos : POSITION,
 in float3 inormal : NORMAL,
 in float2 itex : TEXCOORD0,
 out float4 opos : POSITION,
 out float2 otex : TEXCOORD0,
 out float3 olight : TEXCOORD1
)
{
 float3 -normal = normalize(mul(inormal,(float3x3)World));
 opos = mul(ipos,WorldViewProj);
 otex = itex;
 olight = lightambient + lightcolor * max(0,dot(onormal,lightdirection));
}

void PS
(
 in float2 otex : TEXCOORD0,
 in float3 olight : TEXCOORD1,
 out float4 ocolor : COLOR
)
{
 ocolor = tex2D(basesampler, otex)* float4(olight,1.0f);
}

technique jp1
{
 pass p0
 {
  vertexshader = compile vs_2_0 VS();
  pixelshader = compile ps_2_0 PS();
 }
}

Hugo로 만듦
JimmyStack 테마 사용 중