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

116 lines
3.8 KiB
HLSL

#include "def_effect.fx"
//=============================================================================
//Object
VSOBJ_OUTPUT Object_VS( VSOBJ_INPUT In )
{
VSOBJ_OUTPUT Out = (VSOBJ_OUTPUT) 0;
float4 pos = In.position;
float3 normal = In.normal;
float4 color = In.diffuse;
float4 output_pos, pos_world;
int b_index = In.indices[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);
float3 N = normalize(mul(normal, (float3x3)blendMatrices[b_index])); // normal (view space)
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(N, L));
float sdot = saturate(dot(N, halfway) + 0.1);
Out.diffuse = Light_ambient + max(Light_diffuse * ddot * Atten, Light_specular * pow(sdot, 7)); // diffuse + ambient
Out.diffuse.a = fVisibility;
Out.texCoord1 = fUVAnimation.w*In.texCoord + fUVAnimation;
float heightturm = (pos_world.z - fTerrainTextureCenter.z);
float4 litproj = heightturm*float4(L.x, L.y, L.z, L.z);///L.z;
Out.texCoord2 = 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.texCoord3 = fTerrain2ndTextureScale * (pos_world - fTerrainTextureCenterDusk - litproj);
return Out;
}
VSOBJ_NOLIGHT_OUTPUT ObjectNoLight_VS( VSOBJ_INPUT In )
{
VSOBJ_NOLIGHT_OUTPUT Out = (VSOBJ_NOLIGHT_OUTPUT) 0;
float4 pos = In.position;
float3 normal = In.normal;
float4 color = In.diffuse;
float4 output_pos, pos_world;
int b_index = In.indices[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);
float3 N = normalize(mul(normal, (float3x3)blendMatrices[b_index])); // normal (view space)
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(N, L));
//float sdot = saturate(dot(normal, halfway));
Out.diffuse = Light_ambient + Light_diffuse;// * ddot * Atten + Light_specular * pow(dotval, 7); // diffuse + ambient
Out.diffuse.a = 1;//fVisibility;
Out.texCoord = fUVAnimation.w*In.texCoord + fUVAnimation;
return Out;
}
//=============================================================================
//Object Mesh Å×Å©´Ð
technique ObjectTech_2x
{
pass P0
{
VertexShader = compile vs_1_1 Object_VS();
PixelShader = NULL;
}
}
technique ObjectNoLightTech_2x
{
pass P0
{
VertexShader = compile vs_1_1 ObjectNoLight_VS();
PixelShader = NULL;
}
}