Skip to content

Instantly share code, notes, and snippets.

@hvent90
Created January 21, 2019 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hvent90/1365f0dc531e9699eb8abed6a7a03df5 to your computer and use it in GitHub Desktop.
Save hvent90/1365f0dc531e9699eb8abed6a7a03df5 to your computer and use it in GitHub Desktop.
Shader "Raymarch/RaymarchHDRP"
{
SubShader
{
Cull Off ZWrite Off ZTest Always
Pass
{
HLSLPROGRAM
#pragma target 3.5
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl"
TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex);
half4 _MainTex_ST;
uniform float4 _CamWorldSpace;
uniform float4x4 _CamFrustum, _CamToWorld;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
float2 texcoordStereo : TEXCOORD1;
float3 ray : TEXCOORD2;
};
v2f vert(AttributesDefault v)
{
v2f o;
o.vertex = float4(v.vertex.xy, 0.0, 1.0);
o.texcoord = TransformTriangleVertexToUV(v.vertex.xy);
#if UNITY_UV_STARTS_AT_TOP
o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
#endif
o.texcoordStereo = TransformStereoScreenSpaceTex(o.texcoord, 1.0);
half index = v.vertex.z;
v.vertex.z = 0;
o.vertex = mul(unity_MatrixVP, v.vertex);
o.ray = _CamFrustum[(int)index].xyz;
o.ray /= abs(o.ray.z);
o.ray = mul(_CamToWorld, o.ray);
return o;
}
float4 frag(v2f i) : SV_Target
{
float3 rayDirection = normalize(i.ray.xyz);
float3 rayOrigin = _CamWorldSpace;
return float4(rayDirection, 1);
}
ENDHLSL
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment