Hi,
I’m trying to render a textured quad in OnRenderImage using GL methods. I’ve got a Material with this shader:
Shader "Custom/MarkerShader" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Spec Color", Color) = (1,1,1,0)
_Emission ("Emissive Color", Color) = (0,0,0,0)
_Shininess ("Shininess", Range (0.1, 1)) = 0.7
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {"RenderType"="Transparent" "Queue"="Transparent"}
// Render normally
Pass {
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Lighting On
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
}
}
In the inspector I set Main Color and Spec Color to (0,0,0,1), Emission to (0,1,0,1) and Shininess to 0. The texture is set to a png with alpha channel. I import the texture with “Alpha is Transparency” checked. In OnRenderImage, I first blit src to dst, then I try to draw the textured quad like this:
Material mat = this.MarkerMaterial;
GL.Color( Color.white );
mat.SetPass( 0 );
GL.PushMatrix();
{
GL.LoadOrtho();
GL.LoadIdentity();
pos.x *= ar;
pos.y = 1.0f - pos.y;
GL.MultMatrix( Matrix4x4.Scale( new Vector3( 1.0f / ar, 1.0f, 1.0f ) ) * Matrix4x4.TRS( pos, q, Vector3.one ) );
GL.Begin( GL.QUADS );
{
GL.Vertex3( -markerWidth, -markerHeight, 0.0f );
GL.Vertex3( -markerWidth, markerHeight, 0.0f );
GL.Vertex3( markerWidth, markerHeight, 0.0f );
GL.Vertex3( markerWidth, -markerHeight, 0.0f );
}
GL.End();
}
GL.PopMatrix();
When I try to render using the texture including alpha channel, I see nothing. When I replace it by another texture without alpha, it works.
Any ideas about what I’m doing wrong?
Thanks a lot.
Now, that's embarrassing. When I switched from lines to quad I forgot that I now have to also set the uv coordinates. I was so distracted by all the ShaderLab syntax I'm not quite familiar with that I thought I must have made a mistake there somewhere.