日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

unity片元着色器中获取屏幕坐标_Unity踩坑笔记(持续更新)

發布時間:2024/10/6 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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.自動生成粒子好像粒子數大于16384就會出問題

16384 * 4 = 2 的 16次方, unity最多只能有65535個頂點。即索引值是uint的,本身的int類型很令人迷惑。create.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;可設置為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 中利用天空盒位置計算隨機數,然后通過乘以一個大數然后模一個數來獲取隨機星星,但是好像不可行吶,因為精度問題模出來之后星星老是會閃

原因:應該是因為天空盒精度達不到導致像素對應的天空盒坐標有微小變化最終的出來的隨機數也有微小變化導致閃爍。

Tsize=Rwidth/tan(fov/2) 因為減小了fov之后增加了天空盒精度之后改善了。

如上圖所示,假設紅色是第T幀的屏幕(假設屏幕5*5像素),藍色是第T+1幀的屏幕,則可以看到前一幀的紅點并不一定在后一幀中出現,所以根據位置算出來的隨機數是不一致的,導致閃爍現象

目前想到的解決方案:不要讓位置完全隨機,而是把整個天空盒分為512等份,然后fragment shader里面獲得的天空盒位置規則化到這512等份里面,這樣可以通過減少隨機精度的方案來減少位置的變化抖動。

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

解決方案:在頂點著色器的輸入輸出加入宏UNITY_INSTANCE_ID

9.Unity shader 改完之后要實際賦給材質用一下可能有些錯誤才能暴露出來

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.關于Skybox

粗略做了一下測試unity默認的Skybox應該是用的Sphere模型,然后當前攝像機下ModelMatrix大概放大了十幾萬倍。而且這個ModelMatrix是和裁剪平面的大小有關的。

14.build target android player is not supported

解決方案:把VS工程關掉重啟好像就可以了

15.Alpha 貼圖采樣的時候一定記得要是tex2Dlod().a, 不寫.a取不到正確的值

16.Vertex Shader 采樣貼圖需要SM3以上,最好用tex2Dlod而不是tex2D

17.2D Texture在Spherical mapping的時候會有一條縫隙

解決方案,用tex2Dlod采樣貼圖,防止mipmap插值采樣可以防止。

18.AssetImporter.GetAtPath 需要Assets開頭的相對路徑

19.2D Texture(從左到右六個面)轉cubemap size must power of two

20.surface shader里面取出來的vertex color和texcoord不對,轉成正常的vert frag就正常了

21.shader中定義常量定義在shader外面好像不生效,寫在shader里面就可以了

22.Unity 和UE4 FBX導入之后UV.v是相反的,需要flip一下才能一致

23.反射不要忘記設置BindingFlags

24.抽象函數的反射,反射函數要用抽象類型來獲取(反射函數參數是基本類型),然后反射調用的時候再用實際的對象去執行,不然可能反射參數會不對。

25.unity 沒有實例化的prefab獲取的collider bound是不對的

26.unity在PC float half fixed都是32位,移動端half16位,可能會導致精度問題。

總結

以上是生活随笔為你收集整理的unity片元着色器中获取屏幕坐标_Unity踩坑笔记(持续更新)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。