Files
Leviathan/Client/Game/Shader/terrain_effect.fx
T
2026-06-01 12:46:52 +02:00

119 lines
3.9 KiB
HLSL

#include "def_effect.fx"
//=============================================================================
//지형
VSTERRAIN_OUTPUT Terrain_VS( VSTERRAIN_INPUT In )
{
VSTERRAIN_OUTPUT Out = (VSTERRAIN_OUTPUT) 0;
float4 pos = In.position;
float3 normal = In.normal;
float4 color = In.color;
float4 output_pos, pos_world;
int b_index = 0;
// transform position to screen space before changing it.
pos_world = mul( pos, blendMatrices[b_index] );
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);
float nLength = length(Light_position - pos_world);
float3 L = normalize(Light_position - pos_world);
float Atten = 1/(1+Light_ambient.a*nLength);
// eye-base의 half-way 벡터
float3 light_vector = -Light_direction_forsp;
float3 eye_vector = Camera_position - pos_world;
float3 halfway = normalize(normalize(light_vector) + normalize(eye_vector));
float ddot = saturate(dot(normal, L));
float sdot = saturate(dot(normal, halfway));
Out.diffuse = color;// + color * ddot; // diffuse + ambient
Out.diffuse.a = color.a;
Out.specular = (Light_ambient + Light_diffuse * ddot * Atten) + (Light_specular * pow(sdot, 22));
// 지형 텍스처 연산 추가
Out.texCoord1 = fTerrain1stTextureScale * (pos_world - fTerrainTextureCenter);
Out.texCoord2 = fTerrain2ndTextureScale * (pos_world - fTerrainTextureCenter);
Out.texCoord3 = fTerrain3thTextureScale * (pos_world - fTerrainTextureCenter);
Out.texCoord4 = fTerrain4thTextureScale * pos; // 얘만 특이한 것
return Out;
}
// 안쓰임
VSTERRAIN_OUTPUT TerrainShadow_VS( VSTERRAIN_INPUT In )
{
VSTERRAIN_OUTPUT Out = (VSTERRAIN_OUTPUT) 0;
float4 pos = In.position;
float3 normal = In.normal;
float4 color = In.color;
float4 output_pos, pos_world;
int b_index = 0;
// transform position to screen space before changing it.
pos_world = mul( pos, blendMatrices[b_index] );
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);
float nLength = length(Light_position - pos_world);
float3 L = normalize(Light_position - pos_world);
// eye-base의 half-way 벡터
float3 light_vector = -Light_direction_forsp;
float3 eye_vector = Camera_position - pos_world;
float3 halfway = normalize(normalize(light_vector) + normalize(eye_vector));
//float ddot = saturate(dot(normal, L));
//float sdot = saturate(dot(normal, halfway));
Out.diffuse = color;// + color * ddot; // diffuse + ambient
Out.diffuse.a = color.a;
//Out.specular = (Light_ambient + Light_diffuse * ddot * Atten) + (Light_specular * pow(sdot, 22));
// 지형 텍스처 연산 추가
float heightturm = (pos_world.z - fTerrainTextureCenter.z);
float4 litproj = heightturm*float4(L.x, L.y, L.z, L.z);///L.z;
Out.texCoord1 = fTerrain1stTextureScale * (pos_world - fTerrainTextureCenter - litproj);
heightturm = (pos_world.z - fTerrainTextureCenterDusk.z);
litproj = heightturm*float4(L.x, L.y, L.z, L.z);///L.z;
Out.texCoord2 = fTerrain2ndTextureScale * (pos_world - fTerrainTextureCenterDusk - litproj);
return Out;
}
//=============================================================================
//지형 테크닉
technique TerrainTech
{
pass P0
{
VertexShader = compile vs_1_1 Terrain_VS();
PixelShader = NULL;
}
}
technique TerrainShadowTech
{
pass P0
{
VertexShader = compile vs_1_1 TerrainShadow_VS();
PixelShader = NULL;
}
}