Hello Unity Community,
I’m having trouble with scripted post-processing shaders. The shader itself works inside the editor but as soon as I build and run the project I get a black screen. Most probably I’m doing something wrong…
I created a tiny sample that shows the problem. I hope someone can reproduce the problem.
What I’m doing is this: Attach a custom shader to a material and call Graphics.blit(…) during the OnImageRender callback of the main camera. (Is that the way to go?)
I’m using the Unity3d Pro Trial on Win7 64bit. The build itself is 32bit.
Here is the complete code (just in case…)
PostShader.cs
using UnityEngine;
using System.Collections;
public class PostShader : MonoBehaviour {
private Material mat;
// Use this for initialization
void Start () {
mat = new Material(Shader.Find("Custom/PostShader"));
}
// Update is called once per frame
void Update () {
}
void OnRenderImage (RenderTexture src, RenderTexture dst) {
Graphics.Blit(src, dst, mat);
}
}
PostShader.shader
Shader "Custom/PostShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = half3(c.b, c.r, c.g);
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Any suggestions are appreciated!
Kind Regards,
Gregg
1416972–74376–$BugSample.zip (182 KB)