- Home /
Question by
abbsimoga · Nov 09, 2021 at 03:05 PM ·
shaderprefabtransparentforward rendering
ForwardAdd tag makes material invinsible in prefab preview
As shown in this image: The prefab is visible in the project folder and in the game view however it is transparrent in "prefab view". Changing the ForwardAdd tag to ForwardBase only kinda fixes this issue as shown here:
However then my shader breaks in game. How can i make the shader visible in "prefab view" and work in game?
Shader:
Shader "Custom/Stone Shader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1, 1, 1, 1)
_ShadowSoftness("_ShadowSoftness", Range(0,1)) = 0.5
_DarkestValue("Darkest Value", Range(0, 1)) = 0.0
}
SubShader
{
Pass
{
Tags
{
"RenderType" = "Opaque"
"Queue"="Geometry+2"
"LightMode" = "ForwardAdd"
"PassFlags" = "OnlyDirectional"
}
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight
#include "/Assets/Graphics/CGincFiles/NormalShading.cginc"
float4 _Color;
fixed4 frag(v2f i) : SV_Target
{
fixed light = CalculateLight(i);
fixed4 light_color = _LightColor0.rgba * light;
return fixed4(_Color.rgb * light_color.rgb, 1);
}
ENDCG
}
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}
NormalShading.cginc:
#include "UnityCG.cginc"
#include "AutoLight.cginc"
#include "Lighting.cginc"
sampler2D _LightTexture0;
float4x4 unity_WorldToLight;
float _ShadowSoftness;
float _DarkestValue;
float _DayNightTime;
struct v2f
{
float2 uv : TEXCOORD0;
SHADOW_COORDS(1)
fixed3 diff : COLOR0;
fixed3 ambient : COLOR1;
float4 pos : SV_POSITION;
float3 worldPos : TEXCOORD2;
};
v2f vert(appdata_base v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.worldPos = mul (unity_ObjectToWorld, v.vertex);
o.uv = v.texcoord;
half3 worldNormal = UnityObjectToWorldNormal(v.normal);
half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
o.diff = nl * _LightColor0.rgb;
o.ambient = ShadeSH9(half4(worldNormal,1));
TRANSFER_SHADOW(o)
return o;
}
fixed CalculateLight(v2f i)
{
float shadow = SHADOW_ATTENUATION(i);
shadow = saturate(shadow + _ShadowSoftness * _DayNightTime);
fixed2 uvCookie = mul(unity_WorldToLight, float4(i.worldPos, 1)).xy;
fixed attenuation = tex2D(_LightTexture0, uvCookie).w;
fixed3 lighting = i.diff * shadow * attenuation + i.ambient;
return max(saturate(lighting.x), _DarkestValue * _DayNightTime);
}
capture1.png
(156.1 kB)
capture2.png
(136.7 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613045154im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
alpha sorting issues 1 Answer
Semi transparent Object behind walls? 1 Answer
Transparent Shader/Water With Shadows 1 Answer
Z-priming alpha-per-vertex 0 Answers
Transparent terrain shader not working 2 Answers