{"action":"created","issue":{"url":"https://api.github.com/repos/candycat1992/Unity_Shaders_Book/issues/35","repository_url":"https://api.github.com/repos/candycat1992/Unity_Shaders_Book","labels_url":"https://api.github.com/repos/candycat1992/Unity_Shaders_Book/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/candycat1992/Unity_Shaders_Book/issues/35/comments","events_url":"https://api.github.com/repos/candycat1992/Unity_Shaders_Book/issues/35/events","html_url":"https://github.com/candycat1992/Unity_Shaders_Book/issues/35","id":173953845,"number":35,"title":"第9章第2节疑似代码错误","user":{"login":"JOKULLIU","id":5339546,"avatar_url":"https://avatars.githubusercontent.com/u/5339546?v=3","gravatar_id":"","url":"https://api.github.com/users/JOKULLIU","html_url":"https://github.com/JOKULLIU","followers_url":"https://api.github.com/users/JOKULLIU/followers","following_url":"https://api.github.com/users/JOKULLIU/following{/other_user}","gists_url":"https://api.github.com/users/JOKULLIU/gists{/gist_id}","starred_url":"https://api.github.com/users/JOKULLIU/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JOKULLIU/subscriptions","organizations_url":"https://api.github.com/users/JOKULLIU/orgs","repos_url":"https://api.github.com/users/JOKULLIU/repos","events_url":"https://api.github.com/users/JOKULLIU/events{/privacy}","received_events_url":"https://api.github.com/users/JOKULLIU/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-30T08:01:08Z","updated_at":"2016-08-31T05:08:16Z","closed_at":null,"body":"作者你好。\r\n前次给你发了一个邮件说发布PC包的Shader不被支持的问题。\r\n根据我逐个计算模块的排查，以及直接使用你的工程里面第9章第2节的“Forward Rendering”的源码，基本可以确定是以下代码引发错误：\r\n```\r\n#ifdef USING_DIRECTIONAL_LIGHT\r\n    fixed atten = 1.0;\r\n#else\r\n    float3 lightCoord = mul(_LightMatrix0, float4(i.worldPos, 1)).xyz;\r\n// half lr = dot(lightCoord, lightCoord);\r\n    fixed atten = tex2D(_LightTexture0, dot(lightCoord, lightCoord).rr).UNITY_ATTEN_CHANNEL;\r\n// fixed atten = tex2D(_LightTexture0, half2(lr, lr)).UNITY_ATTEN_CHANNEL;\r\n#endif\r\n```\r\n上面注释的两句代码，是我误以为d3d11不支持.rr的写法，就换了一个写法，但不管用。\r\n报错是：\r\nShader error in 'Forward Rendering': 'tex2D': no matching 2 parameter intrinsic function; Possible intrinsic functions are:……\r\n后面是Unity给出的tex2D函数格式建议。\r\n此错误在编辑器模式下不会报，且可以正确计算衰减，但如果打包至win平台，则会报上述错误。\r\n如将此段代码注释，一切正常。\r\n此错误会导致Shader无法被执行，两个Pass被移除，并寻找备胎。\r\n备胎代码：\r\n`FallBack \"Specular\"`\r\n无法正常执行。\r\n下面是Unity的output_log记录：\r\n```\r\nWARNING: Shader Unsupported: 'Forward Rendering' - Pass '' has no vertex shader\r\nWARNING: Shader Unsupported: 'Forward Rendering' - All passes removed\r\n```"},"comment":{"url":"https://api.github.com/repos/candycat1992/Unity_Shaders_Book/issues/comments/243659769","html_url":"https://github.com/candycat1992/Unity_Shaders_Book/issues/35#issuecomment-243659769","issue_url":"https://api.github.com/repos/candycat1992/Unity_Shaders_Book/issues/35","id":243659769,"user":{"login":"candycat1992","id":5907064,"avatar_url":"https://avatars.githubusercontent.com/u/5907064?v=3","gravatar_id":"","url":"https://api.github.com/users/candycat1992","html_url":"https://github.com/candycat1992","followers_url":"https://api.github.com/users/candycat1992/followers","following_url":"https://api.github.com/users/candycat1992/following{/other_user}","gists_url":"https://api.github.com/users/candycat1992/gists{/gist_id}","starred_url":"https://api.github.com/users/candycat1992/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/candycat1992/subscriptions","organizations_url":"https://api.github.com/users/candycat1992/orgs","repos_url":"https://api.github.com/users/candycat1992/repos","events_url":"https://api.github.com/users/candycat1992/events{/privacy}","received_events_url":"https://api.github.com/users/candycat1992/received_events","type":"User","site_admin":false},"created_at":"2016-08-31T05:08:16Z","updated_at":"2016-08-31T05:08:16Z","body":"这个错误很常见，我在5.6.2节提到过这个错误：\r\n\r\n![qq 20160831130456](https://cloud.githubusercontent.com/assets/5907064/18116585/9c750a2a-6f7b-11e6-82c1-7ea0bfae85a4.png)\r\n\r\n具体原因和解决方法你可以再读一下这一小节。其实解决方法很简单，就是保证声明的每个变量都被赋值了就好了。\r\n\r\n另外，这个错误是我书中的某个代码吗？我记得我都检查过，应该不会有这种错误才对啊。\r\n"}}
{"actor":{"display_login":"candycat1992"}}