In editor mode, when I make a change to the following shader, save, and return window focus to Unity, Unity crashes. If I comment out lines 29 - 33 (the grab pass), everything works fine. Any help? I read somewhere it could be related to something else in my scene using render textures. Is that a possible cause? Code (CSharp): Shader "WaterLAB/Balanced/Weir - Fluid Surface" { Properties { _MainTex("Albedo (RGB)", 2D) = "white" {} _NormalMap("Bump", 2D) = "bump" {} _MainTint("Diffuse Tint", Color) = (1,1,1,1) _SpecPower("Specular Power", Range(0.1, 500)) = 3 //How much objects/light behind the water flow is "bent" _RefractionAmount("Refraction Amount", Range(0, 100)) = 35 //How much to multiply the diffuse color in greyscale value before assinging to the output alpha _DiffToAlphaPower("Diffuse To Alpha Power (Lighting)", Range(0.5, 1.5)) = 1.5 } SubShader { Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } Cull Back ZWrite Off Blend SrcAlpha OneMinusSrcAlpha LOD 200 // This pass grabs the screen behind the object into a texture. // We can access the result in the next pass as _GrabTexture GrabPass { Name "BASE" Tags{ "LightMode" = "Always" } } // Refraction pass: Take the texture grabbed above and use the bumpmap to perturb it //// on to the screen //Pass //{ // Name "BASE" // Tags{ "LightMode" = "Always" } // CGPROGRAM // #pragma vertex vert // #pragma fragment frag // #pragma fragmentoption ARB_precision_hint_fastest // #include "UnityCG.cginc" // struct appdata_t { // float4 vertex : POSITION; // float2 texcoord: TEXCOORD0; // }; // struct v2f { // float4 vertex : POSITION; // float4 uvgrab : TEXCOORD0; // float2 uvbump : TEXCOORD1; // }; // sampler2D _NormalMap; // float4 _NormalMap_ST; // float _RefractionAmount; // sampler2D _GrabTexture; // float4 _GrabTexture_TexelSize; // v2f vert(appdata_t v) // { // v2f o; // //Set vertex position from model space to screen space // o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); // //Adjust for OpenGL/DirectX platforms // #if UNITY_UV_STARTS_AT_TOP // float scale = -1.0; // #else // float scale = 1.0; // #endif // //Set UV Grab // o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5; // o.uvgrab.zw = o.vertex.zw; // //Set UV Bump, including the tiling/offset values given from the inspector // o.uvbump = TRANSFORM_TEX(v.texcoord, _NormalMap); // return o; // } // half4 frag(v2f i) : COLOR // { // // calculate perturbed coordinates // // we could optimize this by just reading the x & y without reconstructing the Z in the UnpackNormal method (from the UnityCG.cginc) // half2 bump = UnpackNormal(tex2D(_NormalMap, i.uvbump)).rg; // float2 offset = bump * _RefractionAmount * _GrabTexture_TexelSize.xy; // i.uvgrab.xy = offset * i.uvgrab.z + i.uvgrab.xy; // half4 col = tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(i.uvgrab)); // return col; // } // ENDCG //} CGPROGRAM #pragma surface surf CustomBlinnPhong alpha sampler2D _MainTex; sampler2D _NormalMap; float4 _MainTint; float _SpecPower; float _DiffToAlphaPower; struct Input { float2 uv_MainTex; }; void surf(Input IN, inout SurfaceOutput o) { half4 c = tex2D(_MainTex, IN.uv_MainTex) * _MainTint; o.Albedo = c.rgb; o.Specular = _SpecPower; o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTex)); } inline fixed4 LightingCustomBlinnPhong(SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten) { float3 halfVector = normalize(lightDir + viewDir); float diff = max(0, dot(s.Normal, lightDir)); float nh = max(0, dot(s.Normal, halfVector)); float spec = pow(nh, _SpecPower); fixed4 c; c = fixed4(1, 0, 0, 1) * atten; //c.rgb = (s.Albedo * _LightColor0.rgb * diff) + (_LightColor0.rgb * spec) * (atten * 2); //c.a = pow((c.r + c.g + c.b) / 3, _DiffToAlphaPower); return c; } ENDCG } FallBack "Diffuse" }
Update, it's now happening with other shaders, even worse, when I relaunch, my scene is reverted to the state it was when I launched unity last even if i saved it after the first launch. I've lost plenty of work because of this. Yet even worse, changes made to assets are also reverted to the state they were in at last launch. So now I may run into bugs as a result of changes to assets that were not preserved. This is a huge problem and is killing my productivity. Stack trace from the crash: Code (CSharp): 0x0000000140C2C971 (Unity) SelectionRenderQueue::Render 0x0000000140C2D08D (Unity) PickObjects 0x0000000140C2DF62 (Unity) PickClosestObject 0x0000000140C2E205 (Unity) PickClosestGO 0x000000014130DE77 (Unity) HandleUtility_CUSTOM_INTERNAL_CALL_Internal_PickClosestGO 0x0000000026BC6203 (Mono JIT Code) (wrapper managed-to-native) UnityEditor.HandleUtility:INTERNAL_CALL_Internal_PickClosestGO (UnityEngine.Camera,int,UnityEngine.Vector2&,UnityEngine.GameObject[],int&) 0x0000000026BC60EE (Mono JIT Code) [C:\buildslave\unity\build\artifacts\generated\common\editor\EditorHandlesUtilityBindings.gen.cs:536] UnityEditor.HandleUtility:Internal_PickClosestGO (UnityEngine.Camera,int,UnityEngine.Vector2,UnityEngine.GameObject[],int&) 0x0000000026BC5EB6 (Mono JIT Code) [C:\buildslave\unity\build\artifacts\generated\common\editor\EditorHandlesUtilityBindings.gen.cs:479] UnityEditor.HandleUtility:PickGameObject (UnityEngine.Vector2,UnityEngine.GameObject[],int&) 0x0000000026BC5960 (Mono JIT Code) [C:\buildslave\unity\build\artifacts\generated\common\editor\EditorHandlesUtilityBindings.gen.cs:493] UnityEditor.HandleUtility:PickGameObject (UnityEngine.Vector2,bool,UnityEngine.GameObject[]) 0x0000000026BC5645 (Mono JIT Code) [C:\buildslave\unity\build\Editor\Mono\SceneView\SceneViewPicking.cs:84] UnityEditor.SceneViewPicking:GetAllOverlapping (UnityEngine.Vector2) 0x0000000026BC4F44 (Mono JIT Code) [C:\buildslave\unity\build\Editor\Mono\SceneView\SceneViewPicking.cs:27] UnityEditor.SceneViewPicking:PickGameObject (UnityEngine.Vector2) 0x0000000020074F1F (Mono JIT Code) [C:\buildslave\unity\build\Editor\Mono\SceneView\RectSelection.cs:143] UnityEditor.RectSelection:OnGUI () 0x000000002007324A (Mono JIT Code) [C:\buildslave\unity\build\Editor\Mono\SceneView\SceneView.cs:1404] UnityEditor.SceneView:HandleSelectionAndOnSceneGUI () 0x000000002004E546 (Mono JIT Code) [C:\buildslave\unity\build\Editor\Mono\SceneView\SceneView.cs:1242] UnityEditor.SceneView:OnGUI () 0x000000001C38D422 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr) 0x00007FFF7BAB41BF (mono) [c:\buildslave\mono-runtime-and-classlibs\build\mono\mini\mini.c:4937] mono_jit_runtime_invoke 0x00007FFF7BA08435 (mono) [c:\buildslave\mono-runtime-and-classlibs\build\mono\metadata\object.c:2623] mono_runtime_invoke 0x00007FFF7BA0E82F (mono) [c:\buildslave\mono-runtime-and-classlibs\build\mono\metadata\object.c:3827] mono_runtime_invoke_array 0x00007FFF7B9CCF2F (mono) [c:\buildslave\mono-runtime-and-classlibs\build\mono\metadata\icall.c:2857] ves_icall_InternalInvoke 0x000000001C370217 (Mono JIT Code) (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&) 0x000000001C36E372 (Mono JIT Code) [/Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222] System.Reflection.MonoMethod:Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) 0x000000001DA77B4F (Mono JIT Code) [/Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115] System.Reflection.MethodBase:Invoke (object,object[]) 0x0000000015B5F9C6 (Mono JIT Code) [C:\buildslave\unity\build\Editor\Mono\HostView.cs:187] UnityEditor.HostView:Invoke (string,object) 0x0000000015B5F8B0 (Mono JIT Code) [C:\buildslave\unity\build\Editor\Mono\HostView.cs:180] UnityEditor.HostView:Invoke (string) 0x000000001FFD9092 (Mono JIT Code) [C:\buildslave\unity\build\Editor\Mono\GUI\DockArea.cs:336] UnityEditor.DockArea:OnGUI () 0x000000001C38D422 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr) 0x00007FFF7BAB41BF (mono) [c:\buildslave\mono-runtime-and-classlibs\build\mono\mini\mini.c:4937] mono_jit_runtime_invoke 0x00007FFF7BA08435 (mono) [c:\buildslave\mono-runtime-and-classlibs\build\mono\metadata\object.c:2623] mono_runtime_invoke 0x000000014033E20F (Unity) scripting_method_invoke 0x00000001404A3EDC (Unity) ScriptingInvocationNoArgs::Invoke 0x00000001412058E6 (Unity) MonoBehaviourDoGUI 0x00000001411F8EC0 (Unity) IMGUIModule::MonoBehaviourDoGUI 0x000000014031F35A (Unity) MonoBehaviour::DoGUI 0x0000000140DAF8ED (Unity) GUIView::OnInputEvent 0x0000000140DB0A79 (Unity) GUIView::ProcessEventMessages 0x0000000140DB24F5 (Unity) GUIView::GUIViewWndProc 0x00007FFFAEAE250D (USER32) DispatchMessageW 0x00007FFFAEAE2367 (USER32) NotifyWinEvent 0x0000000140DCCDCB (Unity) RelaunchUnity 0x0000000140DCE45A (Unity) WinMain 0x000000014151FBB4 (Unity) read 0x00007FFFAE5A13D2 (KERNEL32) BaseThreadInitThunk
I ran into a similar problem just now, figured out why my problem was so maybe this would be helpful for you. I have an effect that uses grabpass. The effect works by using Graphics.DrawMesh with the layer of the object it is attached to. What I found is that if the layer is "TransparentFX" it works, however if the layer is "Default" it instantly crashes. There are some other things going on in my game - there is a minimap camera and a camera that does a different grab pass / depth pass for some water drawing. Those cameras don't render TransparentFX layers. So it seems like the problem is that I have an effect that uses a grab pass, and that effect is ITSELF used by cameras that also use other grab passes. By making those effects not included in those other cameras by adjusting the layer the problem is fixed. Hope that helps.
Could you submit a bug-report for this issue, please? Otherwise it's rather unlikely that Unity is going to fix this issue from my experience.