暫無描述
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.

FrameBufferFetch.shader 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. Shader "FrameBufferFetch"
  2. {
  3. SubShader
  4. {
  5. Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline"}
  6. ZWrite Off Cull Off
  7. Pass
  8. {
  9. Name "InitialBlit"
  10. HLSLPROGRAM
  11. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  12. #include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
  13. #pragma vertex Vert
  14. #pragma fragment Frag
  15. // Out frag function takes as input a struct that contains the screen space coordinate we are going to use to sample our texture. It also writes to SV_Target0, this has to match the index set in the UseTextureFragment(sourceTexture, 0, …) we defined in our render pass script.
  16. float4 Frag(Varyings input) : SV_Target0
  17. {
  18. // this is needed so we account XR platform differences in how they handle texture arrays
  19. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  20. // sample the texture using the SAMPLE_TEXTURE2D_X_LOD
  21. float2 uv = input.texcoord.xy;
  22. half4 color = SAMPLE_TEXTURE2D_X_LOD(_BlitTexture, sampler_LinearRepeat, uv, _BlitMipLevel);
  23. // Modify the sampled color
  24. return color;
  25. }
  26. ENDHLSL
  27. }
  28. Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline"}
  29. ZWrite Off Cull Off
  30. Pass
  31. {
  32. Name "FrameBufferFetch"
  33. HLSLPROGRAM
  34. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  35. #include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
  36. #pragma vertex Vert
  37. #pragma fragment Frag
  38. // Declares the framebuffer input as a texture 2d containing half.
  39. FRAMEBUFFER_INPUT_X_HALF(0);
  40. // Out frag function takes as input a struct that contains the screen space coordinate we are going to use to sample our texture. It also writes to SV_Target0, this has to match the index set in the UseTextureFragment(sourceTexture, 0, …) we defined in our render pass script.
  41. float4 Frag(Varyings input) : SV_Target0
  42. {
  43. // this is needed so we account XR platform differences in how they handle texture arrays
  44. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  45. // read the current pixel from the framebuffer
  46. float2 uv = input.texcoord.xy;
  47. // read previous subpasses directly from the framebuffer.
  48. half4 color = LOAD_FRAMEBUFFER_X_INPUT(0, input.positionCS.xy);
  49. // Modify the sampled color
  50. return half4(0,0,1,1) * color;
  51. }
  52. ENDHLSL
  53. }
  54. }
  55. }