使用cube进行纹理采样,可以很方便的预览全景图,可以用立方体去显示全景图,而不必非得用球
甚至还可以用更复杂的网格去贴全景图,只要保证网格的形状和全景图里的内容能对应上就行,比如激光扫的房间的模型,可以直接贴房间的全景图
代码很简单,其中_Point是拍摄全景图的点位,可以先见个Cube,然后挂上这个shader,修改_Point看看效果,很容易理解的,(需要将Cube的缩放改大点,如(200,200,200)太小可能有畸变)
Shader "Unlit/SimpleCube" { Properties { _CubeMap("CubeMap", CUBE) = "" {} _Point("Point",VECTOR) = (0,0,0,0) } SubShader { Tags { "Queue" = "Transparent" "RenderType" = "Transparent" } Blend SrcAlpha OneMinusSrcAlpha LOD 100 Cull Off Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float3 normal : NORMAL; }; struct v2f { float4 vertex : SV_POSITION; float4 vertexLocal : TEXCOORD1; }; samplerCUBE _CubeMap; float4 _Point; v2f vert(appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.vertexLocal = v.vertex; return o; } fixed4 frag(v2f i) : SV_Target { fixed4 col = texCUBE(_CubeMap, normalize(mul(UNITY_MATRIX_M,i.vertexLocal.xyz) - mul(UNITY_MATRIX_M,_Point.xyz))); return col; } ENDCG } } }
标签:cube,Point,CubeMap,vertex,shader,float4,Unity,v2f,全景图 From: https://www.cnblogs.com/Jason-c/p/16993680.html