#ifndef ts_normal_fn #define ts_normal_fn default_ts_normal #endif #ifndef ambient_light_fn #define ambient_light_fn default_ambient_light #endif #ifndef sample_lights_fn #define sample_lights_fn default_sample_lights #endif #ifndef specular_color_fn #define specular_color_fn default_specular_color #endif #ifndef diffuse_color_fn #define diffuse_color_fn default_diffuse_color #endif #ifndef self_color_fn #define self_color_fn default_self_color #endif #ifndef env_color_fn #define env_color_fn default_env_color #endif sampler2D TexLightBuffer; float4 ScreenSize; float4 CameraPos; float4 ObjectColor; float4 MatColor; float4 MatParams, MatParams2; float4 AlphaTestRef; // x sampler2D TexDiffuse; sampler2D TexNormalHeight; sampler2D TexNormal; sampler2D TexSpecularColor; sampler2D TexSelf; #ifdef _TexEnv_CUBE samplerCUBE TexEnv; #else sampler2D TexEnv; #endif #include "Ambient.fxh" #include "Fog.fxh" #include "FakeBlend.fxh" float GetSelfMultiply() { return MatParams.x; } float GetSpecularLevel() { return MatParams.y; } float GetBumpScale() { return MatParams.z; } float GetGlossiness() { return MatParams.w; } half3 default_ambient_light(VSOutput IN, half2 vScreenPos) { #ifdef _COLOR return get_ambient_light_masked(vScreenPos, IN.vColor.xyz); #else return get_ambient_light(vScreenPos); #endif } void default_sample_lights(VSOutput IN, half2 vScreenPos, out half3 dif, out half3 spc, out half3 amb) { SampleLightDiffuseSpecular(TexLightBuffer, vScreenPos, dif, spc); amb = ambient_light_fn(IN, vScreenPos); #ifndef _USE_LIGHTING // ignoruj swiatlo (na razie, kiedys czesciowa obsluge bedzie) dif = 0; spc = 0; amb = 1; #endif #if defined(_GLOWPASS) || defined(_LIGHTSHAFTSPASS) dif = 0; spc = 0; amb = 0; #endif } half3 default_specular_color(VSOutput IN) { half3 vSpecularColor = GetSpecularLevel(); #ifdef _TexSpecularColor vSpecularColor *= decode_sRGB(tex2D(TexSpecularColor, IN.vTex0.xy)).x; // na razie skala szarosci #endif return vSpecularColor; } half4 default_diffuse_color(VSOutput IN) { #ifdef _TexDiffuse half4 vDiffuseColor = h4tex2D(TexDiffuse, IN.vTex0.xy); #else half4 vDiffuseColor = 1; #endif vDiffuseColor = decode_sRGB(vDiffuseColor); return vDiffuseColor; } half3 default_self_color(VSOutput IN) { half3 vSelfColor = 0; #ifdef _TexSelf vSelfColor = decode_sRGB(tex2D(TexSelf, IN.vTex0.xy)).xyz * GetSelfMultiply(); #endif return vSelfColor; } half3 default_env_color(VSOutput IN, float3 wsNormal) { #ifdef _TexEnv float3 eye_vec = normalize(CameraPos.xyz - IN.vWorldPos); float3 reflect = eye_vec - 2 * dot(eye_vec, wsNormal) * wsNormal; half mask = MatParams2.x; #ifdef _TexSpecularColor mask *= decode_sRGB(tex2D(TexSpecularColor, IN.vTex0.xy)).x; #endif #ifdef _TexEnv_CUBE return decode_sRGB(texCUBE(TexEnv, -reflect)).rgb * mask; #else // world space float3 r3; r3.x = dot(ViewMatrix[0].xyz, reflect); r3.y = dot(ViewMatrix[1].xyz, reflect); r3.z = dot(ViewMatrix[2].xyz, reflect); r3 = normalize(r3) * 0.9; return decode_sRGB(tex2D(TexEnv, r3.xy * .5 + .5)).rgb * mask; #endif #endif return 0; } half3 default_ts_normal(VSOutput IN) { #ifdef _TexNormalHeight float4 bump_sample = tex2D(TexNormalHeight, IN.vTex0.xy); half3 tsNormal = bump_sample.xyz*2 -1; tsNormal.xy *= GetBumpScale(); tsNormal.y *= -1; //tsNormal = normalize(tsNormal); return tsNormal; #else return half3(0,0,1); #endif } half3 compute_ws_normal(VSOutput IN, float vFace) { #ifdef NEEDS_WS_NORMAL #ifdef HAS_TANGENT_SPACE float3x3 worldToTangentSpace = float3x3( (IN.vWorldTangentS), (IN.vWorldTangentT), (IN.vWorldTangentN)); float3 wsNormal = normalize(mul(ts_normal_fn(IN), worldToTangentSpace)); #else float3 wsNormal = normalize(IN.vNormal); #endif wsNormal *= VFACE_SIGN sign(vFace); return wsNormal; #else return 0; #endif } half3 compute_ws_normal(VSOutput IN, float vFace, float2 vScreenPos) { #ifndef NEEDS_WS_NORMAL return 0; #endif #ifdef _DRAW_SOLID half3 normal; SampleNormal(TexNormal, vScreenPos, normal); return normal; #endif return compute_ws_normal(IN, vFace); } half4 compute_output_color(half2 vPos, half vFace, VSOutput IN) { half2 vScreenPos = get_screen_texcoord(vPos, (half4)ScreenSize); half3 wsNormal = compute_ws_normal(IN, vFace, vScreenPos); half3 vDiffuseLight, vSpecularLight, vAmbientLight; sample_lights_fn(IN, vScreenPos, vDiffuseLight, vSpecularLight, vAmbientLight); // specular color half3 vSpecularColor = specular_color_fn(IN); // diffuse color half4 vDiffuseColor = diffuse_color_fn(IN); // alfa-test - obetnij po samej alfie z diffusa #if defined(_DRAW_ALPHATEST) && defined(_PSP2) clip(vDiffuseColor.w - AlphaTestRef.x); #endif // wynik half4 vResult; vResult.xyz = vDiffuseColor.xyz * (vDiffuseLight+vAmbientLight) + vSpecularColor*vSpecularLight; vResult.w = vDiffuseColor.w; #ifdef _DRAW_ALPHATEST vResult.rgb *= (MatColor * ObjectColor).rgb; #else vResult *= MatColor * ObjectColor; #endif // self color / emmisive light half3 vSelfColor = self_color_fn(IN) + env_color_fn(IN, wsNormal) * vResult.w; #if defined(_ALPHABLEND) vResult.rgb *= vResult.w; // premultiplied alpha! (lub additive) #endif vResult.rgb += vSelfColor.rgb; // half fog_density = get_fog_density(vScreenPos.xy, IN.vWorldPos - CameraPos.xyz); vResult = apply_fog(vResult, fog_density); return vResult; }