- Home /
Textured object appears transparent in a textured sphere with front culling
I have a textured sphere with front culling so when I put camera at center I can see texture from in sphere, similar to viewing 360.
I want to put a textured object in the sphere to see both sphere texture and object texture. Everything is fine when shader of object is set to opaque. But when I set shader to fade, because I want to change transparence of object, the object just disappears and can only see sphere.
What I noticed is that the object seems to be only showing if I move the camera so it's facing from out to in.
But when I move camera to face from in to out, object just disappear.
Anyone know what might be problem? Thank you.
My sphere shader
Shader "PanoSphere" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Alpha ("Alpha", Float) = 1
}
SubShader {
Tags { "Queue" = "Transparent" "RenderType" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
Cull front
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _Alpha;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
v.texcoord.x = 1 - v.texcoord.x;
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord);
col.a *= _Alpha;
return col;
}
ENDCG
}
}
}
Answer by brianleake · Feb 13, 2016 at 08:02 PM
You may want to investigate what render queue the other object is in and what shader it is using. Also think about what your desired Z-test and Z-write is for both of the objects and shaders. You may want to be explicit with ZTest and ZWrite. If the contained object doesn't write to Z, then the containing object draws after it (or doesn't do a ZTest) then it could just obliterate it on screen. Just a thought.
Your answer
Follow this Question
Related Questions
Cross Section Shader 1 Answer
Cullingmask issue. 0 Answers
Is It Possible To Clip a Sprite With Another Sprite? 2 Answers
Uniform Texture, Rendering Problem 0 Answers
Multiple materials on same object 0 Answers