2017-09-13 90 views
0

我想为360图像做一个自定义天空盒这至少有2个纹理与交叉淡入淡出,我需要它来响应旋转值像Unity Skybox。我只需要相同的滑块,但我没有得到任何好运,我在着色器方面全新。统一自定义天空盒像Unity天空盒

这里是我的代码至今

Shader "Custom/fundido" 
{ 
    Properties { 

    _Blend ("Blend", Range (0, 1)) = 0.0 
    _Rotation ("Rotation", Range(0, 360)) = 0 
    _BaseTexture ("Cubemap (HDR)", Cube) = "grey" {} 
    _OverlayTexture ("Cubemap2 (HDR)", Cube) = "grey" {} 

} 

SubShader { 

Tags { "Queue"="Background" "RenderType"="Background" 
"PreviewType"="Skybox" } 

Pass { 

     SetTexture[_BaseTexture] 
     SetTexture[_OverlayTexture] { 
     ConstantColor (0,0,0, [_Blend]) 
     combine texture Lerp(constant) previous 
     } 
    } 
} 
} 

的_Blend作品完美的淡入淡出我只需要添加旋转听众。

非常感谢!

+0

有此链接一看:https://forum.unity.com/threads/rotate-a-skybox.130639/,但不是改变通过脚本旋转,你会改变它您的滑块_旋转属性。 –

+0

Hi Tengku! 感谢您如此快速。我尝试过这个帖子,两个相机的窍门有些修改,但是当我将陀螺仪控制附加到主相机时,给我一些轴奇怪的动作。 正如你所说最好的方法将使用我的滑块,但它没有连接到没有,因为我不知道如何将它附加到着色器。这就是我想要做的,将我的滑块添加到交叉淡入淡出处。 Thankas :) –

+0

嗨,我刚到家。我设法创建着色器,它适用于我,经过一些清理后,我会发布一个答案。 –

回答

1

这是着色器。您可以通过脚本来改变白天的循环。 https://docs.unity3d.com/ScriptReference/Material.SetFloat.html

Shader "TFTM/Skybox2CubeBlend" { 
Properties { 
    _Blend ("Blend", Range (0, 1)) = 0.0 
    _Rotation ("Rotation", Range(0, 360)) = 0 
    _Tex ("Cubemap (HDR)", Cube) = "grey" {} 
    _OverlayTex ("CubemapOverlay (HDR)", Cube) = "grey" {} 
} 

SubShader { 
    Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" } 
    Cull Off ZWrite Off 

    Pass { 

     CGPROGRAM 
     #pragma vertex vert 
     #pragma fragment frag 
     #pragma target 2.0 

     #include "UnityCG.cginc" 

     samplerCUBE _Tex; 
     samplerCUBE _OverlayTex; 
     half4 _Tex_HDR; 
     half4 _Tint; 
     half _Exposure; 
     float _Rotation; 
     float _Blend; 

     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; 
     }; 

     struct v2f { 
      float4 vertex : SV_POSITION; 
      float3 texcoord : TEXCOORD0; 
     }; 

     v2f vert (appdata_t v) 
     { 
      v2f 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); 
      half4 tex2 = texCUBE (_OverlayTex, i.texcoord); 
      float4 env = lerp(tex, tex2, _Blend); 

      half3 c = DecodeHDR (env, _Tex_HDR); 

      return half4(c, 1); 
     } 
     ENDCG 
    } 
} 
Fallback Off 

} 
+0

哇!非常感谢你这么多!你知道一个好的文档地方来开始学习着色器吗?我想了解他们未来的问题。并且非常感谢:D –

+0

我个人非常喜欢Alan Zucconi着色书。 http://www.alanzucconi.com/books/ –

+0

感谢东姑希望我能回报这份青睐。 :D –