Files
2026-06-01 12:46:52 +02:00

2542 lines
77 KiB
HLSL

/******************************************************************************
DefaultEffect.fx
shader functions for Rappelz
unknown, unknown : Created and modified
2006/04, JiYoung : FX-related shaders (ALPHATEX) added
******************************************************************************/
#define VS20_COMPILE_COMMAND VertexShader = compile vs_2_0
#define VS11_COMPILE_COMMAND VertexShader = compile vs_1_1
#define PS20_COMPILE_COMMAND PixelShader = compile ps_2_0
#define PS11_COMPILE_COMMAND PixelShader = compile ps_1_1
#define BONE_NUM 57
//=======================================================
// Global변수들 : 메인 프로그램쪽에서 세팅함
//=======================================================
float4x4 view_matrix : VIEWMATRIX;
float4x4 view_proj_matrix : VIEWPROJECTIONMATRIX;
float4x4 view_proj_matrix_sb;
//float4x4 world_matrix : WORLDMATRIX;
//float4x4 world_view_matrix : WORLDVIEWMATRIX;
//float4x4 world_view_proj_matrix : WORLDVIEWPROJECTION;
float4x4 select_target_matrix;
// Light intensity
float4 Light_ambient = { 0.5f, 0.5f, 0.5f, 1.0f }; // ambient , alpha 는 Attenuation 사용
float4 Light_diffuse = { 0.2f, 0.2f, 0.2f, 1.0f }; // diffuse
float4 Light_specular = { 1.0f, 1.0f, 1.0f, 1.0f }; // specular
// Light positioning
float4 Light_halfway = { -0.4, -0.5, 0.7, 1.0 };
float3 Light_position = { 5000, 5000, 5000 };
float3 Light_direction = { -1, 0, 0 };
float3 Camera_position = { 5000, 5000, 5000 };
// Fog Setting
float fFogDistStart = 800.f;
float fFogDistEnd = 2000.f;
float fFogHeightStart = 100.f;
float fFogHeightEnd = 10000.f;
// UV Animation
float4 fUVAnimation = 0;
float fVisibility = 1.f;
//Sky Setting
float fSky_Max_height = 2000.f;
float fSky_Mid_height = 1150.f;
float fSky_Min_height = -300.f;
float4 Sky_Light_High = { .3f, .5f, 1.0f, 1.0f };
float4 Sky_Light_Mid = { .4f, .6f, .8f, 1.0f };
float4 Sky_Light_Low = { .7f, .7f, .7f, 1.0f };
// Cloud Spread - setting
float4 CloudSpread_Center = 0;
float CloudSpread_CornerDistance = 6000;
float CloudSpread_BalanceHeight = 800;
// Weather Setting
float3 WeatherAreaPosition = { 0.0f, 0.0f, 0.0f };
float3 WeatherAreaVelocity = { 0.0f, 0.0f, 0.0f }; // for unit particle
float4x4 blendMatrices[BONE_NUM];
float4 LocalCoord_Offset = { 0.0f, 0.0f, 0.0f, 0.0f }; // 로컬좌표계에서 그릴 때 그림자를 나오게 하기 위한 오프셋
float fSelfShadowAmbientFactor = 0.25f;
float fTerrainSpecularFactor = 0.75f;
float fAmbientFactor = 1.0f;
float fDiffuseFactor = 1.0f;
float fSpecularFactor = 1.0f;
// AlphaTex쪽에서 사용하는 global params
float fAlphaTexParam0=0.0f;
float fAlphaTexParam1=0.0f;
float fAlphaTexParam2=0.0f;
float fAlphaTexParam3=0.0f;
//Avatar용 고정된 라이트 매터리얼 및 스킨 디퓨즈
float4 AL_Ambient = { 1.0f, 1.0f, 1.0f, 1.0f };
float4 AL_Diffuse = { 1.0f, 1.0f, 1.0f, 1.0f };
float4 skin_diffuse = { 0.0f, 0.0f, 0.0f, 0.0f };
// 렌더링에 사용하는 텍스처 리스트
sampler DiffTexture : register(s0) = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
sampler BumpTexture : register(s1) = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
sampler IllumTexture : register(s2) = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
sampler ShadowTexture : register(s3) = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = None;
AddressU = Clamp;
AddressV = Clamp;
};
//Default=======================================================================
struct VS_INPUT
{
float4 position :POSITION;
float3 normal :NORMAL;
float4 texCoord0 :TEXCOORD0;
int4 indices :BLENDINDICES;
float2 weights :BLENDWEIGHT;
};
struct VS_OUTPUT
{
float4 position :POSITION;
float4 diffuse :COLOR0;
float4 specular :COLOR1;
float4 texCoord0 :TEXCOORD0;
float4 texCoord1 :TEXCOORD1;
float4 texCoord2 :TEXCOORD2;
//float4 texCoord3 :TEXCOORD3;
float fog :FOG;
};
//struct PS_INPUT
//{
// float4 diffuse :COLOR0;
// float4 specular :COLOR1;
// float4 texCoord0 :TEXCOORD0;
// float4 texCoord1 :TEXCOORD1;
// float4 texCoord2 :TEXCOORD2;
// float4 texCoord3 :TEXCOORD3;
//};
//=============================================================================
//Bump=======================================================================
struct VS_BUMP_INPUT
{
float4 position :POSITION;
float3 normal :NORMAL;
float4 texCoord0 :TEXCOORD0;
float4 tangent :TANGENT;
int4 indices :BLENDINDICES;
float2 weights :BLENDWEIGHT;
};
struct VS_BUMP_OUTPUT
{
float4 position :POSITION;
float4 texCoord0 :TEXCOORD0; // diffuse texture
float4 texCoord1 :TEXCOORD1; // bump texture
float4 texCoord2 :TEXCOORD2; // light vector - in tagent space
float4 texCoord3 :TEXCOORD3; // half-way vector - in tagent space
float4 texCoord4 :TEXCOORD4; // shadow buffer & depth(w)
float fog :FOG;
};
struct PS_BUMP_INPUT
{
float4 texCoord0 :TEXCOORD0; // diffuse texture
float4 texCoord1 :TEXCOORD1; // bump texture
float4 texCoord2 :TEXCOORD2; // light vector - in tagent space
float4 texCoord3 :TEXCOORD3; // half-way vector - in tagent space
float4 texCoord4 :TEXCOORD4; // shadow buffer & depth(w)
};
//Specular=======================================================================
struct VS_SPECULAR_OUTPUT
{
float4 position :POSITION;
float4 diffuse :COLOR0;
float4 specular :COLOR1;
float4 texCoord0 :TEXCOORD0;
float4 texCoord1 :TEXCOORD1;
float4 texCoord2 :TEXCOORD2;
float4 texCoord3 :TEXCOORD3;
float fog :FOG;
};
/*struct PS_INPUT
{
float4 diffuse :COLOR;
float4 texCoord0 :TEXCOORD0;
float3 normal :TEXCOORD1;
float3 normalWS :TEXCOORD4;
float4 positionWS :TEXCOORD5;
};*/
//=======================================================================
//Normal Mesh Structures
struct VSOBJ_INPUT
{
float4 position :POSITION;
float3 normal :NORMAL;
float4 diffuse :COLOR0;
float4 texCoord0 :TEXCOORD0;
int4 indices :BLENDINDICES;
};
struct VSOBJ_OUTPUT
{
float4 position :POSITION;
float4 diffuse :COLOR0;
float4 specular :COLOR1;
float4 texCoord0 :TEXCOORD0;
float4 texCoord1 :TEXCOORD1;
float4 texCoord2 :TEXCOORD2;
float fog :FOG;
};
struct VSOBJ_LIGHTMAP_OUTPUT
{
float4 position :POSITION;
float4 diffuse :COLOR0;
float4 texCoord0 :TEXCOORD0;
float4 texCoord1 :TEXCOORD1;
float4 texCoord2 :TEXCOORD2;
float4 texCoord3 :TEXCOORD3;
float fog :FOG;
};
struct VSOBJ_NOLIGHT_OUTPUT
{
float4 position :POSITION;
float4 diffuse :COLOR0;
float4 specular :COLOR1;
float4 texCoord0 :TEXCOORD0;
float fog :FOG;
};
//=======================================================================
//Terrain Structures
float4 fTerrainTextureCenter = 0;
float4 fTerrainTextureCenterDusk = 0;
float fTerrain1stTextureScale = 1.f;
float fTerrain2ndTextureScale = 1.f;
float fTerrain3thTextureScale = 1.f;
float fTerrain4thTextureScale = 1.f;
float fTerrainModTextureScale = 1.f;
float4 fLightmapUVOffset = 0;
float fLightmapUVDevider = 2688.f; // lightmap scale factor는 2 , 4 , 8, 16으로 고정하므로 이 값을 유지하자.
struct VSTERRAIN_INPUT
{
float4 position :POSITION;
float3 normal :NORMAL;
float4 color :COLOR0;
};
struct VSTERRAIN_OUTPUT
{
float4 position :POSITION;
float4 diffuse :COLOR0;
float4 texCoord0 :TEXCOORD0;
float4 texCoord1 :TEXCOORD1;
float4 texCoord2 :TEXCOORD2;
float4 texCoord3 :TEXCOORD3;
float4 texCoord4 :TEXCOORD4;
float fog :FOG;
};
struct PSTERRAIN_INPUT
{
float4 diffuse :COLOR0;
float4 texCoord0 :TEXCOORD0;
float4 texCoord1 :TEXCOORD1;
float4 texCoord2 :TEXCOORD2;
float4 texCoord3 :TEXCOORD3;
};
//=======================================================================
// Weather Structures
struct VSWEATHER_INPUT
{
float4 local :POSITION;
float3 position :NORMAL;
float4 diffuse :COLOR0;
float2 texCoord0 :TEXCOORD0;
};
struct VSWEATHER_OUTPUT
{
float4 position :POSITION;
float4 diffuse :COLOR0;
float2 texCoord0 :TEXCOORD0;
};
//===========================================================================================
// SkinPoint
// Applies 4 matrix skinning to a single point. The point passed in is changed as well as returned.
//
float4 SkinPoint( inout float4 io_value, int4 indices, float2 weights)
{
int i;
float4 incoming_io_value = io_value;
if(weights[0] != -1 )
{
io_value = 0;
// skin
io_value += mul( incoming_io_value, blendMatrices[indices[0]]) * weights[0];
io_value += mul( incoming_io_value, blendMatrices[indices[1]]) * weights[1];
}
return io_value;
}
//===========================================================================================
// SkinVector
// Applies 4 matrix skinning to a vector. The vector passed in is changed as well as returned.
//
float3 SkinVector( inout float3 io_value, int4 indices, float2 weights)
{
int i;
float3 incoming_io_value = io_value;
if(weights[0] != -1 )
{
io_value = 0;
io_value += mul( incoming_io_value, blendMatrices[indices[0]]) * weights[0];
io_value += mul( incoming_io_value, blendMatrices[indices[1]]) * weights[1];
io_value = normalize(io_value); // 이거 키면 tangent가 0이 되는 부분이 있어서 일단 삭제
}
return io_value;
}
//=============================================================================
//캐릭터 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 , In.indices, In.weights); // pos is changed.
float3 N = SkinVector( normal , In.indices, In.weights); // normal is changed.
float3 T = SkinVector( tangent, In.indices, In.weights); // tangent is changed.
//float3 binormal = flipper*cross(normal, tangent);
float3 B = flipper*cross(N, T);
// transform position to screen space before changing it.
output_pos = mul( pos_world, view_proj_matrix );
Out.position = output_pos;
pos_world = pos_world + LocalCoord_Offset;
// light vector
float3 light_vec = -Light_direction;//Light_position - pos_world;
// eye-base의 half-way 벡터
float3 eye_vector = Camera_position - pos_world;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
tex = fUVAnimation.w*In.texCoord0 + 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;
Out.texCoord2.x = dot(light_vec, T);
Out.texCoord2.y = dot(light_vec, B);
Out.texCoord2.z = dot(light_vec, N);
Out.texCoord2.w = 1;
Out.texCoord3.x = dot(Light_halfway, T);
Out.texCoord3.y = dot(Light_halfway, B);
Out.texCoord3.z = dot(Light_halfway, N);
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;
if(ddot <= 0) sdot = 0; else sdot = saturate(dot(n, halfway_vec));
float Atten = 1/(1+(Light_ambient.a*light_length));
float4 m_col = Light_ambient * fAmbientFactor + (Light_diffuse * fDiffuseFactor * ddot * Atten);
outc = d_col*m_col*2 + (Light_specular * fSpecularFactor * pow(sdot, 20) * glossness + illum);
//outc.w = Light_diffuse.w*d_col.w;
outc.w = Light_diffuse.w * d_col.w * fVisibility;
return outc;
}
//=============================================================================
//캐릭터 Bump Map 포함
VS_BUMP_OUTPUT BumpMapSS_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 , In.indices, In.weights); // pos is changed.
float3 N = SkinVector( normal , In.indices, In.weights); // normal is changed.
float3 T = SkinVector( tangent, In.indices, In.weights); // tangent is changed.
float3 B = flipper*cross(normal, tangent);
// transform position to screen space before changing it.
output_pos = mul( pos_world, view_proj_matrix );
Out.position = output_pos;
pos_world = pos_world + LocalCoord_Offset;
// light vector
float3 light_vec = -Light_direction;//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));
//float ddot = saturate(dot(N, L));
//float sdot = saturate(dot(N, halfway));
//Out.diffuse = Light_ambient * fAmbientFactor + max(Light_diffuse * fDiffuseFactor * ddot * Atten, Light_specular * pow(sdot, 7)); // specular + diffuse + ambient
//Out.diffuse.a = fVisibility;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
tex = fUVAnimation.w*In.texCoord0 + 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;
Out.texCoord2.x = dot(light_vec, T);
Out.texCoord2.y = dot(light_vec, B);
Out.texCoord2.z = dot(light_vec, N);
Out.texCoord2.w = 1;
Out.texCoord3.x = dot(Light_halfway, T);
Out.texCoord3.y = dot(Light_halfway, B);
Out.texCoord3.z = dot(Light_halfway, N);
Out.texCoord3.w = 1;
// 셀프 쉐도우
float4 sb_pos = mul( pos_world, view_proj_matrix_sb );
Out.texCoord4.x = sb_pos.x*0.5 + 0.5;
Out.texCoord4.y = sb_pos.y*-0.5 + 0.5;
//Out.texCoord4.z = output_pos.z;
if(sb_pos.z > 0.99)
Out.texCoord4.w = 0;
else
//Out.texCoord4.w = sb_pos.z - 0.00009;
Out.texCoord4.w = sb_pos.z - 0.0009;
return Out;
}
float4 BumpMapSS_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);
float depth = In.texCoord4.w;
//float offset = ( depth + 0.01f ) * 0.002f;
//float offset = ( 1.01f - In.texCoord4.z ) * 0.0002f;
//float offset = 0.00098f;
float offset = 0.0025f;
//float offset = 0.001f;
float shadow = 0.0f;
float4 bias_depth;
float4 shadowmap_depth;
// +x
bias_depth = In.texCoord4;
bias_depth.x += offset; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.25f;
// -x
bias_depth = In.texCoord4;
bias_depth.x -= offset; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.25f;
// +y
bias_depth = In.texCoord4;
bias_depth.y += offset; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.25f;
// -y
bias_depth = In.texCoord4;
bias_depth.y -= offset; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.25f;
/*
// 기본
float4 bias_depth = In.texCoord4;
float4 shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow = 0.2f;
// +x
//bias_depth = In.texCoord4;
bias_depth.x += 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1f;
bias_depth.x += 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1f;
// -x
bias_depth = In.texCoord4;
bias_depth.x -= 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1f;
bias_depth.x -= 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1f;
// +y
bias_depth = In.texCoord4;
bias_depth.y += 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1f;
bias_depth.y += 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1f;
// -y
bias_depth = In.texCoord4;
bias_depth.y -= 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1f;
bias_depth.y -= 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1f;
*/
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;
if(ddot <= 0) sdot = 0; else sdot = saturate(dot(n, halfway_vec));
float Atten = 1/(1+(Light_ambient.a*light_length));
float fAmbientFactor = saturate( shadow + fSelfShadowAmbientFactor );
//float4 m_col = Light_ambient * fAmbientFactor + (Light_diffuse * fDiffuseFactor * ddot * Atten)*shadow;
float4 m_col = Light_ambient * fAmbientFactor * fAmbientFactor + (Light_diffuse * fDiffuseFactor * ddot * Atten) * shadow;
outc = d_col*m_col*2 + (Light_specular * pow(sdot, 20) * glossness * shadow + illum);
//outc = d_col * shadow;
//outc.w = Light_diffuse.w*d_col.w;
outc.w = Light_diffuse.w * d_col.w * fVisibility;
return outc;
}
//=============================================================================
//캐릭터 Specular 포함
VS_SPECULAR_OUTPUT Specular_VS( VS_INPUT In )
{
VS_SPECULAR_OUTPUT Out = (VS_SPECULAR_OUTPUT)0;
float4 pos = In.position;
float3 normal = In.normal;
float4 tex = 0;
float4 output_pos, pos_world;
pos_world = SkinPoint( pos , In.indices, In.weights); // pos is changed.
float3 N = SkinVector( normal, In.indices, In.weights); // normal is changed.
// transform position to screen space before changing it.
output_pos = mul( pos_world, view_proj_matrix );
Out.position = output_pos;
pos_world = pos_world + LocalCoord_Offset;
if( skin_diffuse.w == 0.0f )
{
float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
//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));
//Out.diffuse = Light_ambient * fAmbientFactor + max(Light_diffuse * fDiffuseFactor * ddot * Atten, Light_specular * pow(sdot, 7)); // specular + diffuse + ambient
Out.diffuse = Light_ambient * fAmbientFactor + Light_diffuse * fDiffuseFactor * ddot * Atten; // diffuse + ambient
}
else
{
float3 L = Camera_position - pos_world; //고정된 라이트 방향이 아닌 카메라 와 정점의 방향
L = normalize(L);
float ddot = saturate(dot(N, L));
float4 diffuse = skin_diffuse / 255.0f;
Out.diffuse = /*AL_Ambient * fAmbientFactor + AL_Diffuse * */diffuse/** ddot*/;
}
Out.diffuse.a = fVisibility;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
// tex = fUVAnimation.w * In.texCoord0 + fUVAnimation;
tex = In.texCoord0;
Out.specular = Light_specular;
Out.texCoord0 = tex;
// Out.texCoord1 = fUVAnimation.w * In.texCoord0 + fUVAnimation;
Out.texCoord1 = tex;
Out.texCoord2.xy = saturate( dot(N, Light_halfway) * fSpecularFactor );
Out.texCoord3 = fUVAnimation.w * In.texCoord0 + fUVAnimation;
return Out;
}
//=============================================================================
//캐릭터
VS_OUTPUT Default_VS( VS_INPUT In )
{
VS_OUTPUT Out = (VS_OUTPUT) 0;
float4 pos = In.position;
float3 normal = In.normal;
float4 output_pos, pos_world;
pos_world = SkinPoint( pos , In.indices, In.weights); // pos is changed.
float3 N = SkinVector( normal, In.indices, In.weights); // normal is changed.
// transform position to screen space before changing it.
output_pos = mul( pos_world, view_proj_matrix );
Out.position = output_pos;
pos_world = pos_world + LocalCoord_Offset;
if( skin_diffuse.w == 0.0f )
{
float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
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));
Out.diffuse = Light_ambient * fAmbientFactor + max(Light_diffuse * fDiffuseFactor * ddot * Atten, Light_specular * fSpecularFactor * pow(sdot, 7)); // diffuse + ambient
}
else
{
float3 L = Camera_position - pos_world; //고정된 라이트 방향이 아닌 카메라 와 정점의 방향
L = normalize(L);
float ddot = saturate(dot(N, L));
float4 diffuse = skin_diffuse / 255.0f;
Out.diffuse = /*AL_Ambient * fAmbientFactor + AL_Diffuse * */diffuse/** ddot*/;
}
Out.diffuse.a = fVisibility;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
Out.texCoord0 = In.texCoord0;
Out.texCoord1 = fUVAnimation.w * In.texCoord0 + fUVAnimation;
//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);
// float4 sb_pos = mul( pos_world, view_proj_matrix_sb );
// Out.texCoord3.x = sb_pos.x*0.5 + 0.5;
// Out.texCoord3.y = sb_pos.y*-0.5 + 0.5;
// if(sb_pos.z > 0.99)
// Out.texCoord3.w = 0;
// else
// Out.texCoord3.w = sb_pos.z - 0.00009;
return Out;
}
VS_OUTPUT DefaultNoUvAni2nd_VS( VS_INPUT In )
{
VS_OUTPUT Out = (VS_OUTPUT) 0;
float4 pos = In.position;
float3 normal = In.normal;
float4 output_pos, pos_world;
pos_world = SkinPoint( pos , In.indices, In.weights); // pos is changed.
float3 N = SkinVector( normal, In.indices, In.weights); // normal is changed.
// transform position to screen space before changing it.
output_pos = mul( pos_world, view_proj_matrix );
Out.position = output_pos;
pos_world = pos_world + LocalCoord_Offset;
float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
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));
Out.diffuse = Light_ambient * fAmbientFactor + max(Light_diffuse * fDiffuseFactor * ddot * Atten, Light_specular * fSpecularFactor * pow(sdot, 7)); // diffuse + ambient
Out.diffuse.a = fVisibility;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
Out.texCoord0 = fUVAnimation.w * In.texCoord0 + fUVAnimation;
Out.texCoord1 = In.texCoord0;
//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);
// float4 sb_pos = mul( pos_world, view_proj_matrix_sb );
// Out.texCoord3.x = sb_pos.x*0.5 + 0.5;
// Out.texCoord3.y = sb_pos.y*-0.5 + 0.5;
// if(sb_pos.z > 0.99)
// Out.texCoord3.w = 0;
// else
// Out.texCoord3.w = sb_pos.z - 0.00009;
return Out;
}
/*
float4 Default_PS( PS_INPUT In ) : COLOR
{
float4 d_col = tex2D(DiffTexture, In.texCoord0);
float4 outc;
float depth = In.texCoord3.w;
float shadow = 0;
// 기본
float4 bias_depth = In.texCoord3;
float4 shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow = 0.2;
// +x
//bias_depth = In.texCoord3;
bias_depth.x += 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1;
bias_depth.x += 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1;
// -x
bias_depth = In.texCoord3;
bias_depth.x -= 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1;
bias_depth.x -= 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1;
// +y
bias_depth = In.texCoord3;
bias_depth.y += 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1;
bias_depth.y += 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1;
// -y
bias_depth = In.texCoord3;
bias_depth.y -= 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1;
bias_depth.y -= 0.00098; shadowmap_depth = tex2D(ShadowTexture, bias_depth);
if(shadowmap_depth.x >= depth) shadow += 0.1;
//outc = d_col * 2 * shadow;
//outc.w = Light_diffuse.w * d_col.w;
outc = shadow;
return outc;
}
*/
/*float4 Default_PS( PS_INPUT In ) : COLOR
{
float4 c= {1.0,0,1,0};// error
c = tex2D( inputTexture, In.texCoord);
return c;
}*/
//=============================================================================
//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/255;
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] );
float3 N = normalize(mul(normal, (float3x3)blendMatrices[b_index]));
output_pos = mul( pos_world, view_proj_matrix );
Out.position = output_pos;
pos_world = pos_world + LocalCoord_Offset;
float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
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));
Out.diffuse = Light_ambient + max(Light_diffuse * ddot * Atten, Light_specular * pow(sdot, 7)); // diffuse + ambient
Out.diffuse.a = fVisibility;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
Out.texCoord0 = fUVAnimation.w * In.texCoord0 + fUVAnimation;
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;
}
//Object Lightmap
VSOBJ_LIGHTMAP_OUTPUT Object_Lightmap_VS( VS_INPUT In )
{
VSOBJ_LIGHTMAP_OUTPUT Out = (VSOBJ_LIGHTMAP_OUTPUT) 0;
float4 pos = In.position;
float3 normal = In.normal;
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;
pos_world = pos_world + LocalCoord_Offset;
float3 light_vec = -Light_direction;//Light_position - pos_world;
float3 L = normalize(light_vec);
float3 N = normalize(mul(normal, (float3x3)blendMatrices[b_index]));
float3 eye_vector = Camera_position - pos_world;
float3 halfway = normalize(L + normalize(eye_vector));
float sdot = saturate(dot(N, halfway));
// 엔진에서 0.5로 나눠주기 때문에 다시 곱해준다.
Out.diffuse.rgb = Light_diffuse * 2.f + Light_specular * pow(sdot, 7);
Out.diffuse.a = fVisibility;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
Out.texCoord0.xy = In.weights.xy;
Out.texCoord1 = fUVAnimation.w * In.texCoord0 + 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/255;
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] );
float3 N = normalize(mul(normal, (float3x3)blendMatrices[b_index])); // normal (view space)
output_pos = mul( pos_world, view_proj_matrix );
Out.position = output_pos;
//pos_world = pos_world + LocalCoord_Offset;
float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
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;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
Out.texCoord0 = fUVAnimation.w * In.texCoord0 + fUVAnimation;
return Out;
}
VSOBJ_NOLIGHT_OUTPUT SkyBox_VS( VSOBJ_INPUT In )
{
VSOBJ_NOLIGHT_OUTPUT Out = (VSOBJ_NOLIGHT_OUTPUT) 0;
float4 pos = In.position;
float3 normal = In.normal;
//float4 color = In.diffuse/255;
float4 output_pos, pos_world;
int b_index = 0;
float fValue = 0.f;
// transform position to screen space before changing it.
pos_world = mul( pos, blendMatrices[b_index] );
//float3 N = normalize(mul(normal, (float3x3)blendMatrices[b_index])); // normal (view space)
output_pos = mul( pos_world, view_proj_matrix );
Out.position = output_pos;
//apply fog
float heightfog = 1.f-saturate((fSky_Mid_height - pos_world.z)/fSky_Mid_height);
Out.fog = heightfog;
//float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
//float3 eye_vector = Camera_position - pos_world;
//float3 halfway = normalize(normalize(light_vector) + normalize(eye_vector));
if( pos_world.z > fSky_Mid_height )
{
fValue = (pos_world.z-fSky_Mid_height)/(fSky_Max_height-fSky_Mid_height);
fValue = saturate( fValue );
Out.diffuse = Sky_Light_High * fValue + Sky_Light_Mid * (1-fValue);// * ddot * Atten + Light_specular * pow(dotval, 7); // diffuse + ambient
}
else
{
fValue = (pos_world.z-fSky_Min_height)/(fSky_Mid_height-fSky_Min_height);
fValue = saturate( fValue );
Out.diffuse = Sky_Light_Mid * fValue + Sky_Light_Low * (1-fValue);// * ddot * Atten + Light_specular * pow(dotval, 7); // diffuse + ambient
}
Out.diffuse.a = 1;
Out.texCoord0 = In.texCoord0;
return Out;
}
VSOBJ_NOLIGHT_OUTPUT CloudSpread_VS( VSOBJ_INPUT In )
{
VSOBJ_NOLIGHT_OUTPUT Out = (VSOBJ_NOLIGHT_OUTPUT) 0;
float4 pos = In.position;
float3 normal = In.normal;
float4 color = In.diffuse/255;
float4 output_pos, pos_world;
int b_index = 0;
pos_world = mul( pos, blendMatrices[b_index] );
// pos_world = pos;
//float3 N = normalize(mul(normal, (float3x3)blendMatrices[b_index])); // normal (view space)
float dVal = length(float2(pos_world.x, pos_world.y) - float2(CloudSpread_Center.x, CloudSpread_Center.y));
dVal = pow(saturate((CloudSpread_CornerDistance - dVal)/CloudSpread_CornerDistance), 2);
pos_world.z -= (1-dVal)*CloudSpread_BalanceHeight;
// 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((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
//float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = 1;//min(1-distfog*distfog, heightfog);
//float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
//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));
//Out.diffuse = colorLight_ambient + max(Light_diffuse * ddot * Atten, Light_specular * pow(sdot, 7)); // diffuse + ambient
//Out.diffuse.a = fVisibility;
float fValue = (pos_world.z-fSky_Min_height)/(fSky_Max_height-fSky_Min_height);
fValue = saturate( fValue );
float4 output_color = Sky_Light_High * fValue + Sky_Light_Low * (1-fValue);
output_color = (1 - fVisibility)*output_color + fVisibility*color; // diffuse + ambient
Out.diffuse.x = output_color.z;
Out.diffuse.y = output_color.y;
Out.diffuse.z = output_color.x;
Out.diffuse.a = color.a;
Out.texCoord0 = In.texCoord0;
//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;
}
//=============================================================================
//지형
float4 temp_gap_texture = { 42, 42, 42, 42 };
VSTERRAIN_OUTPUT Terrain_VS( VSTERRAIN_INPUT In )
{
VSTERRAIN_OUTPUT Out = (VSTERRAIN_OUTPUT) 0;
float4 pos = In.position;
float3 N = In.normal;
float4 color = In.color/255;
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;
pos_world = pos_world + LocalCoord_Offset;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
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));
if(dot(color, float4(1, 1, 1, 1)) < 4) sdot = 0;
//Out.diffuse = ((Light_ambient + Light_diffuse * ddot * Atten) + (Light_specular * pow(sdot, 22)))*color;
Out.diffuse = ( Light_ambient ) + ( Light_diffuse * ddot * Atten * color ) + ( Light_specular * fTerrainSpecularFactor * pow( sdot, 22 ) );
Out.diffuse.a = color.a;
// 지형 텍스처 연산 추가
Out.texCoord0 = fTerrainModTextureScale * (pos + temp_gap_texture); // used to modulate textures
Out.texCoord1 = fTerrain1stTextureScale * (pos_world - fTerrainTextureCenter); // base texture
Out.texCoord2 = fTerrain2ndTextureScale * (pos_world - fTerrainTextureCenter); // decoration1
Out.texCoord3 = fTerrain3thTextureScale * (pos_world - fTerrainTextureCenter); // decoration2
return Out;
}
//지형
VSTERRAIN_OUTPUT Terrain_Lightmap_VS( VSTERRAIN_INPUT In )
{
VSTERRAIN_OUTPUT Out = (VSTERRAIN_OUTPUT) 0;
float4 pos = In.position;
float3 N = In.normal;
float4 color = In.color/255;
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;
pos_world = pos_world + LocalCoord_Offset;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
float3 eye_vector = Camera_position - pos_world;
float3 halfway = normalize(normalize(light_vector) + normalize(eye_vector));
float sdot = saturate(dot(N, halfway));
// Device에서 diffuse light를 2로 나눠서 넣어주므로 바꾸자.
Out.diffuse = Light_diffuse * 2.f + ( Light_specular * fTerrainSpecularFactor * pow( sdot, 22 ) );
Out.diffuse.a = color.a;
// 지형 텍스처 연산 추가
Out.texCoord0 = fTerrainModTextureScale * (pos + temp_gap_texture); // used to modulate textures
Out.texCoord1 = fTerrain1stTextureScale * (pos_world - fTerrainTextureCenter); // base texture
Out.texCoord2 = fTerrain2ndTextureScale * (pos_world - fTerrainTextureCenter); // decoration1
Out.texCoord3 = fTerrain3thTextureScale * (pos_world - fTerrainTextureCenter); // decoration2
Out.texCoord4 = fLightmapUVOffset + pos / fLightmapUVDevider;
return Out;
}
VSTERRAIN_OUTPUT Terrain_1stPass_VS( VSTERRAIN_INPUT In )
{
VSTERRAIN_OUTPUT Out = (VSTERRAIN_OUTPUT) 0;
float4 pos = In.position;
// float3 N = In.normal;
float4 color = In.color/255;
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;
pos_world = pos_world + LocalCoord_Offset;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
// float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
// 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));
// if(dot(color, float4(1, 1, 1, 1)) < 4) sdot = 0;
// Out.diffuse = ((Light_ambient + Light_diffuse * ddot * Atten) + (Light_specular * pow(sdot, 22)))*color;
// Out.diffuse.a = color.a;
// 지형 텍스처 연산 추가
Out.texCoord0 = fTerrainModTextureScale * (pos + temp_gap_texture); // used to modulate textures
Out.texCoord1 = fTerrain2ndTextureScale * (pos_world - fTerrainTextureCenter); // decoration1
return Out;
}
VSTERRAIN_OUTPUT Terrain_2ndPass_VS( VSTERRAIN_INPUT In )
{
VSTERRAIN_OUTPUT Out = (VSTERRAIN_OUTPUT) 0;
float4 pos = In.position;
// float3 N = In.normal;
float4 color = In.color/255;
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;
pos_world = pos_world + LocalCoord_Offset;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
// float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
// 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));
// if(dot(color, float4(1, 1, 1, 1)) < 4) sdot = 0;
// Out.diffuse = ((Light_ambient + Light_diffuse * ddot * Atten) + (Light_specular * pow(sdot, 22)))*color;
// Out.diffuse.a = color.a;
// 지형 텍스처 연산 추가
Out.texCoord0 = fTerrainModTextureScale * (pos + temp_gap_texture); // used to modulate textures
Out.texCoord1 = fTerrain1stTextureScale * (pos_world - fTerrainTextureCenter); // base texture
return Out;
}
VSTERRAIN_OUTPUT Terrain_3rdPass_VS( VSTERRAIN_INPUT In )
{
VSTERRAIN_OUTPUT Out = (VSTERRAIN_OUTPUT) 0;
float4 pos = In.position;
// float3 N = In.normal;
float4 color = In.color/255;
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;
pos_world = pos_world + LocalCoord_Offset;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
// float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
// 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));
// if(dot(color, float4(1, 1, 1, 1)) < 4) sdot = 0;
// Out.diffuse = ((Light_ambient + Light_diffuse * ddot * Atten) + (Light_specular * pow(sdot, 22)))*color;
// Out.diffuse.a = color.a;
// 지형 텍스처 연산 추가
Out.texCoord0 = fTerrainModTextureScale * (pos + temp_gap_texture); // used to modulate textures
Out.texCoord1 = fTerrain3thTextureScale * (pos_world - fTerrainTextureCenter); // decoration2
return Out;
}
VSTERRAIN_OUTPUT Terrain_4thPass_VS( VSTERRAIN_INPUT In )
{
VSTERRAIN_OUTPUT Out = (VSTERRAIN_OUTPUT) 0;
float4 pos = In.position;
// float3 N = In.normal;
float4 color = In.color/255;
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;
pos_world = pos_world + LocalCoord_Offset;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
// float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
// 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));
// if(dot(color, float4(1, 1, 1, 1)) < 4) sdot = 0;
// Out.diffuse = ((Light_ambient + Light_diffuse * ddot * Atten) + (Light_specular * pow(sdot, 22)))*color;
// Out.diffuse.a = color.a;
// 지형 텍스처 연산 추가
//Out.texCoord0 = fTerrainModTextureScale * (pos + temp_gap_texture); // used to modulate textures
//Out.texCoord1 = fTerrain3thTextureScale * (pos_world - fTerrainTextureCenter); // decoration2
return Out;
}
//VSTERRAIN_OUTPUT Terrain_5thPass_VS( VSTERRAIN_INPUT In )
//{
// VSTERRAIN_OUTPUT Out = (VSTERRAIN_OUTPUT) 0;
// float4 pos = In.position;
// float3 N = In.normal;
//float4 color = In.color/255;
// float4 color = {0, 0, 0, 1};
// 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((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
// float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
// Out.fog = min(1-distfog*distfog, heightfog);
// float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
// 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));
// if(dot(color, float4(1, 1, 1, 1)) < 4) sdot = 0;
// Out.diffuse = ((Light_ambient + Light_diffuse * ddot * Atten) + (Light_specular * pow(sdot, 22)))*color;
// Out.diffuse.a = color.a;
// 지형 텍스처 연산 추가
//Out.texCoord0 = fTerrainModTextureScale * (pos + temp_gap_texture); // used to modulate textures
//Out.texCoord1 = fTerrain3thTextureScale * (pos_world - fTerrainTextureCenter); // decoration2
// return Out;
//}
sampler terrain_s0 : register(s0) = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;
AddressU = Wrap;
AddressV = Wrap;
};
sampler terrain_s1 : register(s1) = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
sampler terrain_s2 : register(s2) = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
sampler terrain_s3 : register(s3) = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
float4 Terrain_PS( PSTERRAIN_INPUT In ) : COLOR
{
float4 res;
float4 modtex = tex2D(terrain_s0, In.texCoord0);
float4 invmodtex = 1 - modtex;
float4 basetex = tex2D(terrain_s1, In.texCoord1);
float4 deco1tex = tex2D(terrain_s2, In.texCoord2);
float4 deco2tex = tex2D(terrain_s3, In.texCoord3);
res = basetex * invmodtex.r + deco1tex * modtex.r;
res = res * invmodtex.a + deco2tex * modtex.a;
res = res * modtex.g * In.diffuse * 2;
return res;
}
// 안쓰임 - 이거 왜 안 쓰인다며 쓰이고 있지.. ㅡ.,ㅡ by blackfish
VSTERRAIN_OUTPUT TerrainShadow_VS( VSTERRAIN_INPUT In )
{
VSTERRAIN_OUTPUT Out = (VSTERRAIN_OUTPUT) 0;
float4 pos = In.position;
float3 N = In.normal;
float4 color = In.color/255;
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;
pos_world = pos_world + LocalCoord_Offset;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
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));
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.texCoord0 = 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.texCoord1 = fTerrain2ndTextureScale * (pos_world - fTerrainTextureCenterDusk - litproj);
return Out;
}
//=============================================================================
//캐릭터 테크닉
technique DefaultTech_2x
{
pass P0
{
VS20_COMPILE_COMMAND Default_VS();
PixelShader = NULL;
//PS20_COMPILE_COMMAND Default_PS();
}
}
technique DefaultTechNoUvAni2nd_2x
{
pass P0
{
VS20_COMPILE_COMMAND DefaultNoUvAni2nd_VS();
PixelShader = NULL;
}
}
//=============================================================================
//Bump 테크닉
technique BumpTech_2x
{
pass P0
{
VS20_COMPILE_COMMAND BumpMap_VS();
PS20_COMPILE_COMMAND BumpMap_PS();
}
}
//=============================================================================
//Bump & SelfShadow 테크닉
technique BumpSSTech_2x
{
pass P0
{
VS20_COMPILE_COMMAND BumpMapSS_VS();
PS20_COMPILE_COMMAND BumpMapSS_PS();
}
}
//=============================================================================
//Specular 테크닉
technique SpecularTech_2x
{
pass P0
{
//VS20_COMPILE_COMMAND Specular_VS(); // 이걸 왜 2.0으로.. -_-+
VS11_COMPILE_COMMAND Specular_VS();
PixelShader = NULL;
}
}
//=============================================================================
//Object Mesh 테크닉
technique ObjectTech_2x
{
pass P0
{
VS11_COMPILE_COMMAND Object_VS();
PixelShader = NULL;
}
}
technique ObjectTech_LightMap
{
pass P0
{
VS11_COMPILE_COMMAND Object_Lightmap_VS();
PixelShader = NULL;
}
}
technique ObjectNoLightTech_2x
{
pass P0
{
VS11_COMPILE_COMMAND ObjectNoLight_VS();
PixelShader = NULL;
}
}
technique SkyBox_Tech
{
pass P0
{
VS11_COMPILE_COMMAND SkyBox_VS();
PixelShader = NULL;
}
}
technique CloudSpread_Tech
{
pass P0
{
VS11_COMPILE_COMMAND CloudSpread_VS();
PixelShader = NULL;
}
}
//=============================================================================
//지형 테크닉
technique TerrainTech
{
pass P0
{
VS11_COMPILE_COMMAND Terrain_VS();
// PS11_COMPILE_COMMAND Terrain_PS();
PixelShader = NULL;
}
}
technique TerrainLightmapTech
{
pass P0
{
VS11_COMPILE_COMMAND Terrain_Lightmap_VS();
PixelShader = NULL;
}
}
technique TerrainTech_1stPass
{
pass P0
{
VS11_COMPILE_COMMAND Terrain_1stPass_VS();
PixelShader = NULL;
}
}
technique TerrainTech_2ndPass
{
pass P0
{
VS11_COMPILE_COMMAND Terrain_2ndPass_VS();
PixelShader = NULL;
}
}
technique TerrainTech_3rdPass
{
pass P0
{
VS11_COMPILE_COMMAND Terrain_3rdPass_VS();
PixelShader = NULL;
}
}
technique TerrainTech_4thPass
{
pass P0
{
VS11_COMPILE_COMMAND Terrain_4thPass_VS();
PixelShader = NULL;
}
}
//technique TerrainTech_5thPass
//{
// pass P0
// {
// VS11_COMPILE_COMMAND Terrain_5thPass_VS();
// PixelShader = NULL;
// }
//}
technique TerrainShadowTech
{
pass P0
{
VS11_COMPILE_COMMAND TerrainShadow_VS();
PixelShader = NULL;
}
}
// Shadow Buffer를 위한 technique
// 1. bone을 사용하는놈과 안사용하는놈을 나눈다
// 2. 제3의 view & projection을 사용한다.
// 3. 지형에는 적용하지 않는다.
struct VS_SB_OUTPUT
{
float4 position :POSITION;
float4 texCoord0 :TEXCOORD0;
};
VS_SB_OUTPUT ShadowBuffer_Blend_VS( VS_INPUT In )
{
VS_SB_OUTPUT Out = (VS_SB_OUTPUT) 0;
float4 pos = In.position;
float4 output_pos, pos_world;
pos_world = SkinPoint( pos , In.indices, In.weights); // pos is changed.
// transform position to screen space before changing it.
output_pos = mul( pos_world, view_proj_matrix_sb );
Out.position = output_pos;
if(output_pos.z > 0.99)
Out.texCoord0.x = 0;
else
Out.texCoord0.x = output_pos.z;
return Out;
}
float4 ShadowBuffer_PS( float4 In : TEXCOORD0 ) : COLOR
{
return In.x;
}
//=============================================================================
// Shadow Buffer Technique
technique ShadowBuffer_Tech
{
pass P0
{
VS20_COMPILE_COMMAND ShadowBuffer_Blend_VS();
PS20_COMPILE_COMMAND ShadowBuffer_PS();
//PixelShader = NULL;
}
}
// hdr
#define HDR_NUMSAMPLES 11 // HDR_NUMSAMPLES * 2 + 1
//#define HDR_NUMSAMPLES 13 // pow( HDR_SAMPLESPAN + 1, 2 ) / 2 - HDR_SAMPLESPAN
float2 g_vBlurSampleOffset[ HDR_NUMSAMPLES ];
float g_fBlurSampleWeight[ HDR_NUMSAMPLES ];
sampler g_blurs0 : register( s0 ) = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;
AddressU = CLAMP;
AddressV = CLAMP;
};
float2 g_vBlurSampleOffset2 = { 1.0f / 1024.0f, 1.0f / 1024.0f };
// blur
float4 Blur_PS( float2 vTexCoord : TEXCOORD0 ) : COLOR
{
float4 vAccum = 0.0f;
float2 vSamplePos;
for( int i = 0; i < HDR_NUMSAMPLES; i++ )
{
vSamplePos = vTexCoord + g_vBlurSampleOffset[ i ] + g_vBlurSampleOffset2;
vAccum.xyz += tex2D( g_blurs0, vSamplePos ) * g_fBlurSampleWeight[ i ];
}
vAccum.w = 1.0f;
return vAccum;
}
technique Blur_Tech
{
pass P0
{
VertexShader = NULL;
PS20_COMPILE_COMMAND Blur_PS();
}
}
sampler g_tones0 : register( s0 ) = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;
AddressU = CLAMP;
AddressV = CLAMP;
};
sampler g_tones1 : register( s1 ) = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;
AddressU = CLAMP;
AddressV = CLAMP;
};
sampler g_tones2 : register( s2 ) = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;
AddressU = CLAMP;
AddressV = CLAMP;
};
// tone mapping
float g_fBlurMixRatio = 0.4f;
float g_fSceneExposure = 1.2f;
float g_fSceneGamma = 0.9f;
float4 Tone_PS( float2 vTexCoord : TEXCOORD0 ) : COLOR
{
float4 vSource, vBlur, vRes;
vSource.xyz = tex2D( g_tones0, vTexCoord );
vBlur.xyz = tex2D( g_tones1, vTexCoord );
float4 outlineColor = tex2D(g_tones2, vTexCoord);
vRes.xyz = lerp( vSource.xyz, vBlur.xyz, g_fBlurMixRatio );
vTexCoord -= 0.5f;
float fVignette = 1 - dot( vTexCoord, vTexCoord );
//vRes = vRes * fVignette * fVignette * fVignette * fVignette;
vRes.xyz = vRes.xyz * fVignette;
vRes.xyz *= g_fSceneExposure;
vRes.xyz = pow( vRes.xyz, g_fSceneGamma );
vRes.w = 1.0f;
vRes.xyz += outlineColor.xyz;
return vRes;
}
technique Tone_Tech
{
pass P0
{
VertexShader = NULL;
PS20_COMPILE_COMMAND Tone_PS();
}
}
//// glow 효과
//#define MAX_SAMPLES 15
//float2 g_avGlowSampleOffsets[MAX_SAMPLES];
//float4 g_avGlowSampleWeights[MAX_SAMPLES];
//// Glow 효과에 사용하는 텍스처 리스트
//sampler g_s0 : register(s0) = sampler_state
//{
// MinFilter = LINEAR;
// MagFilter = LINEAR;
// MipFilter = NONE;
// AddressU = Clamp;
// AddressV = Clamp;
//};
//sampler g_s1 : register(s1);
//sampler g_s2 : register(s2);
//sampler g_s3 : register(s3);
//sampler g_s4 : register(s4);
//sampler g_s5 : register(s5);
//sampler g_s6 : register(s6);
//sampler g_s7 : register(s7);
//float4 glow_color_average = { 0.3333, 0.3333, 0.3333, 0 };
//float4 glow_color_distort = { 1, 0, 0, 0 };
////=============================================================================
////Glow 효과 pixel shader
//float4 Glow_PS( in float2 vScreenPosition : TEXCOORD0 ) : COLOR
//{
// float4 vSample = 0.0f;
// float4 vColor = 0.0f;
// float2 vSamplePosition = vScreenPosition;
// // Perform a one-directional gaussian blur
// for(int iSample = 0; iSample < MAX_SAMPLES; iSample++)
// {
// vSamplePosition += g_avGlowSampleOffsets[iSample];
// vColor = saturate( glow_color_distort.x * tex2D( g_s0, vSamplePosition ) - glow_color_distort.y );
// //vColor = dot(vColor, glow_color_average);
// vSample += g_avGlowSampleWeights[iSample]*vColor;
// }
// return vSample;
//}
//float4 Glow_White_PS( in float2 vScreenPosition : TEXCOORD0 ) : COLOR
//{
// float4 vSample = 0.0f;
// float4 vColor = 0.0f;
// float2 vSamplePosition = vScreenPosition;
// // Perform a one-directional gaussian blur
// for(int iSample = 0; iSample < MAX_SAMPLES; iSample++)
// {
// vSamplePosition += g_avGlowSampleOffsets[iSample];
// vColor = saturate( glow_color_distort.x * tex2D( g_s0, vSamplePosition ) - glow_color_distort.y );
// vColor = dot(vColor, glow_color_average);
// vSample += g_avGlowSampleWeights[iSample]*vColor;
// }
// return vSample;
//}
//technique GlowScreen_Tech
//{
// pass P0
// {
// VertexShader = NULL;
// PS20_COMPILE_COMMAND Glow_PS();
// }
//}
//technique GlowWhiteScreen_Tech
//{
// pass P0
// {
// VertexShader = NULL;
// PS20_COMPILE_COMMAND Glow_White_PS();
// }
//}
////////////////////////////////////////////////////////////////////////////////////////////////////
/////////
struct VSWATER_INPUT
{
float4 position :POSITION;
float4 color :COLOR0;
// float3 normal :NORMAL;
float2 texCoord0 :TEXCOORD0;
float2 texCoord1 :TEXCOORD1;
};
struct VSWATER_OUTPUT
{
float4 position :POSITION;
float4 color :COLOR0;
float2 texCoord0 :TEXCOORD0;
float2 texCoord1 :TEXCOORD1;
float fog :FOG;
};
VSWATER_OUTPUT WaterSpecular_VS( VSWATER_INPUT In )
{
VSWATER_OUTPUT Out = (VSWATER_OUTPUT)0;
float4 pos = In.position;
float3 normal = { 0.f, 0.f, 1.f };//In.normal;
float4 output_pos, pos_world;
float4 campos = { 0.f, 0.f, 0.f, 0.f };
int b_index = 0;
pos_world = mul( pos, blendMatrices[b_index] );
output_pos = mul( pos_world, view_proj_matrix );
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
float3 light_vec = -Light_direction;//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 light_vector = normalize(-Light_direction);
float3 eye_vector = normalize(campos - pos_world);
float3 halfway = normalize(light_vector + eye_vector);
float4 color = In.color/255;
color.x = In.color.z/255;
color.z = In.color.x/255;
float ddot = saturate(dot(normal, L));
float sdot = saturate(dot(normal, halfway));
if(dot(color, float4(1, 1, 1, 1)) < 4) sdot = 0;
Out.color = ((Light_ambient + Light_diffuse * ddot * Atten) + (Light_specular * pow(sdot, 22)))*color;
Out.color.a = color.a;
Out.position = output_pos;
Out.texCoord0.xy = In.texCoord0.xy + fUVAnimation.xy;
Out.texCoord1.xy = In.texCoord1.xy + fUVAnimation.zw;
return Out;
}
VSWATER_OUTPUT HqWater_VS( VSWATER_INPUT In )
{
VSWATER_OUTPUT Out = ( VSWATER_OUTPUT ) 0;
//float4 out_pos;
Out.position.xyz = In.position.xyz;
Out.position.w = 1.0f;
//out_pos = mul( In.position, view_proj_matrix );
//Out.position = out_pos;
//Out.position = In.position;
Out.color = In.color;
Out.texCoord0 = In.texCoord0;
Out.texCoord1 = In.texCoord1;
//float distfog = saturate((out_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
Out.fog = In.position.w;
//Out.fog = 1 - distfog * distfog;
//Out.fog = 1.0f;
return Out;
}
technique WaterSpecular_Tech
{
pass P0
{
VS11_COMPILE_COMMAND WaterSpecular_VS();
PixelShader = NULL;
}
}
technique HqWater_Tech
{
pass P0
{
VS11_COMPILE_COMMAND HqWater_VS();
PixelShader = NULL;
}
}
//===================================================================================
// FX이펙트용 텍스처 + 컬러 + 알파 쉐이더
//===================================================================================
struct VSALPHATEX_INPUT
{
float4 position :POSITION; // 0 +12
float3 normal :NORMAL; // +12 +12
float4 color0 :COLOR0; // +24 +4
float4 color1 :COLOR1; // +28 +4
float2 texCoord0 :TEXCOORD0; // +32 +8
float2 texCoord1 :TEXCOORD1; // +40 +8
int4 indices :BLENDINDICES; // +48 +4
float3 weights :BLENDWEIGHT; // +52 +12
// blendindices / blendweight / texcoord1은 사용하지 않을 수 있음
};
struct VSALPHATEX_OUTPUT
{
float4 position :POSITION;
float4 color0 :COLOR0;
float4 color1 :COLOR1;
float2 texCoord0 :TEXCOORD0;
float2 texCoord1 :TEXCOORD1;
float2 texCoord2 :TEXCOORD2;
float2 texCoord3 :TEXCOORD3;
float fog :FOG;
};
//--------------------------------
// Vertex shader for Alpha-tex
//--------------------------------
////////////////////////////////////////////////////////////////////////////////////
// color1을 specular로 생각하여 렌더링
////////////////////////////////////////////////////////////////////////////////////
VSALPHATEX_OUTPUT AlphaTex_VS( VSALPHATEX_INPUT In )
{
VSALPHATEX_OUTPUT Out = (VSALPHATEX_OUTPUT) 0;
float4 pos;
float3 normal = In.normal;
float4 output_pos, pos_world;
int b_index = 0;
pos=In.position; // pos=float4(In.position, 1); // for float3
// transform position to screen space before changing it.
pos_world = mul( pos, blendMatrices[b_index] );
float3 N = normalize(mul(normal, (float3x3)blendMatrices[b_index]));
output_pos = mul( pos_world, view_proj_matrix );
Out.position = output_pos;
pos_world = pos_world + LocalCoord_Offset;
// Use light model with specular
float3 light_vec = -Light_direction; //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 light_vector = -Light_direction;
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));
// Base color with specular light
Out.color0 = Light_ambient*In.color0
+ max(Light_diffuse * In.color0 * ddot * Atten
, Light_specular * In.color1 * pow(sdot, 7)); // diffuse + ambient
// Out.color1 = In.color1; // specular color를 일단 copy한다
// Out.color0.a = Out.color0.a*fVisibility;
Out.color0.a = In.color0.a * fVisibility; // light의 alpha값을 무시한다
/*
// Use vertex color only
Out.color0 = In.color0;
Out.color1 = In.color1;
*/
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
// Texture animation
Out.texCoord0 = fUVAnimation.w * In.texCoord0 + fUVAnimation;
return Out;
}
////////////////////////////////////////////////////////////////////////////////////
// Edge부분의 색을 강조. i.e. view normal과 surface normal이 평행하면 색 안 보임
////////////////////////////////////////////////////////////////////////////////////
VSALPHATEX_OUTPUT AlphaTex_EdgeEnhance_VS( VSALPHATEX_INPUT In )
{
VSALPHATEX_OUTPUT Out = (VSALPHATEX_OUTPUT) 0;
// float4 pos;
float4 pos_world;
int b_index = 0;
// pos=In.position; // pos=float4(In.position, 1); // for float3
// transform position to screen space before changing it.
pos_world = mul( In.position, blendMatrices[b_index] );
pos_world = pos_world + LocalCoord_Offset;
Out.position = mul( pos_world, view_proj_matrix );
// face normal과 eye normal의 sin관계에 따라 visibility변화
// float3 vEye = normalize(Camera_position - pos_world);
// float3 normal = normalize(mul(In.normal, blendMatrices[b_index]));
// float sinV = sqrt(1-dot(normal, vEye)); // Use vertex normal
/*
//float3 normal = normalize(mul(In.normal, blendMatrices[b_index]));
//normal = normalize(mul(normal, view_proj_matrix));
//float sinV = sqrt(1 - normal.z * normal.z);
*/
/*
float3 vEye = normalize(Camera_position - pos_world);
float4 tmpn = mul( In.position+In.normal, blendMatrices[b_index] ) - pos_world;
float sinV = sqrt(1-dot(tmpn, vEye)); // Use vertex normal
*/
/*
tmpn = mul(tmpn, view_proj_matrix)-Out.position;
tmpn = normalize(tmpn);
float sinV = sqrt(1 - tmpn.z * tmpn.z);
*/
//sinV = sinV*sinV; // 강조
// transform후에 z좌표를 뒤로 밀어서, 같은 pos위의 다른 오브젝트 뒤에 표시
// pos_world+=float4(vEye, 0) * -2.0; // <- offset값이 현재 constant : 필요하면 나중에 var화 할 것
// Out.position.z += 0.01;
Out.color0 = In.color0;
Out.color1 = In.color1;
Out.color0.a = Out.color0.a * fVisibility;// * sinV;
Out.color1.a = Out.color1.a * fVisibility;// * sinV;
//apply fog
float distfog = saturate((Out.position.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
// Texture animation
Out.texCoord0 = fUVAnimation.w * In.texCoord0 + fUVAnimation;
return Out;
}
////////////////////////////////////////////////////////////////////////////////////
// Edge강조 + vertex blend
////////////////////////////////////////////////////////////////////////////////////
VSALPHATEX_OUTPUT AlphaTex_EdgeEnhance_Blend_VS( VSALPHATEX_INPUT In )
{
VSALPHATEX_OUTPUT Out = (VSALPHATEX_OUTPUT) 0;
float4 pos_world;
pos_world = SkinPoint(In.position, In.indices, In.weights); // pos blended
// float3 N = SkinVector(In.normal , In.indices, In.weights); // normal blended
// float3 vEye = normalize(Camera_position - pos_world);
Out.position = mul( pos_world, view_proj_matrix );
// transform후에 z좌표를 뒤로 밀어서, 같은 pos위의 다른 오브젝트 뒤에 표시
// Out.position.z += 0.01; // <- 뒤로 미는 거리의 적당한(not 적절한) constant
pos_world = pos_world + LocalCoord_Offset;
// face normal과 eye normal의 sin관계에 따라 visibility변화
//float3 normal = normalize(N);
//float sinV = sqrt(1-dot(normal, vEye)); // Use vertex normal
// float sinV = sqrt(1-dot(N, vEye)); // Use vertex normal
//sinV = sinV*sinV; // 강조
Out.color0 = In.color0;
Out.color1 = In.color1;
Out.color0.a = Out.color0.a * fVisibility;// * sinV;
Out.color1.a = Out.color1.a * fVisibility;// * sinV;
//apply fog
float distfog = saturate((Out.position.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
// Texture animation
Out.texCoord0 = fUVAnimation.w * In.texCoord0 + fUVAnimation;
return Out;
}
float4 AlphaTex_PS( VSALPHATEX_OUTPUT In ) : COLOR
{
// color0 : texture modulation color
// color1 : base color
float4 color=saturate(tex2D(DiffTexture, In.texCoord0) * In.color0 + In.color1);
color.a = color.a * fVisibility;
return color;
}
// Light에 관계 없이 color1을 base color로 사용하여 렌더링
technique AlphaTex_Tech
{
pass P0
{
VertexShader = NULL;
PS11_COMPILE_COMMAND AlphaTex_PS();
}
}
// Face의 normal에 따라 color0이 달라짐
technique AlphaTex_EdgeEnhance_Tech
{
pass P0 {
VS11_COMPILE_COMMAND AlphaTex_EdgeEnhance_VS();
PS11_COMPILE_COMMAND AlphaTex_PS();
}
}
// color1을 specular light로 사용하여 렌더링
technique AlphaTex_Lighting_Tech
{
pass P0
{
VS11_COMPILE_COMMAND AlphaTex_VS();
PixelShader = NULL;
}
}
// Face의 normal에 따라 color0이 달라짐 + Bone에 의해 blending
technique AlphaTex_EdgeEnhance_Blend_Tech
{
pass P0 {
VS11_COMPILE_COMMAND AlphaTex_EdgeEnhance_Blend_VS();
PS11_COMPILE_COMMAND AlphaTex_PS();
}
}
///////////////////////////////////////////////////////////////////////
////SelectTargetFx
VSOBJ_OUTPUT SelectTarget_VS( VSOBJ_INPUT In )
{
VSOBJ_OUTPUT Out = (VSOBJ_OUTPUT) 0;
float4 pos = In.position;
float3 normal = In.normal;
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] );
float3 N = normalize(mul(normal, (float3x3)blendMatrices[b_index]));
output_pos = mul( pos_world, view_proj_matrix );
Out.position = output_pos;
pos_world = pos_world + LocalCoord_Offset;
float3 light_vec = -Light_direction;//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 light_vector = -Light_direction;
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));
Out.diffuse = Light_ambient + max(Light_diffuse * ddot * Atten, Light_specular * pow(sdot, 7)); // diffuse + ambient
Out.diffuse.a = fVisibility;
//apply fog
float distfog = saturate((output_pos.z - fFogDistStart)/(fFogDistEnd - fFogDistStart));
float heightfog = saturate((fFogHeightEnd - pos_world.z)/(fFogHeightEnd - fFogHeightStart));
Out.fog = min(1-distfog*distfog, heightfog);
// Out.texCoord0 = mul( In.position, select_target_matrix );
Out.texCoord0 = fUVAnimation.w * In.texCoord0 + fUVAnimation;
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 SelectTargetFx
{
pass P0
{
VS11_COMPILE_COMMAND SelectTarget_VS();
PixelShader = NULL;
}
}
//=============================================================================
// WEATHER FX
VSWEATHER_OUTPUT Weather_VS( VSWEATHER_INPUT In )
{
VSWEATHER_OUTPUT Out = (VSWEATHER_OUTPUT)0;
float3 localPosition, worldPosition;
int blendingIndex = 0; // IN THIS TIME, BLENDING MATIRX AT INDEX 0(WORLD MATRIX) SHOULD BE BILLBOARDING MATRIX
// position
localPosition = mul( (float3)In.local, (float3x3)blendMatrices[ blendingIndex ] ); // billboarding
worldPosition = localPosition;
worldPosition += localPosition.z * WeatherAreaVelocity; // sloping
worldPosition += (float3)In.position; // map to weather area coordinate
worldPosition += WeatherAreaPosition; // map to world coordinate
Out.position = mul( float4( worldPosition, 1 ), view_proj_matrix );
// diffuse
Out.diffuse = In.diffuse;
// texture
Out.texCoord0 = In.texCoord0;
// output
return Out;
}
technique WeatherTech
{
pass P0
{
VS11_COMPILE_COMMAND Weather_VS();
PixelShader = NULL;
}
}
float3 selectColor;
float selectTexInvSize;
float4 OutLine_PS( float2 vTexCoord : TEXCOORD0 ) : COLOR
{
float c = 0.0f;
float4 color = tex2D(g_tones0, vTexCoord);
if (color.r > 0.0f)
{
float l = tex2D(g_tones0, float2(vTexCoord.x-selectTexInvSize, vTexCoord.y)).r;
float r = tex2D(g_tones0, float2(vTexCoord.x+selectTexInvSize, vTexCoord.y)).r;
float t = tex2D(g_tones0, float2(vTexCoord.x, vTexCoord.y-selectTexInvSize)).r;
float b = tex2D(g_tones0, float2(vTexCoord.x, vTexCoord.y+selectTexInvSize)).r;
float lr = abs(l - r);
float tb = abs(t - b);
c = saturate(lr + tb) * color.a;
}
return float4(c*selectColor.x, c*selectColor.y, c*selectColor.z, 1.0f);
}
technique OutLineTech
{
pass P0
{
VertexShader = NULL;
PS20_COMPILE_COMMAND OutLine_PS();
}
}
float4 OutLineBlend_PS(float2 vTexCoord : TEXCOORD0) : COLOR
{
float4 sceneColor = tex2D(g_tones0, vTexCoord);
float4 outlineColor = tex2D(g_tones1, vTexCoord);
sceneColor.xyz += outlineColor.xyz;
return sceneColor;
}
/// 씬과 아웃라인 텍스춰를 블렌딩 해주는 함수
technique OutLineBlendTech
{
pass P0
{
VertexShader = NULL;
PS20_COMPILE_COMMAND OutLineBlend_PS();
}
}
//=============================================================================
//캐릭터
VS_OUTPUT NoTex_VS( VS_INPUT In )
{
VS_OUTPUT Out = (VS_OUTPUT) 0;
float4 output_pos, pos_world;
pos_world = SkinPoint( In.position , In.indices, In.weights);
output_pos = mul( pos_world, view_proj_matrix );
Out.position = output_pos;
Out.diffuse = float4(1, 1, 1, 1);
Out.texCoord0 = In.texCoord0;
return Out;
}
float4 NoTex_PS(float2 texCoord : TEXCOORD0) : COLOR
{
float4 color = tex2D(DiffTexture, texCoord);
return float4(1, 1, 1, color.a);
}
technique NoTexTech
{
pass P0
{
VS20_COMPILE_COMMAND NoTex_VS();
PS11_COMPILE_COMMAND NoTex_PS();
}
}