4
我有一个灰度着色器,适用于材质时工作。 我想将它应用于相机呈现的内容。应用后处理着色器
我发现了一些教程谈到 无效OnRenderImage(渲染纹理源,渲染纹理目的地)
,但我无法使其与我的工作。
着色器:
Shader "Custom/Grayscale" {
SubShader {
Pass{
CGPROGRAM
#pragma exclude_renderers gles
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
fixed4 frag(v2f_img i) : COLOR{
fixed4 currentPixel = tex2D(_MainTex, i.uv);
fixed grayscale = Luminance(currentPixel.rgb);
fixed4 output = currentPixel;
output.rgb = grayscale;
output.a = currentPixel.a;
//output.rgb = 0;
return output;
}
ENDCG
}
}
FallBack "VertexLit"
}
和连接到相机的脚本:
using UnityEngine;
using System.Collections;
public class Grayscale : ImageEffectBase {
void OnRenderImage (RenderTexture source, RenderTexture destination) {
Graphics.Blit (source, destination, material);
}
}
有什么建议? 非常感谢!
统一标签用于Microsoft Unity。请不要滥用它。 –