104 lines
3.2 KiB
HLSL
104 lines
3.2 KiB
HLSL
|
|
#include "def_effect.fx"
|
|
|
|
//=============================================================================
|
|
//캐릭터 Bump Map 포함
|
|
VS_BUMP_OUTPUT BumpMap_VS( VS_BUMP_INPUT In )
|
|
{
|
|
VS_BUMP_OUTPUT Out = (VS_BUMP_OUTPUT)0;
|
|
|
|
float4 pos = In.position;
|
|
float3 normal = In.normal;
|
|
float3 tangent = In.tangent;
|
|
float flipper = In.tangent.w;
|
|
float4 tex = 0;
|
|
float4 output_pos, pos_world;
|
|
|
|
pos_world = SkinPoint( pos , blendMatrices, In.indices, In.weights); // pos is changed.
|
|
float3 N = SkinVector( normal, blendMatrices, In.indices, In.weights); // normal is changed.
|
|
SkinVector( tangent, blendMatrices, In.indices, In.weights); // tangent is changed.
|
|
|
|
float3 binormal = flipper*cross(normal, tangent);
|
|
|
|
// transform position to screen space before changing it.
|
|
output_pos = mul( pos_world, view_proj_matrix );
|
|
Out.position = output_pos;
|
|
|
|
//apply fog
|
|
float distfog = saturate((fFogDistEnd - output_pos.z)/(fFogDistEnd - fFogDistStart));
|
|
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
|
|
Out.fog = min(distfog, heightfog);
|
|
|
|
|
|
// light vector
|
|
float3 light_vec = Light_position - pos_world;
|
|
//float nLength = length(light_vec);
|
|
//float3 L = normalize(light_vec);
|
|
|
|
//float Atten = 1/(1+(Light_ambient.a*nLength));
|
|
|
|
// eye-base의 half-way 벡터
|
|
float3 eye_vector = Camera_position - pos_world;
|
|
//float3 halfway = (normalize(eye_vector) - normalize(Light_direction_forsp));
|
|
|
|
//float ddot = saturate(dot(N, L));
|
|
//float sdot = saturate(dot(N, halfway));
|
|
|
|
//Out.diffuse = Light_ambient + max(Light_diffuse * ddot * Atten, Light_specular * pow(sdot, 7)); // specular + diffuse + ambient
|
|
//Out.diffuse.a = fVisibility;
|
|
|
|
tex = fUVAnimation.w*In.texCoord + fUVAnimation;
|
|
|
|
//Out.specular = Light_specular;
|
|
Out.texCoord0 = tex;
|
|
Out.texCoord1 = tex;
|
|
|
|
// tangent space calc
|
|
Out.texCoord2.x = dot(light_vec, tangent);
|
|
Out.texCoord2.y = dot(light_vec, binormal);
|
|
Out.texCoord2.z = dot(light_vec, normal);
|
|
Out.texCoord2.w = 1;
|
|
Out.texCoord3.x = dot(Light_halfway, tangent);
|
|
Out.texCoord3.y = dot(Light_halfway, binormal);
|
|
Out.texCoord3.z = dot(Light_halfway, normal);
|
|
Out.texCoord3.w = 1;
|
|
|
|
return Out;
|
|
}
|
|
|
|
float4 BumpMap_PS( PS_BUMP_INPUT In ) : COLOR
|
|
{
|
|
float4 d_col = tex2D(DiffTexture, In.texCoord0);
|
|
float4 outc;
|
|
float4 n = tex2D(BumpTexture, In.texCoord1);
|
|
float glossness = n.w;
|
|
n = n*2 - 1;
|
|
float4 illum = tex2D(IllumTexture, In.texCoord0);
|
|
|
|
float3 light_vec = In.texCoord2;
|
|
float light_length = length(light_vec);
|
|
float3 halfway_vec = In.texCoord3;
|
|
light_vec = normalize(light_vec);
|
|
halfway_vec = normalize(halfway_vec);
|
|
float ddot = saturate(dot(n, light_vec));
|
|
float sdot = saturate(dot(n, halfway_vec));
|
|
|
|
float Atten = 1/(1+(Light_ambient.a*light_length));
|
|
|
|
float4 m_col = Light_ambient + Light_diffuse * ddot * Atten;
|
|
outc = d_col*m_col*2 + Light_specular * pow(sdot, 7) * glossness + illum;
|
|
outc.w = Light_diffuse.w*d_col.w;
|
|
|
|
return outc;
|
|
}
|
|
|
|
//=============================================================================
|
|
//Bump 테크닉
|
|
technique BumpTech_2x
|
|
{
|
|
pass P0
|
|
{
|
|
VertexShader = compile vs_2_0 BumpMap_VS();
|
|
PixelShader = compile ps_2_0 BumpMap_PS();
|
|
}
|
|
} |