Advertisement
Guest User

Untitled

a guest
May 13th, 2022
45
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #if OPENGL
  2.     #define VS_SHADERMODEL vs_3_0
  3.     #define PS_SHADERMODEL ps_3_0
  4. #else
  5.     #define VS_SHADERMODEL vs_4_0_level_9_1
  6.     #define PS_SHADERMODEL ps_4_0_level_9_1
  7. #endif
  8.  
  9. float4x4 World;
  10. float4x4 View;
  11. float4x4 Projection;
  12. float4x4 InverseWorldView;
  13. float FarClip;
  14.  
  15. Texture2D DecalTexture;
  16. sampler DecalSampler = sampler_state {
  17.     Texture = (DecalTexture);
  18.     MagFilter = Linear;
  19.     MinFilter = Linear;
  20.     AddressU = Clamp;
  21.     AddressV = Clamp;
  22. };
  23.  
  24. Texture2D Depth;
  25. sampler DepthSampler = sampler_state {
  26.     texture = (Depth);
  27.     magfilter = POINT;
  28.     minfilter = POINT;
  29.     mipfilter = POINT;
  30.     AddressU = Clamp;
  31.     AddressV = Clamp;
  32. };
  33.  
  34. struct VertexShaderInput
  35. {
  36.     float4 Position : SV_POSITION;
  37. };
  38.  
  39. struct VertexShaderOutput
  40. {
  41.     float4 Position : SV_POSITION;
  42.     float4 PositionCS : TEXCOORD0;
  43.     float4 PositionVS : TEXCOORD1;
  44. };
  45.  
  46. VertexShaderOutput MainVS(in VertexShaderInput input)
  47. {
  48.     VertexShaderOutput output = (VertexShaderOutput)0;
  49.     //float4 viewPosition = mul(input.Position, WorldView);
  50.     float4 worldPosition = mul(input.Position, World);
  51.     float4 viewPosition = mul(worldPosition, View);
  52.  
  53.     output.Position = mul(viewPosition, Projection);
  54.     output.PositionCS = output.Position;
  55.     output.PositionVS = viewPosition;
  56.  
  57.     return output;
  58. }
  59.  
  60. float4 MainPS(VertexShaderOutput input) : COLOR
  61. {
  62.     //read depth, use point sample or load
  63.     //float depth = DepthSampler.Load(int3(input.Position.xy, 0)).r;
  64.     float depth = tex2D(DepthSampler, input.Position.xy).r;
  65.  
  66.     //Basically extend the depth of this ray to the end of the far plane, this gives us the position of the sphere only
  67.     float3 cameraDirVS = input.PositionVS.xyz * (FarClip / -input.PositionVS.z);
  68.  
  69.     //compute ViewSpace position
  70.     float3 positionVS = depth * cameraDirVS;
  71.  
  72.     //Transform to box space
  73.     float3 positionOS = mul(float4(positionVS, 1), InverseWorldView).xyz;
  74.  
  75.     clip(1 - abs(positionOS.xyz));
  76.  
  77.     float2 textureCoordinate = (positionOS.xy + 1) / 2;
  78.  
  79.     //return DecalSampler.Sample(DecalSampler, textureCoordinate);
  80.     return float4(1, 0, 0, 1);
  81. }
  82.  
  83. technique BasicColorDrawing
  84. {
  85.     pass P0
  86.     {
  87.         VertexShader = compile VS_SHADERMODEL MainVS();
  88.         PixelShader = compile PS_SHADERMODEL MainPS();
  89.     }
  90. };
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement