浏览代码

cleanup shader #ifdef code

/main
Paul Melamed 7 年前
当前提交
5265aacd
共有 3 个文件被更改,包括 34 次插入52 次删除
  1. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader
  2. 61
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalData.hlsl
  3. 23
      com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPassDBuffer.hlsl

2
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader


_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map
_MaskMap("MaskMap", 2D) = "white" {}
_DecalBlend("_DecalBlend", Range(0.0, 1.0)) = 0.5
[ToggleUI] _AlbedoMode("_AlbedoMode", Range(0.0, 1.0)) = 0.0
[ToggleUI] _AlbedoMode("_AlbedoMode", Range(0.0, 1.0)) = 1.0
}
HLSLINCLUDE

61
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalData.hlsl


#if (SHADERPASS == SHADERPASS_DBUFFER)
void GetSurfaceData(float2 texCoordDS, float4x4 normalToWorld, out DecalSurfaceData surfaceData)
#elif (SHADERPASS == SHADERPASS_MESHDECALS)
void GetSurfaceData(FragInputs input, out DecalSurfaceData surfaceData)
#endif
#if (SHADERPASS == SHADERPASS_DBUFFER)
texCoordDS = texCoordDS * scale + offset;
float2 texCoords = texCoordDS * scale + offset;
#elif (SHADERPASS == SHADERPASS_MESHDECALS)
float totalBlend = _DecalBlend;
float2 texCoords = input.texCoord0;
#endif
surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, texCoordDS.xy);
surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, texCoords);
surfaceData.baseColor.w *= totalBlend;
totalBlend = surfaceData.baseColor.w; // base alpha affects all other channels;
#if _ALBEDOCONTRIBUTION

#endif
#endif
surfaceData.normalWS.xyz = mul((float3x3)normalToWorld, UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoordDS))) * 0.5f + 0.5f;
float3 normalTS = UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoords));
#if (SHADERPASS == SHADERPASS_DBUFFER)
float3 normalWS = mul((float3x3)normalToWorld, normalTS);
#elif (SHADERPASS == SHADERPASS_MESHDECALS)
float3 normalWS;
GetNormalWS(input, 0, normalTS, normalWS);
#endif
surfaceData.normalWS.xyz = normalWS * 0.5f + 0.5f;
surfaceData.mask = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, texCoordDS.xy);
surfaceData.mask = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, texCoords);
#endif
#if (SHADERPASS == SHADERPASS_MESHDECALS)
void GetSurfaceData(FragInputs input, out DecalSurfaceData surfaceData)
{
surfaceData.baseColor = float4(0, 0, 0, 0);
surfaceData.normalWS = float4(0, 0, 0, 0);
surfaceData.mask = float4(0, 0, 0, 0);
surfaceData.HTileMask = 0;
float totalBlend = _DecalBlend;
#if _COLORMAP
surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, input.texCoord0);
surfaceData.baseColor.w *= totalBlend;
totalBlend = surfaceData.baseColor.w; // base alpha affects all other channels;
#if _ALBEDOCONTRIBUTION
surfaceData.HTileMask |= DBUFFERHTILEBIT_DIFFUSE;
#else
surfaceData.baseColor.w = 0; // dont blend any albedo
#endif
#endif
#if _NORMALMAP
float3 normalTS = UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, input.texCoord0));
float3 normalWS;
GetNormalWS(input, 0, normalTS, normalWS);
surfaceData.normalWS.xyz = normalWS * 0.5f + 0.5f;
surfaceData.normalWS.w = totalBlend;
surfaceData.HTileMask |= DBUFFERHTILEBIT_NORMAL;
#endif
#if _MASKMAP
surfaceData.mask = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, input.texCoord0);
surfaceData.mask.z = surfaceData.mask.w;
surfaceData.mask.w = totalBlend;
surfaceData.HTileMask |= DBUFFERHTILEBIT_MASK;
#endif
}
#endif

23
com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPassDBuffer.hlsl


clip(1.0 - positionDS); // Clip value above one
float4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(matrix, _NormalToWorld);
GetSurfaceData(positionDS.xz, normalToWorld, surfaceData);
GetSurfaceData(positionDS.xz, normalToWorld, surfaceData);\
// have to do explicit test since compiler behavior is not defined for RW resources and discard instructions
if ((all(positionDS.xyz > 0.0f) && all(1.0f - positionDS.xyz > 0.0f)))
{
// have to do explicit test since compiler behavior is not defined for RW resources and discard instructions
if((all(positionDS.xyz > 0.0f) && all(1.0f - positionDS.xyz > 0.0f)))
{
uint oldVal = UnpackByte(_DecalHTile[posInput.positionSS.xy / 8]);
#elif (SHADERPASS == SHADERPASS_MESHDECALS)
GetSurfaceData(input, surfaceData);
#endif
uint oldVal = UnpackByte(_DecalHTile[input.positionSS.xy / 8]);
_DecalHTile[posInput.positionSS.xy / 8] = PackByte(oldVal);
_DecalHTile[input.positionSS.xy / 8] = PackByte(oldVal);
#if (SHADERPASS == SHADERPASS_DBUFFER)
#endif
#if (SHADERPASS == SHADERPASS_MESHDECALS)
GetSurfaceData(input, surfaceData);
uint oldVal = UnpackByte(_DecalHTile[input.positionSS.xy / 8]);
oldVal |= surfaceData.HTileMask;
_DecalHTile[input.positionSS.xy / 8] = PackByte(oldVal);
#endif
ENCODE_INTO_DBUFFER(surfaceData, outDBuffer);
}
正在加载...
取消
保存