置灰的shader
Shader "My/PostEffectGray" { Properties { _MainTex("Texture", 2D) = "white" {} } SubShader { Tags { "RenderType" = "Opaque" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; }; sampler2D _MainTex; float4 _MainTex_ST; v2f vert(appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); return o; } fixed4 frag(v2f i) : SV_Target { fixed4 c = tex2D(_MainTex, i.uv); c.rgb = Luminance(c.rgb); return c; } ENDCG } } }
PostEffectsBase来自shader入门精要第12章
using UnityEngine; public class PostEffectGray : PostEffectsBase { public Shader m_grayShader; private Material m_grayMaterial; public Material material { get { m_grayMaterial = CheckShaderAndCreateMaterial(m_grayShader, m_grayMaterial); return m_grayMaterial; } } void OnRenderImage(RenderTexture src, RenderTexture dest) { if (null != material) { Graphics.Blit(src, dest, material); } else { Graphics.Blit(src, dest); } } }
参考
unity 常见的置灰处理_天涯过客TYGK的博客-CSDN博客_unity置灰mash
标签:MainTex,uv,vertex,grayMaterial,后处理,v2f,简单,float4,屏幕 From: https://www.cnblogs.com/sailJs/p/17120669.html