【问题标题】:Apply post processing shader应用后处理着色器
【发布时间】: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。请不要滥用它。

标签: unity3d shader


【解决方案1】:

您必须添加一个顶点着色器,因为没有默认的顶点着色器。这只是从顶点缓冲区复制数据。

#pragma vertex vert
v2f_img vert (appdata_base v) {
    v2f_img o;
    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    o.uv = v.texcoord;
    return o;
}

AND ALSO 你可以在Pass { 之后添加ZTest Always。

这显然是一个错误,但 Unity3d 支持人员表示他们以这种方式保留它(使用默认 ZTest)不是为了改变着色器行为。我希望他们会重新考虑这一点,并让ZTest Always 默认用于Graphics.Blit。

【讨论】:

    猜你喜欢
    • 2010-11-05
    • 2015-02-22
    • 2013-05-21
    • 1970-01-01
    • 2018-11-14
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多