【发布时间】:2012-10-25 15:06:55
【问题描述】:
我有一个灰度着色器,可以在应用于材质时工作。 我想将其应用于相机渲染的内容。
我找到了一些关于 void OnRenderImage(RenderTexture 源,RenderTexture 目标)
但我无法让它与我的一起工作。
着色器:
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。请不要滥用它。