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? The light is directional and uses a lightcookie, do plan on supporting multiple lights (pointlights, etc). 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); }
Include both passes. Make a ForwardBase and ForwardAdd in your shader. The pragma for ForwardAdd should be multi_compile_fwdadd and for ForwardBase multi_compile_fwdbase . You want both passes in your shader because they are both used in the forward rendering process. Base is used for the basic lighting and Add is for every additional light in the scene. The default Prefab preview window does not have Additional lights, so ForwardAdd isn't being used in that context. Writing shaders for URP is different, you can't use the old syntax that the example in this thread is using. It only needs a pass named "ForwardLit" and in the tags "LightMode" = "UniversalForward". But also the pass needs to be written with URP references and syntax in mind. You can see an example here: https://github.com/phi-lira/Univers...Scenes/51_LitPhysicallyBased/CustomLit.shader and https://github.com/ColinLeung-NiloC.../master/SimpleURPToonLitOutlineExample.shader
Thanks for replying, I've fixed this issue by changing the default behaviour mode from 3D to 2D, after deleting the library folder, all prefab's preview images are right.