unity片元着色器中获取屏幕坐标_Unity踩坑笔记(持续更新)
1.error CS0104: 'MinAttribute' is an ambiguous reference between 'UnityEngine.Rendering.PostProcessing.MinAttribute' and 'UnityEngine.MinAttribute'
Solution:using MinAttribute = UnityEngine.PostProcessing.MinAttribute;
2.自動(dòng)生成粒子好像粒子數(shù)大于16384就會(huì)出問題
16384 * 4 = 2 的 16次方, unity最多只能有65535個(gè)頂點(diǎn)。即索引值是uint的,本身的int類型很令人迷惑。create.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;可設(shè)置為uint32
3.shift alt enter vs enter full screen
4.Unity sky box render order appears quite bugged. Shader says queue is background, but it is actually rendering as the last thing in the Geometry queue.
5.unity can't add script behaviour assemblyinfo. the script needs to derive from monobehaviour
一種可能是沒有繼承monobehaviour 或者腳本名字和類名不一致
6.fragment shader 中利用天空盒位置計(jì)算隨機(jī)數(shù),然后通過乘以一個(gè)大數(shù)然后模一個(gè)數(shù)來獲取隨機(jī)星星,但是好像不可行吶,因?yàn)榫葐栴}模出來之后星星老是會(huì)閃
原因:應(yīng)該是因?yàn)樘炜蘸芯冗_(dá)不到導(dǎo)致像素對應(yīng)的天空盒坐標(biāo)有微小變化最終的出來的隨機(jī)數(shù)也有微小變化導(dǎo)致閃爍。
Tsize=Rwidth/tan(fov/2) 因?yàn)闇p小了fov之后增加了天空盒精度之后改善了。
如上圖所示,假設(shè)紅色是第T幀的屏幕(假設(shè)屏幕5*5像素),藍(lán)色是第T+1幀的屏幕,則可以看到前一幀的紅點(diǎn)并不一定在后一幀中出現(xiàn),所以根據(jù)位置算出來的隨機(jī)數(shù)是不一致的,導(dǎo)致閃爍現(xiàn)象
目前想到的解決方案:不要讓位置完全隨機(jī),而是把整個(gè)天空盒分為512等份,然后fragment shader里面獲得的天空盒位置規(guī)則化到這512等份里面,這樣可以通過減少隨機(jī)精度的方案來減少位置的變化抖動(dòng)。
7.Shader.setGlobal不生效問題
According to the reference, Shader.setGlobal functions would only work on variables that are not exposed as a property in the property block. So what you have to do is remove the _test("_test",Float) = 0.0 line to make it work. Be sure to remake a new material, since unity will save the properties you have set on a material even when you are using a shader that doesn't have that property.
8.UNITY_TRANSFER_INSTANCE_ID invalid subscript instanceID
解決方案:在頂點(diǎn)著色器的輸入輸出加入宏UNITY_INSTANCE_ID
9.Unity shader 改完之后要實(shí)際賦給材質(zhì)用一下可能有些錯(cuò)誤才能暴露出來
10.shader_feature & multi_compile
shader_feature is very similar to multi_compile. The only difference is that Unity does not include unused variants of shader_feature shaders in the final build. For this reason, you should use shader_feature for keywords that are set from the Materials, while multi_compile is better for keywords that are set from code globally.
The main disadvantage of shader_feature and multi_compile is that all keywords defined in them contribute towards Unity’s global keyword count limit (256 global keywords, plus 64 local keywords). To avoid this issue, you can use different shader variant directives: shader_feature_local and multi_compile_local.
- shader_feature_local: similar to shader_feature, but enumerated keywords are local.
- multi_compile_local: similar to multi_compile, but enumerated keywords are local.
11.Difference between UnityObjectToWorldDir and UnityObjectToWorldNormal
WorldDir is applying the rotation from the transform matrix.
WorldNormal is apply the rotation from the inverse transpose matrix.
12.圖片邊界有條縫
(把圖片排布方式由repeat改為clamp)
13.關(guān)于Skybox
粗略做了一下測試unity默認(rèn)的Skybox應(yīng)該是用的Sphere模型,然后當(dāng)前攝像機(jī)下ModelMatrix大概放大了十幾萬倍。而且這個(gè)ModelMatrix是和裁剪平面的大小有關(guān)的。
14.build target android player is not supported
解決方案:把VS工程關(guān)掉重啟好像就可以了
15.Alpha 貼圖采樣的時(shí)候一定記得要是tex2Dlod().a, 不寫.a取不到正確的值
16.Vertex Shader 采樣貼圖需要SM3以上,最好用tex2Dlod而不是tex2D
17.2D Texture在Spherical mapping的時(shí)候會(huì)有一條縫隙
解決方案,用tex2Dlod采樣貼圖,防止mipmap插值采樣可以防止。
18.AssetImporter.GetAtPath 需要Assets開頭的相對路徑
19.2D Texture(從左到右六個(gè)面)轉(zhuǎn)cubemap size must power of two
20.surface shader里面取出來的vertex color和texcoord不對,轉(zhuǎn)成正常的vert frag就正常了
21.shader中定義常量定義在shader外面好像不生效,寫在shader里面就可以了
22.Unity 和UE4 FBX導(dǎo)入之后UV.v是相反的,需要flip一下才能一致
23.反射不要忘記設(shè)置BindingFlags
24.抽象函數(shù)的反射,反射函數(shù)要用抽象類型來獲取(反射函數(shù)參數(shù)是基本類型),然后反射調(diào)用的時(shí)候再用實(shí)際的對象去執(zhí)行,不然可能反射參數(shù)會(huì)不對。
25.unity 沒有實(shí)例化的prefab獲取的collider bound是不對的
26.unity在PC float half fixed都是32位,移動(dòng)端half16位,可能會(huì)導(dǎo)致精度問題。
總結(jié)
以上是生活随笔為你收集整理的unity片元着色器中获取屏幕坐标_Unity踩坑笔记(持续更新)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: gitclone 一个tag的地址_一个
- 下一篇: python for循环连续输入五个成绩