I'm trying to use this custom shader from Sebastian League on Universal Render Pipeline, but since it only accepts HLSL language i have to port it. Its supposed to display a flat projection of a camera onto a surface, and have the camera follow the player's movement so it looks like a window. But i only got it to become grey.
![alt text][1]
Heres what i got so far:
The original code:
Shader "Custom/Portal"
{
Properties
{
_InactiveColour ("Inactive Colour", Color) = (1, 1, 1, 1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Cull Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
float4 screenPos : TEXCOORD0;
};
sampler2D _MainTex;
float4 _InactiveColour;
int displayMask; // set to 1 to display texture, otherwise will draw test colour
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.screenPos = ComputeScreenPos(o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 uv = i.screenPos.xy / i.screenPos.w;
fixed4 portalCol = tex2D(_MainTex, uv);
return portalCol * displayMask + _InactiveColour * (1-displayMask);
}
ENDCG
}
}
Fallback "Standard" // for shadows
}
My HLSL conversion:
Shader "Custom/AverageShader"
{
Properties
{
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
LOD 100
Cull Off
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
//#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct Varyings
{
float4 vertex : SV_POSITION;
float4 screenPos : TEXCOORD0;
};
sampler2D _MainTex;
Varyings vert (appdata v)
{
Varyings o;
//o.vertex = UnityObjectToClipPos(v.vertex);
o.vertex = mul(mul(unity_MatrixVP, unity_ObjectToWorld), (v.vertex));
o.screenPos = ComputeScreenPos(o.vertex);
return o;
}
float4 frag (Varyings i) : SV_Target
{
float2 uv = i.screenPos.xy / i.screenPos.w;
float4 portalCol = tex2D(_MainTex, uv);
return portalCol;
}
ENDHLSL
}
}
}
[1]: /storage/temp/177525-upload-2021-3-13-20-35-19.png
↧