Quantcast
Channel: Questions in topic: "post processing"
Viewing all articles
Browse latest Browse all 713

How do you port old shaders to hlsl so they work with the new post-processing stack?

$
0
0
I recently upgraded my project's graphics pipeline to the new lightweight srp. When it comes to shaders I'm a complete novice. I tried to port several of my old shaders that I had attached to my camera to the new format so they work with the new post-processing stack, following this guide: https://github.com/Unity-Technologies/PostProcessing/wiki/Writing-Custom-Effects. However I'm completely stumped as to what to do exactly. For example I tried to port this publicly available shader: Shader "Hidden/Pixelation" { Properties { _MainTex ("Texture", 2D) = "white" {} } SubShader { Pass { CGPROGRAM #pragma vertex vert_img #pragma fragment frag #include "UnityCG.cginc" sampler2D _MainTex; float2 BlockCount; float2 BlockSize; fixed4 frag (v2f_img i) : SV_Target { float2 blockPos = floor(i.uv * BlockCount); float2 blockCenter = blockPos * BlockSize + BlockSize * 0.5; float4 tex = tex2D(_MainTex, blockCenter); return tex; } ENDCG } } } And this was my attempt: Shader "Hidden/Custom/Pixelisation" { HLSLINCLUDE #include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl" TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex); float2 BlockCount; float2 BlockSize; ENDHLSL SubShader { Cull Off ZWrite Off ZTest Always Pass { HLSLPROGRAM #pragma vertex VertDefault #pragma fragment Frag #include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl" struct appdata { float4 vertex:POSITION; float2 uv:TEXCOORD0; }; struct v2f { float2 uv:TEXCOORD0; float4 vertex:SV_POSITION; }; v2f vert(appdata v) { v2f o; o.vertex=UnityObjectToClipPos(v.vertex); o.uv=v.uv; return o; } float4 Frag(v2f i) : SV_Target { float2 blockPos = floor(i.uv * BlockCount); float2 blockCenter = blockPos * BlockSize + BlockSize * 0.5; float4 tex = tex2D(_MainTex, blockCenter); return tex; } ENDHLSL } } } here it throws an error on UnityObjectToClipPos, saying it's an undeclared identifier. Can someone tell me where I'm going wrong? Or maybe point me in the right direction on this? I'm completely lost here.

Viewing all articles
Browse latest Browse all 713

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>