Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if OPENGL
- #define VS_SHADERMODEL vs_3_0
- #define PS_SHADERMODEL ps_3_0
- #else
- #define VS_SHADERMODEL vs_4_0_level_9_1
- #define PS_SHADERMODEL ps_4_0_level_9_1
- #endif
- float4x4 World;
- float4x4 View;
- float4x4 Projection;
- float4x4 InverseWorldView;
- float FarClip;
- Texture2D DecalTexture;
- sampler DecalSampler = sampler_state {
- Texture = (DecalTexture);
- MagFilter = Linear;
- MinFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- };
- Texture2D Depth;
- sampler DepthSampler = sampler_state {
- texture = (Depth);
- magfilter = POINT;
- minfilter = POINT;
- mipfilter = POINT;
- AddressU = Clamp;
- AddressV = Clamp;
- };
- struct VertexShaderInput
- {
- float4 Position : SV_POSITION;
- };
- struct VertexShaderOutput
- {
- float4 Position : SV_POSITION;
- float4 PositionCS : TEXCOORD0;
- float4 PositionVS : TEXCOORD1;
- };
- VertexShaderOutput MainVS(in VertexShaderInput input)
- {
- VertexShaderOutput output = (VertexShaderOutput)0;
- //float4 viewPosition = mul(input.Position, WorldView);
- float4 worldPosition = mul(input.Position, World);
- float4 viewPosition = mul(worldPosition, View);
- output.Position = mul(viewPosition, Projection);
- output.PositionCS = output.Position;
- output.PositionVS = viewPosition;
- return output;
- }
- float4 MainPS(VertexShaderOutput input) : COLOR
- {
- //read depth, use point sample or load
- //float depth = DepthSampler.Load(int3(input.Position.xy, 0)).r;
- float depth = tex2D(DepthSampler, input.Position.xy).r;
- //Basically extend the depth of this ray to the end of the far plane, this gives us the position of the sphere only
- float3 cameraDirVS = input.PositionVS.xyz * (FarClip / -input.PositionVS.z);
- //compute ViewSpace position
- float3 positionVS = depth * cameraDirVS;
- //Transform to box space
- float3 positionOS = mul(float4(positionVS, 1), InverseWorldView).xyz;
- clip(1 - abs(positionOS.xyz));
- float2 textureCoordinate = (positionOS.xy + 1) / 2;
- //return DecalSampler.Sample(DecalSampler, textureCoordinate);
- return float4(1, 0, 0, 1);
- }
- technique BasicColorDrawing
- {
- pass P0
- {
- VertexShader = compile VS_SHADERMODEL MainVS();
- PixelShader = compile PS_SHADERMODEL MainPS();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement