/*#define BASEUV 1 #define DIFFUSE 1 #define DiffuseTex Tex0 #define DiffuseUV Input.Data.Tex #define SPECULAR 1 #define SpecularTex Tex1 #define SpecularUV Input.Data.Tex #define FACENORMAL 1 #define REFLECTIVE 1 #define ReflectiveTex RealtimeReflectionTex #define ReflectionPower CarReflectionPower #define ReflectionMult CarReflectionMult*/ sampler2D Tex0; sampler2D Tex1; sampler2D Tex2; sampler2D Tex7; sampler2D Tex8; sampler2D Tex10; samplerCUBE ReflectionTex; samplerCUBE RealtimeReflectionTex; float4 Ambient; float Timer; float3 WorldReflectionMult; float WorldReflectionPower; float3 CarReflectionMult; float CarReflectionPower; #include "dcSuperShader_Data.HLSL" #ifndef DiffuseComponent #define DiffuseComponent rgba #endif #ifndef SpecularComponent #define SpecularComponent rgba #endif #ifndef ReflectionPower #define ReflectionPower 1 #endif #ifndef ReflectionMult #define ReflectionMult 1 #endif #ifndef SPECULARPOWER #define SPECULARPOWER 4.0f / 255.0f #endif #ifndef SPECULARINTENSITY #define SPECULARINTENSITY 1 #endif #define COMPRESSEDNORMAL struct PS_INPUT{ float2 Pos : VPOS; float Face : VFACE; dcShaderData Data : TEXCOORD0; }; #define Output0(x) Out.RT0 = x #define Output1(x) Out.RT1 = x #define Output2(x) Out.RT2 = x #define Output3(x) Out.RT3 = x struct PS_OUTPUT{ float4 RT0 : COLOR0; #ifndef FORWARD float4 RT1 : COLOR1; float4 RT2 : COLOR2; #if !defined(NOMOTION) float4 RT3 : COLOR3; #endif #endif }; float4 ComputeDiffuse(const PS_INPUT Input){ #ifdef DIFFUSE float4 Diffuse = tex2D(DiffuseTex, DiffuseUV).DiffuseComponent; #else float4 Diffuse = 0; #endif #ifdef DIFFUSE_DETAILTEX0 float3 DirtTexColor0 = tex2D(DiffuseDetailTex0, Detail0UV).rgb; Diffuse.rgb = (Diffuse.rgb + DirtTexColor0) - 0.5f; #endif #ifdef DIFFUSE_DETAILTEX1 float3 DirtTexColor1 = tex2D(DiffuseDetailTex1, Detail1UV).rgb; Diffuse.rgb = (Diffuse.rgb + DirtTexColor1) - 0.5f; #endif return Diffuse; } float4 ComputeSpecular(const PS_INPUT Input){ #ifdef SPECULAR float4 Specular = tex2D(SpecularTex, SpecularUV).SpecularComponent; #else float4 Specular = 0; #endif #ifdef SPECULAR_DETAILTEX0 float3 DirtTexColor0 = tex2D(SpecularDetailTex0, Detail0UV).rgb; Specular.rgb *= DirtTexColor0; #endif #ifdef SPECULAR_DETAILTEX1 float3 DirtTexColor1 = tex2D(SpecularDetailTex1, Detail1UV).rgb; Specular.rgb *= DirtTexColor1; #endif return Specular / 2; } float3 ComputeNormal(const PS_INPUT Input){ #if defined(FACENORMAL) float3 Normal = Input.Data.Normal; #elif defined(NORMALMAP) #ifndef COMPRESSEDNORMAL float3 Normal = (tex2D(NormalTex, NormalUV).xyz - 0.5f) * 2; #else float3 Normal; Normal.xy = (tex2D(NormalTex, NormalUV).xy - 0.5f) * 2.0f; Normal.z = sqrt(1.0f - dot(Normal.xy, Normal.xy)); #endif #ifdef WATERSHADER float2 BumpTex0 = NormalUV + float2(Timer / 15.1f, 0); float2 BumpTex1 = NormalUV + float2(0, Timer / 17.4f); float3 N0 = (tex2D(NormalTex, BumpTex0) - 0.5f); float3 N1 = (tex2D(NormalTex, BumpTex1) - 0.5f); Normal = normalize(N0 + N1); #endif Normal = mul(Normal, Input.Data.NormalMatrix); #else float3 Normal = 0; #endif #ifdef DOUBLESIDED if (Input.Face < 0){ Normal *= -1; } #endif return Normal; } float3 ComputeReflectionNormal(const PS_INPUT Input){ #if defined(FACENORMAL) float3 Normal = Input.Data.Normal; #elif defined(NORMALMAP) #ifndef COMPRESSEDNORMAL float3 Normal = (tex2D(ReflectionNormalTex, ReflectionNormalUV).xyz - 0.5f) * 2; #else float3 Normal; Normal.xy = (tex2D(ReflectionNormalTex, ReflectionNormalUV).xy - 0.5f) * 2.0f; Normal.z = sqrt(1.0f - dot(Normal.xy, Normal.xy)); #endif #ifdef WATERSHADER float2 BumpTex0 = ReflectionNormalUV + float2(Timer / 15.1f, 0); float2 BumpTex1 = ReflectionNormalUV + float2(0, Timer / 17.4f); float3 N0 = (tex2D(ReflectionNormalTex, BumpTex0) - 0.5f); float3 N1 = (tex2D(ReflectionNormalTex, BumpTex1) - 0.5f); Normal = normalize(N0 + N1); #endif Normal = mul(Normal, Input.Data.NormalMatrix); #else float3 Normal = 0; #endif #ifdef DOUBLESIDED if (Input.Face < 0){ Normal *= -1; } #endif return Normal; } float3 ComputeReflectionVector(const PS_INPUT Input){ #ifdef REFLECTIVE #if defined(FACENORMAL) float3 R = Input.Data.R; #elif defined(NORMALMAP) float3 N = ComputeReflectionNormal(Input); float3 V = Input.Data.V; float3 R = 2 * dot(N, V) * N - V; #endif return R; #else return 0; #endif } float3 ComputeReflection(const PS_INPUT Input){ #ifdef REFLECTIVE #ifdef SPECULAR float4 Specular = ComputeSpecular(Input); #else float4 Specular = 1; #endif float3 R = ComputeReflectionVector(Input); float3 Reflection = texCUBE(ReflectiveTex, R).rgb; Reflection = pow(Reflection, ReflectionPower) * Specular.rgb; Reflection *= ReflectionMult; return Reflection; #else return 0; #endif } float2 ComputeMotion(const PS_INPUT Input){ #ifndef NOMOTION // Motion float2 CurPos = Input.Data.CurPos.xy / Input.Data.CurPos.w; float2 PrevPos = Input.Data.PrevPos.xy / Input.Data.PrevPos.w; float2 Motion = (PrevPos - CurPos); #else float2 Motion = 0; #endif return Motion; } float FogNear, InvFogRange; float4 LerpFogColor; PS_OUTPUT main(const PS_INPUT Input){ float4 Diffuse = ComputeDiffuse(Input); float4 Specular = ComputeSpecular(Input); float3 Normal = ComputeNormal(Input); float3 Reflection = ComputeReflection(Input); float2 Motion = ComputeMotion(Input); float Fog = clamp((length(Input.Data.V) - FogNear) * InvFogRange, 0, 1); Fog *= LerpFogColor.a; //Diffuse = 1; //Specular = 1; //Reflection = 0; //Fog = 0; PS_OUTPUT Out = (PS_OUTPUT)0; Out.RT0 = Diffuse * Ambient + float4(Reflection, 0); Out.RT0.rgb = lerp(Out.RT0.rgb, LerpFogColor.rgb, Fog); #ifndef FORWARD float4 Data1; Data1.xyz = (Normal.xyz / 2.0f) + 0.5f; Data1.w = SPECULARPOWER; Output1(Data1); float Shininess; #if defined(REFLECTIVE) || defined(REALSPECULAR) Shininess = dot(Specular, float3(0.333, 0.333, 0.333)); Shininess *= SPECULARINTENSITY; #else Shininess = 0; #endif Output2(lerp(float4(Diffuse.rgb, Shininess), 0, Fog); #ifndef NOMOTION Output3(Motion.xyxy + 0.49803921568627450980392156862745f); #endif #endif return Out; }