Ei kuvausta
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.

DepthNormalsOnlyPass.hlsl 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef SG_DEPTH_NORMALS_PASS_INCLUDED
  2. #define SG_DEPTH_NORMALS_PASS_INCLUDED
  3. PackedVaryings vert(Attributes input)
  4. {
  5. Varyings output = (Varyings)0;
  6. output = BuildVaryings(input);
  7. PackedVaryings packedOutput = (PackedVaryings)0;
  8. packedOutput = PackVaryings(output);
  9. return packedOutput;
  10. }
  11. void frag(
  12. PackedVaryings packedInput
  13. , out half4 outNormalWS : SV_Target0
  14. #ifdef _WRITE_RENDERING_LAYERS
  15. , out float4 outRenderingLayers : SV_Target1
  16. #endif
  17. )
  18. {
  19. Varyings unpacked = UnpackVaryings(packedInput);
  20. UNITY_SETUP_INSTANCE_ID(unpacked);
  21. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
  22. SurfaceDescription surfaceDescription = BuildSurfaceDescription(unpacked);
  23. #if defined(_ALPHATEST_ON)
  24. clip(surfaceDescription.Alpha - surfaceDescription.AlphaClipThreshold);
  25. #endif
  26. #if defined(LOD_FADE_CROSSFADE) && USE_UNITY_CROSSFADE
  27. LODFadeCrossFade(unpacked.positionCS);
  28. #endif
  29. #if defined(_GBUFFER_NORMALS_OCT)
  30. float3 normalWS = normalize(unpacked.normalWS);
  31. float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms
  32. float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); // values between [ 0, 1]
  33. half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); // values between [ 0, 1]
  34. outNormalWS = half4(packedNormalWS, 0.0);
  35. #else
  36. // Retrieve the normal from the bump map or mesh normal
  37. #if defined(_NORMALMAP)
  38. #if _NORMAL_DROPOFF_TS
  39. // IMPORTANT! If we ever support Flip on double sided materials ensure bitangent and tangent are NOT flipped.
  40. float crossSign = (unpacked.tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale();
  41. float3 bitangent = crossSign * cross(unpacked.normalWS.xyz, unpacked.tangentWS.xyz);
  42. float3 normalWS = TransformTangentToWorld(surfaceDescription.NormalTS, half3x3(unpacked.tangentWS.xyz, bitangent, unpacked.normalWS.xyz));
  43. #elif _NORMAL_DROPOFF_OS
  44. float3 normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS);
  45. #elif _NORMAL_DROPOFF_WS
  46. float3 normalWS = surfaceDescription.NormalWS;
  47. #endif
  48. #else
  49. float3 normalWS = unpacked.normalWS;
  50. #endif
  51. outNormalWS = half4(NormalizeNormalPerPixel(normalWS), 0.0);
  52. #endif
  53. #ifdef _WRITE_RENDERING_LAYERS
  54. uint renderingLayers = GetMeshRenderingLayer();
  55. outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
  56. #endif
  57. }
  58. #endif