Files
AIC-Project/Client/Assets/Game/shader/SGame/Base/SGameEnvMapBase.hlsl
T

67 lines
1.9 KiB
HLSL

#ifndef SGAME_ENV_MAP_BASE
#define SGAME_ENV_MAP_BASE
#define SGAME_ENV_MAP_OUTPUT 0.5
#if defined(SGAME_ENV_MAP_GEN)
float4x4 _MWorldToView;
float _FarPlane;
half _SGameEnvMapGenBoost;
#endif
#if defined(SGAME_ENV_MAP_GEN)
inline float4 EnvMap_WorldToClipPos(float4 worldPos)
{
float4 pos = mul(_MWorldToView, worldPos);
float distance = - pos.z;
pos.xyz = normalize(pos.xyz);
pos.xy /= (1 - pos.z);
#if UNITY_UV_STARTS_AT_TOP
pos.y = - pos.y;
#endif
float farPlane = _FarPlane;
pos.z = (distance/farPlane);
#if defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X)
#else
pos.z = pos.z * 2.0 - 1.0;
#endif
#if UNITY_REVERSED_Z
pos.z = 1 - pos.z;
#endif
pos.w = 1.0;
return pos;
}
inline float3 EnvMap_Normal( float3 normal)
{
float dir = _MWorldToView[2][2] * -1;
float3 n = float3(normal.x, normal.y, normal.z * dir);
return n;
}
inline half3 EnvMapGen_Output(half3 col)
{
half3 output = col.rgb * SGAME_ENV_MAP_OUTPUT;
return output;
}
#endif
#if defined(SGAME_ENV_MAP)
TEXTURECUBE(_SGameEnvMap); SAMPLER(sampler_SGameEnvMap);
TEXTURECUBE(_SGameEnvLerpMap); SAMPLER(sampler_SGameEnvLerpMap);
half _SGameEnvLerp; half _SGameEnvMapStrength;
inline half3 SGameEnvMapIBL(half roughness, half3 normal, half3 viewDir, half giIntensity = 1, half smoothness = 1)
{
half3 R = reflect(-viewDir, normal);
// float4 uvs = EnvMap_UVs(R, roughness, smoothness);
half4 srcColor = SAMPLE_TEXTURECUBE_LOD(_SGameEnvMap, sampler_SGameEnvMap, R, saturate(roughness) * 2);
half4 dstColor = SAMPLE_TEXTURECUBE_LOD(_SGameEnvLerpMap, sampler_SGameEnvLerpMap, R, saturate(roughness) * 2);
srcColor = lerp(srcColor, dstColor, clamp(_SGameEnvLerp, 0, 1));
#if defined(SGAME_ENV_MAP_STRENGTH)
half3 specIBL = srcColor.rgb * giIntensity;
specIBL *= _SGameEnvMapStrength;
#else
half3 specIBL = srcColor.rgb;
#endif
return specIBL;
}
#endif
#endif