Hi,
It seems that Blend Off doesnt turn off blending, is it a bug?
how can i make an object opaque once it has faded in? i fade things in and they are transparent when alpa = 1.
Hi,
It seems that Blend Off doesnt turn off blending, is it a bug?
how can i make an object opaque once it has faded in? i fade things in and they are transparent when alpa = 1.
What sort of shader are you writing (surface, vertex/fragment)? What behaviour are you seeing with Blend Off? How are you fading things in if alpha isn’t linked to transparency?
How exactly does the object look like or behave with alpha set to 1?
Here is a pic of the mountains with alpha set to 1, it can fade in the distant mountains as they appear but then i have to change to a non transparent shader:
when the camera is turned towards the shadow side it’s fine.
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
LOD 200
Blend Off
Have you tried changing the tags to Tags { “RenderType”=“Opaque” }?
Yes i tried that, it caused an error, there is a message: render queue doesnt exist in shader. I think it’s safe to say that Blend Off isn’t working?
Google says that blend off isnt mentioned on unity community pages and there are only 1-2 shaders on the net using it.
As a fix, i switch between a transparent and an opaque shader using
go.renderer.material.shader = Shader.Find ("Custom/VerticalMultiTrns");
And in webplayer it plays differently, texture updates after 30 seconds so much of the game is pink… i think i should load a material instead. Other than that unity is 100 cool
It is working, I can’t see any kind of blending happening there. Just the geometry is drawn in the wrong order, not respecting the z buffer. Just turning on alpha blending doesn’t give you a properly working transparent object. It needs to be handled differently by the engine (thus the special tags) and it needs to turn off z-writing, so that objects behind it are still shown. It’s the same other way around, setting the alpha of an otherwise transparent object to 1 won’t give you a properly shown opaque object.
So yeah, since there’s no way you can change the tags of a shader dynamically, switching materials is your best bet.
I think that the light parts of an object are visible trough the dark parts of the object on the same mesh? on the above pic on the left you can see the sand going trough the grass i think it’s on the same mesh…
I’m confused by the vertical lines of transparency, what they correspond to?
It would suggest that there is blending relative to color?
In CG code it is possible to have transparent objects that display opaque areas without some opaque parts of mesh visible through others?
I’m pretty sure the cause is that your shader is not writing into the z-buffer… That means the visible triangle is not necessarily the triangle closest to the camera, causing these artifacts.
Actually… In your case, you just want to make the terrain fade away as a whole, right? You don’t need to see the rest of the terrain that might be behind it. Then try taking your transparent shader and just set ZWrite to On. Even fully opaque parts should be shown without artifacts.
I think the easiest option is to switch out the shader to an opaque one once the fade-in’s done.
Is it a kind of error with Unity? Farfarer’s solution solves the problem for near objects, except the far away mountains that fade in are still errored.
should i submit a bug report to unity?
Shader "Custom/MultiTrans" {
Properties {
_TexTop ("Top", 2D) = "white" {}
_TexMid ("Mid", 2D) = "white" {}
_TexBot ("Bot", 2D) = "white" {}
_TopLimit("TopLimit", Range(-1, 1)) = 0.7
_BotLimit("BotLimit", Range(-1, 1)) = 0.27
_MidLimit("MidLimit", Range(-1, 1)) = 0.43
_TotalMetres("TotalMetres", float) = 100
_MidZone("_MidZone", Range(-100, 100)) = 20
_ts ("_ts",float) = 1
}
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
LOD 200
ZWrite On
// Cull Off
Blend OneMinusSrcAlpha One
CGPROGRAM
#pragma surface surf Lambert alpha
#pragma exclude_renderers ps3 flash
sampler2D _TexTop;
sampler2D _TexMid;
sampler2D _TexBot;
float _ts;
float _TopLimit;
float _MidLimit;
float _BotLimit;
float _TotalMetres,_MidZone;
struct Input {
float2 uv_TexTop;
float3 worldNormal;
float incline;
float3 worldPos;
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
o.incline = abs(v.normal.y);
}
void surf (Input IN, inout SurfaceOutput o) {
float Alti = (IN.worldPos.y+_MidZone)/_TotalMetres;
float4 resultCol =
// Above topLimit, 100% topTexture
Alti >= _TopLimit ? tex2D(_TexTop, IN.uv_TexTop)
// Below botLimit, 100% botTexture
: (Alti <= -_BotLimit ? tex2D(_TexBot, IN.uv_TexTop)
// Between sideLimit and -MidLimit, 100% MidTexture
: (Alti <= _MidLimit && Alti >= -_MidLimit ? tex2D(_TexMid, IN.uv_TexTop)
// Above 0 outside thresholds, blend between side and top
: (Alti > 0 ? lerp(tex2D(_TexTop, IN.uv_TexTop), tex2D(_TexMid, IN.uv_TexTop),
1 - ((Alti - _MidLimit) / (_TopLimit - _MidLimit)))
// Below 0, outside thresholds, blend between side and bot
: lerp(tex2D(_TexBot, IN.uv_TexTop), tex2D(_TexMid, IN.uv_TexTop),
1 - ((abs(Alti) - _MidLimit) / (abs(_BotLimit) - _MidLimit))))));
o.Albedo = resultCol.rgb;
o.Alpha = _ts;
}
ENDCG
}
FallBack "Diffuse"
}
To get non-convex transparent objects (like that terrain) to render properly transparently, you need to render them without Z-writing, with some blending, and you need to render them from furthest to nearest order, with respect to the camera. That last part is kind of difficult to do when you don’t have full control over the geometry.