|
|
@@ -1,285 +0,0 @@
|
|
|
-#include "Uniforms.hlsl"
|
|
|
-#include "Samplers.hlsl"
|
|
|
-#include "Transform.hlsl"
|
|
|
-#include "ScreenPos.hlsl"
|
|
|
-#include "Lighting.hlsl"
|
|
|
-#include "Fog.hlsl"
|
|
|
-
|
|
|
-void VS(float4 iPos : POSITION,
|
|
|
- #ifndef BILLBOARD
|
|
|
- float3 iNormal : NORMAL,
|
|
|
- #endif
|
|
|
- float2 iTexCoord : TEXCOORD0,
|
|
|
- #if defined(LIGHTMAP) || defined(AO)
|
|
|
- float2 iTexCoord2 : TEXCOORD1,
|
|
|
- #endif
|
|
|
- #ifdef NORMALMAP
|
|
|
- float4 iTangent : TANGENT,
|
|
|
- #endif
|
|
|
- #ifdef SKINNED
|
|
|
- float4 iBlendWeights : BLENDWEIGHT,
|
|
|
- int4 iBlendIndices : BLENDINDICES,
|
|
|
- #endif
|
|
|
- #ifdef INSTANCED
|
|
|
- float4x3 iModelInstance : TEXCOORD2,
|
|
|
- #endif
|
|
|
- #ifdef BILLBOARD
|
|
|
- float2 iSize : TEXCOORD1,
|
|
|
- #endif
|
|
|
- #ifndef NORMALMAP
|
|
|
- out float2 oTexCoord : TEXCOORD0,
|
|
|
- #else
|
|
|
- out float4 oTexCoord : TEXCOORD0,
|
|
|
- out float4 oTangent : TEXCOORD3,
|
|
|
- #endif
|
|
|
- out float3 oNormal : TEXCOORD1,
|
|
|
- out float4 oWorldPos : TEXCOORD2,
|
|
|
- #ifdef PERPIXEL
|
|
|
- #ifdef SHADOW
|
|
|
- out float4 oShadowPos[NUMCASCADES] : TEXCOORD4,
|
|
|
- #endif
|
|
|
- #ifdef SPOTLIGHT
|
|
|
- out float4 oSpotPos : TEXCOORD5,
|
|
|
- #endif
|
|
|
- #ifdef POINTLIGHT
|
|
|
- out float3 oCubeMaskVec : TEXCOORD5,
|
|
|
- #endif
|
|
|
- #else
|
|
|
- out float3 oVertexLight : TEXCOORD4,
|
|
|
- out float4 oScreenPos : TEXCOORD5,
|
|
|
- #ifdef ENVCUBEMAP
|
|
|
- out float3 oReflectionVec : TEXCOORD6,
|
|
|
- #endif
|
|
|
- #if defined(LIGHTMAP) || defined(AO)
|
|
|
- out float2 oTexCoord2 : TEXCOORD7,
|
|
|
- #endif
|
|
|
- #endif
|
|
|
- out float4 oPos : SV_POSITION)
|
|
|
-{
|
|
|
- float4x3 modelMatrix = iModelMatrix;
|
|
|
- float3 worldPos = GetWorldPos(modelMatrix);
|
|
|
- oPos = GetClipPos(worldPos);
|
|
|
- oNormal = GetWorldNormal(modelMatrix);
|
|
|
- oWorldPos = float4(worldPos, GetDepth(oPos));
|
|
|
-
|
|
|
- #ifdef NORMALMAP
|
|
|
- float3 tangent = GetWorldTangent(modelMatrix);
|
|
|
- float3 bitangent = cross(tangent, oNormal) * iTangent.w;
|
|
|
- oTexCoord = float4(GetTexCoord(iTexCoord), bitangent.xy);
|
|
|
- oTangent = float4(tangent, bitangent.z);
|
|
|
- #else
|
|
|
- oTexCoord = GetTexCoord(iTexCoord);
|
|
|
- #endif
|
|
|
-
|
|
|
- #ifdef PERPIXEL
|
|
|
- // Per-pixel forward lighting
|
|
|
- float4 projWorldPos = float4(worldPos.xyz, 1.0);
|
|
|
-
|
|
|
- #ifdef SHADOW
|
|
|
- // Shadow projection: transform from world space to shadow space
|
|
|
- GetShadowPos(projWorldPos, oShadowPos);
|
|
|
- #endif
|
|
|
-
|
|
|
- #ifdef SPOTLIGHT
|
|
|
- // Spotlight projection: transform from world space to projector texture coordinates
|
|
|
- oSpotPos = mul(projWorldPos, cLightMatrices[0]);
|
|
|
- #endif
|
|
|
-
|
|
|
- #ifdef POINTLIGHT
|
|
|
- oCubeMaskVec = mul(worldPos - cLightPos.xyz, (float3x3)cLightMatrices[0]);
|
|
|
- #endif
|
|
|
- #else
|
|
|
- // Ambient & per-vertex lighting
|
|
|
- #if defined(LIGHTMAP) || defined(AO)
|
|
|
- // If using lightmap, disregard zone ambient light
|
|
|
- // If using AO, calculate ambient in the PS
|
|
|
- oVertexLight = float3(0.0, 0.0, 0.0);
|
|
|
- oTexCoord2 = iTexCoord2;
|
|
|
- #else
|
|
|
- oVertexLight = GetAmbient(GetZonePos(worldPos));
|
|
|
- #endif
|
|
|
-
|
|
|
- #ifdef NUMVERTEXLIGHTS
|
|
|
- for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
|
|
|
- oVertexLight += GetVertexLight(i, worldPos, oNormal) * cVertexLights[i * 3].rgb;
|
|
|
- #endif
|
|
|
-
|
|
|
- oScreenPos = GetScreenPos(oPos);
|
|
|
-
|
|
|
- #ifdef ENVCUBEMAP
|
|
|
- oReflectionVec = worldPos - cCameraPos;
|
|
|
- #endif
|
|
|
- #endif
|
|
|
-}
|
|
|
-
|
|
|
-void PS(
|
|
|
- #ifndef NORMALMAP
|
|
|
- float2 iTexCoord : TEXCOORD0,
|
|
|
- #else
|
|
|
- float4 iTexCoord : TEXCOORD0,
|
|
|
- float4 iTangent : TEXCOORD3,
|
|
|
- #endif
|
|
|
- float3 iNormal : TEXCOORD1,
|
|
|
- float4 iWorldPos : TEXCOORD2,
|
|
|
- #ifdef PERPIXEL
|
|
|
- #ifdef SHADOW
|
|
|
- float4 iShadowPos[NUMCASCADES] : TEXCOORD4,
|
|
|
- #endif
|
|
|
- #ifdef SPOTLIGHT
|
|
|
- float4 iSpotPos : TEXCOORD5,
|
|
|
- #endif
|
|
|
- #ifdef CUBEMASK
|
|
|
- float3 iCubeMaskVec : TEXCOORD5,
|
|
|
- #endif
|
|
|
- #else
|
|
|
- float3 iVertexLight : TEXCOORD4,
|
|
|
- float4 iScreenPos : TEXCOORD5,
|
|
|
- #ifdef ENVCUBEMAP
|
|
|
- float3 iReflectionVec : TEXCOORD6,
|
|
|
- #endif
|
|
|
- #if defined(LIGHTMAP) || defined(AO)
|
|
|
- float2 iTexCoord2 : TEXCOORD7,
|
|
|
- #endif
|
|
|
- #endif
|
|
|
- #ifdef PREPASS
|
|
|
- out float4 oDepth : SV_TARGET1,
|
|
|
- #endif
|
|
|
- #ifdef DEFERRED
|
|
|
- out float4 oAlbedo : SV_TARGET1,
|
|
|
- out float4 oNormal : SV_TARGET2,
|
|
|
- out float4 oDepth : SV_TARGET3,
|
|
|
- #endif
|
|
|
- out float4 oColor : SV_TARGET)
|
|
|
-{
|
|
|
- // Get material diffuse albedo
|
|
|
- #ifdef DIFFMAP
|
|
|
- float4 diffInput = tDiffMap.Sample(sDiffMap, iTexCoord.xy);
|
|
|
- #ifdef ALPHAMASK
|
|
|
- if (diffInput.a < 0.5)
|
|
|
- discard;
|
|
|
- #endif
|
|
|
- float4 diffColor = cMatDiffColor * diffInput;
|
|
|
- #else
|
|
|
- float4 diffColor = cMatDiffColor;
|
|
|
- #endif
|
|
|
-
|
|
|
- // Get material specular albedo
|
|
|
- #ifdef SPECMAP
|
|
|
- float3 specColor = cMatSpecColor.rgb * tSpecMap.Sample(sSpecMap, iTexCoord.xy).rgb;
|
|
|
- #else
|
|
|
- float3 specColor = cMatSpecColor.rgb;
|
|
|
- #endif
|
|
|
-
|
|
|
- // Get normal
|
|
|
- #ifdef NORMALMAP
|
|
|
- float3x3 tbn = float3x3(iTangent.xyz, float3(iTexCoord.zw, iTangent.w), iNormal);
|
|
|
- float3 normal = normalize(mul(DecodeNormal(tNormalMap.Sample(sNormalMap, iTexCoord.xy)), tbn));
|
|
|
- #else
|
|
|
- float3 normal = normalize(iNormal);
|
|
|
- #endif
|
|
|
-
|
|
|
- // Get fog factor
|
|
|
- #ifdef HEIGHTFOG
|
|
|
- float fogFactor = GetHeightFogFactor(iWorldPos.w, iWorldPos.y);
|
|
|
- #else
|
|
|
- float fogFactor = GetFogFactor(iWorldPos.w);
|
|
|
- #endif
|
|
|
-
|
|
|
- #if defined(PERPIXEL)
|
|
|
- // Per-pixel forward lighting
|
|
|
- float3 lightDir;
|
|
|
- float3 lightColor;
|
|
|
- float3 finalColor;
|
|
|
-
|
|
|
- float diff = GetDiffuse(normal, iWorldPos.xyz, lightDir);
|
|
|
-
|
|
|
- #ifdef SHADOW
|
|
|
- diff *= GetShadow(iShadowPos, iWorldPos.w);
|
|
|
- #endif
|
|
|
-
|
|
|
- #if defined(SPOTLIGHT)
|
|
|
- lightColor = iSpotPos.w > 0.0 ? tLightSpotMap.Sample(sLightSpotMap, iSpotPos.xy / iSpotPos.w).rrr * cLightColor.rgb : 0.0;
|
|
|
- #elif defined(CUBEMASK)
|
|
|
- lightColor = tLightCubeMap.Sample(sLightCubeMap, iCubeMaskVec).rgb * cLightColor.rgb;
|
|
|
- #else
|
|
|
- lightColor = cLightColor.rgb;
|
|
|
- #endif
|
|
|
-
|
|
|
- #ifdef SPECULAR
|
|
|
- float spec = GetSpecular(normal, cCameraPosPS - iWorldPos.xyz, lightDir, cMatSpecColor.a);
|
|
|
- finalColor = diff * lightColor * (diffColor.rgb + spec * specColor * cLightColor.a);
|
|
|
- #else
|
|
|
- finalColor = diff * lightColor * diffColor.rgb;
|
|
|
- #endif
|
|
|
-
|
|
|
- #ifdef AMBIENT
|
|
|
- finalColor += cAmbientColor * diffColor.rgb;
|
|
|
- finalColor += cMatEmissiveColor;
|
|
|
- oColor = float4(GetFog(finalColor, fogFactor), diffColor.a);
|
|
|
- #else
|
|
|
- oColor = float4(GetLitFog(finalColor, fogFactor), diffColor.a);
|
|
|
- #endif
|
|
|
- #elif defined(PREPASS)
|
|
|
- // Fill light pre-pass G-Buffer
|
|
|
- float specPower = cMatSpecColor.a / 255.0;
|
|
|
-
|
|
|
- oColor = float4(normal * 0.5 + 0.5, specPower);
|
|
|
- oDepth = iWorldPos.w;
|
|
|
- #elif defined(DEFERRED)
|
|
|
- // Fill deferred G-buffer
|
|
|
- float specIntensity = specColor.g;
|
|
|
- float specPower = cMatSpecColor.a / 255.0;
|
|
|
-
|
|
|
- float3 finalColor = iVertexLight * diffColor.rgb;
|
|
|
- #ifdef AO
|
|
|
- // If using AO, the vertex light ambient is black, calculate occluded ambient here
|
|
|
- finalColor += tEmissiveMap.Sample(sEmissiveMap, iTexCoord2).rgb * cAmbientColor * diffColor.rgb;
|
|
|
- #endif
|
|
|
- #ifdef ENVCUBEMAP
|
|
|
- finalColor += cMatEnvMapColor * tEnvCubeMap.Sample(sEnvCubeMap, reflect(iReflectionVec, normal)).rgb;
|
|
|
- #endif
|
|
|
- #ifdef LIGHTMAP
|
|
|
- finalColor += tEmissiveMap.Sample(sEmissiveMap, iTexCoord2).rgb * diffColor.rgb;
|
|
|
- #endif
|
|
|
- #ifdef EMISSIVEMAP
|
|
|
- finalColor += cMatEmissiveColor * tEmissiveMap.Sample(sEmissiveMap, iTexCoord.xy).rgb;
|
|
|
- #else
|
|
|
- finalColor += cMatEmissiveColor;
|
|
|
- #endif
|
|
|
-
|
|
|
- oColor = float4(GetFog(finalColor, fogFactor), 1.0);
|
|
|
- oAlbedo = fogFactor * float4(diffColor.rgb, specIntensity);
|
|
|
- oNormal = float4(normal * 0.5 + 0.5, specPower);
|
|
|
- oDepth = iWorldPos.w;
|
|
|
- #else
|
|
|
- // Ambient & per-vertex lighting
|
|
|
- float3 finalColor = iVertexLight * diffColor.rgb;
|
|
|
- #ifdef AO
|
|
|
- // If using AO, the vertex light ambient is black, calculate occluded ambient here
|
|
|
- finalColor += tEmissiveMap.Sample(sEmissiveMap, iTexCoord2).rgb * cAmbientColor * diffColor.rgb;
|
|
|
- #endif
|
|
|
-
|
|
|
- #ifdef MATERIAL
|
|
|
- // Add light pre-pass accumulation result
|
|
|
- // Lights are accumulated at half intensity. Bring back to full intensity now
|
|
|
- float4 lightInput = 2.0 * tLightBuffer.Sample(sLightBuffer, iScreenPos.xy / iScreenPos.w);
|
|
|
- float3 lightSpecColor = lightInput.a * (lightInput.rgb / GetIntensity(lightInput.rgb));
|
|
|
-
|
|
|
- finalColor += lightInput.rgb * diffColor.rgb + lightSpecColor * specColor;
|
|
|
- #endif
|
|
|
-
|
|
|
- #ifdef ENVCUBEMAP
|
|
|
- finalColor += cMatEnvMapColor * tEnvCubeMap.Sample(sEnvCubeMap, reflect(iReflectionVec, normal)).rgb;
|
|
|
- #endif
|
|
|
- #ifdef LIGHTMAP
|
|
|
- finalColor += tEmissiveMap.Sample(sEmissiveMap, iTexCoord2).rgb * diffColor.rgb;
|
|
|
- #endif
|
|
|
- #ifdef EMISSIVEMAP
|
|
|
- finalColor += cMatEmissiveColor * tEmissiveMap.Sample(sEmissiveMap, iTexCoord.xy).rgb;
|
|
|
- #else
|
|
|
- finalColor += cMatEmissiveColor;
|
|
|
- #endif
|
|
|
-
|
|
|
- oColor = float4(GetFog(finalColor, fogFactor), diffColor.a);
|
|
|
- #endif
|
|
|
-}
|