暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SixWayForwardPass.hlsl 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. void InitializeInputData(Varyings input, bool frontFace, out InputData inputData)
  2. {
  3. inputData = (InputData)0;
  4. inputData.positionWS = input.positionWS;
  5. float signNormal = frontFace ? 1.0f : -1.0f;
  6. inputData.normalWS = signNormal * input.normalWS;
  7. inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
  8. float crossSign = (input.tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale();
  9. float3 bitangent = crossSign * cross(input.normalWS.xyz, input.tangentWS.xyz);
  10. inputData.tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, signNormal * input.normalWS);
  11. inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
  12. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  13. inputData.shadowCoord = input.shadowCoord;
  14. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  15. inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
  16. #else
  17. inputData.shadowCoord = float4(0, 0, 0, 0);
  18. #endif
  19. inputData.fogCoord = InitializeInputDataFog(float4(input.positionWS, 1.0), input.fogFactorAndVertexLight.x);
  20. inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
  21. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
  22. inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
  23. #if defined(DEBUG_DISPLAY)
  24. #if defined(DYNAMICLIGHTMAP_ON)
  25. inputData.dynamicLightmapUV = input.dynamicLightmapUV.xy;
  26. #endif
  27. #if defined(LIGHTMAP_ON)
  28. inputData.staticLightmapUV = input.staticLightmapUV;
  29. #else
  30. inputData.vertexSH = input.sh;
  31. #endif
  32. inputData.positionCS = input.positionCS;
  33. #endif
  34. }
  35. PackedVaryings vert(Attributes input)
  36. {
  37. Varyings output = (Varyings)0;
  38. output = BuildVaryings(input);
  39. PackedVaryings packedOutput = (PackedVaryings)0;
  40. packedOutput = PackVaryings(output);
  41. return packedOutput;
  42. }
  43. void frag(
  44. PackedVaryings packedInput
  45. , out half4 outColor : SV_Target0
  46. , bool frontFace : FRONT_FACE_SEMANTIC
  47. #ifdef _WRITE_RENDERING_LAYERS
  48. , out float4 outRenderingLayers : SV_Target1
  49. #endif
  50. )
  51. {
  52. Varyings unpacked = UnpackVaryings(packedInput);
  53. UNITY_SETUP_INSTANCE_ID(unpacked);
  54. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
  55. SurfaceDescription surfaceDescription = BuildSurfaceDescription(unpacked);
  56. #if defined(_SURFACE_TYPE_TRANSPARENT)
  57. bool isTransparent = true;
  58. #else
  59. bool isTransparent = false;
  60. #endif
  61. #if defined(_ALPHATEST_ON)
  62. half alpha = AlphaDiscard(surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold);
  63. #elif defined(_SURFACE_TYPE_TRANSPARENT)
  64. half alpha = surfaceDescription.Alpha;
  65. #else
  66. half alpha = half(1.0);
  67. #endif
  68. #if defined(LOD_FADE_CROSSFADE) && USE_UNITY_CROSSFADE
  69. LODFadeCrossFade(unpacked.positionCS);
  70. #endif
  71. InputData inputData;
  72. InitializeInputData(unpacked, frontFace, inputData);
  73. #ifdef VARYINGS_NEED_TEXCOORD0
  74. SETUP_DEBUG_TEXTURE_DATA(inputData, unpacked.texCoord0);
  75. #else
  76. SETUP_DEBUG_TEXTURE_DATA_NO_UV(inputData);
  77. #endif
  78. SixWaySurfaceData surfaceData;
  79. surfaceData.rightTopBack = surfaceDescription.RightTopBack * INV_PI;
  80. surfaceData.leftBottomFront = surfaceDescription.LeftBottomFront * INV_PI;
  81. surfaceData.emission = surfaceDescription.Emission;
  82. surfaceData.baseColor = surfaceDescription.BaseColor;
  83. surfaceData.occlusion = surfaceDescription.Occlusion;
  84. surfaceData.alpha = saturate(alpha);
  85. surfaceData.diffuseGIData0 = unpacked.diffuseGIData0;
  86. surfaceData.diffuseGIData1 = unpacked.diffuseGIData1;
  87. surfaceData.diffuseGIData2 = unpacked.diffuseGIData2;
  88. #if defined(_SIX_WAY_COLOR_ABSORPTION)
  89. surfaceData.absorptionRange = INV_PI + saturate(surfaceDescription.AbsorptionStrength) * (1 - INV_PI);
  90. #endif
  91. half4 color = UniversalFragmentSixWay(inputData, surfaceData);
  92. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  93. color.a = OutputAlpha(color.a, isTransparent);
  94. outColor = color;
  95. #ifdef _WRITE_RENDERING_LAYERS
  96. uint renderingLayers = GetMeshRenderingLayer();
  97. outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
  98. #endif
  99. }