可用Unity官方材质:skybox下的Cubemap:
但是,有些面没有渲染上:
原因在于官方Shader里面的Cull off,将其改为Cull back就好了,或者ZWrite Off改为ZWrite On。附上代码:
Shader "Custom/MyCubemap"
{Properties{_Tint("Tint Color", Color) = (.5, .5, .5, .5)[Gamma] _Exposure("Exposure", Range(0, 8)) = 1.0_Rotation("Rotation", Range(0, 360)) = 0[NoScaleOffset] _Tex("Cubemap (HDR)", Cube) = "grey" {}}SubShader{Tags { "Queue" = "Background" "RenderType" = "Background" "PreviewType" = "Skybox" }Cull Back ZWrite OffPass {CGPROGRAM#pragma vertex vert#pragma fragment frag#pragma target 2.0#include "UnityCG.cginc"samplerCUBE _Tex;half4 _Tex_HDR;half4 _Tint;half _Exposure;float _Rotation;float3 RotateAroundYInDegrees(float3 vertex, float degrees){float alpha = degrees * UNITY_PI / 180.0;float sina, cosa;sincos(alpha, sina, cosa);float2x2 m = float2x2(cosa, -sina, sina, cosa);return float3(mul(m, vertex.xz), vertex.y).xzy;}struct appdata_t {float4 vertex : POSITION;UNITY_VERTEX_INPUT_INSTANCE_ID};struct v2f {float4 vertex : SV_POSITION;float3 texcoord : TEXCOORD0;UNITY_VERTEX_OUTPUT_STEREO};v2f vert(appdata_t v){v2f o;UNITY_SETUP_INSTANCE_ID(v);UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);float3 rotated = RotateAroundYInDegrees(v.vertex, _Rotation);o.vertex = UnityObjectToClipPos(rotated);o.texcoord = v.vertex.xyz;return o;}fixed4 frag(v2f i) : SV_Target{half4 tex = texCUBE(_Tex, i.texcoord);half3 c = DecodeHDR(tex, _Tex_HDR);c = c * _Tint.rgb * unity_ColorSpaceDouble.rgb;c *= _Exposure;return half4(c, 1);}ENDCG}}Fallback Off}
如果感觉有点糊,就调高Cubemap的面数,然后重新导入一遍图片就行了,一定要重新导入一遍图片,具体解释看那个感叹号里面的:
关于Unity官方的Shader,有一个很好的GitHub供参考:Unity Built in Shaders。