Hi guys I am trying to learn how to write shaders by hand for URP but lack of documentation and varying info all over the place is confusing me.
As an exercise to learn this I am trying to convert this shader from minionsart:
Shader "Unlit/SimpleWater"
{
Properties
{
_Tint("Tint", Color) = (1, 1, 1, .5)
_MainTex ("Main Texture", 2D) = "white" {}
_NoiseTex("Extra Wave Noise", 2D) = "white" {}
_Speed("Wave Speed", Range(0,1)) = 0.5
_Amount("Wave Amount", Range(0,1)) = 0.5
_Height("Wave Height", Range(0,1)) = 0.5
_Foam("Foamline Thickness", Range(0,3)) = 0.5
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue" = "Transparent" }
LOD 100
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
float4 scrPos : TEXCOORD1;//
};
float4 _Tint;
uniform sampler2D _CameraDepthTexture; //Depth Texture
sampler2D _MainTex, _NoiseTex;//
float4 _MainTex_ST;
float _Speed, _Amount, _Height, _Foam;//
v2f vert (appdata v)
{
v2f o;
float4 tex = tex2Dlod(_NoiseTex, float4(v.uv.xy, 0, 0));//extra noise tex
v.vertex.y += sin(_Time.z * _Speed + (v.vertex.x * v.vertex.z * _Amount * tex)) * _Height;//movement
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.scrPos = ComputeScreenPos(o.vertex); // grab position on screen
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
half4 col = tex2D(_MainTex, i.uv) * _Tint;// texture times tint;
half depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos))); // depth
half4 foamLine =1 - saturate(_Foam * (depth - i.scrPos.w));// foam line by comparing depth and screenposition
col += foamLine * _Tint; // add the foam line and tint to the texture
return col ;
}
ENDCG
}
}
}
However I am struggling to find decent info on what is required to get this to work for URP. In another thread here someone explained how I can get an alternative to SAMPLE_DEPTH_TEXTURE_PROJ and UNITY_PROJ_COORD
But right now I am having trouble working out what includes, pragma etc statements I need, where in general everything is located (as in which hlsl files contain the useful stuff) as well as how to set up the appdata and v2f structs properly as none of that compiles.
Right now I am trial and erroring it so if anyone has any bits of knowledge I would appreciate it and I am certain this will also be useful to other users too!
TLDR
Whats the minimum I need to get this working (or at very least compiling) with URP?
What parts of this cannot be converted at all, and what alternatives do I have other than ripping those bits out (I am sure the fog bits wont work for example)?
I am happy to work some stuff out on my own, but I definately need to be pointed in the right direction as all the varying info flying around has me super confused
Thanks for any help you can provide!