0

Ok I have looked at all relevant questions including RenderSettings Skybox lerp - I am just trying to lerp between SHADERS or materials, specifically the one assigned to RenderSettings.skybox

My reason for lerping the actual shader is I have my skybox set to a custom rotating skybox shader that uses cube maps. I tried to lerp the cube maps assigned to this material but did not work. Here is the existing rotating skybox shader:

// Made with Amplify Shader Editor
// Available at the Unity Asset Store - http://u3d.as/y3X 
Shader "Skybox/Cubemap Extended"
{
    Properties
    {
        [Gamma][Header(Cubemap)]_TintColor("Tint Color", Color) = (0.5,0.5,0.5,1)
        _Exposure("Exposure", Range( 0 , 8)) = 1
        [NoScaleOffset]_Tex("Cubemap (HDR)", CUBE) = "black" {}
        [Header(Rotation)][Toggle(_ENABLEROTATION_ON)] _EnableRotation("Enable Rotation", Float) = 0
        [IntRange]_Rotation("Rotation", Range( 0 , 360)) = 0
        _RotationSpeed("Rotation Speed", Float) = 1
        [Header(Fog)][Toggle(_ENABLEFOG_ON)] _EnableFog("Enable Fog", Float) = 0
        _FogHeight("Fog Height", Range( 0 , 1)) = 1
        _FogSmoothness("Fog Smoothness", Range( 0.01 , 1)) = 0.01
        _FogFill("Fog Fill", Range( 0 , 1)) = 0.5
        [HideInInspector]_Tex_HDR("DecodeInstructions", Vector) = (0,0,0,0)
        [HideInInspector] __dirty( "", Int ) = 1

    }

    SubShader
    {
        Tags{ "RenderType" = "Background"  "Queue" = "Background+0" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True" "IsEmissive" = "true"  "PreviewType"="Skybox" }
        LOD 100
        Cull Off
        ZWrite Off
        CGPROGRAM
        #include "UnityShaderVariables.cginc"
        #pragma target 2.0
        #pragma shader_feature _ENABLEFOG_ON
        #pragma shader_feature _ENABLEROTATION_ON
        #pragma surface surf Unlit keepalpha noshadow noambient novertexlights nolightmap  nodynlightmap nodirlightmap nofog nometa noforwardadd vertex:vertexDataFunc 
        struct Input
        {
            float3 vertexToFrag774;
            float3 worldPos;
        };

        uniform half4 _Tex_HDR;
        uniform samplerCUBE _Tex;
        uniform half _Rotation;
        uniform fixed _RotationSpeed;
        uniform fixed4 _TintColor;
        uniform half _Exposure;
        uniform fixed _FogHeight;
        uniform fixed _FogSmoothness;
        uniform fixed _FogFill;


        inline half3 DecodeHDR1189( half4 Data )
        {
            return DecodeHDR(Data, _Tex_HDR);
        }      

        void vertexDataFunc( inout appdata_full v, out Input o )
        {
            UNITY_INITIALIZE_OUTPUT( Input, o );
            float3 ase_worldPos = mul( unity_ObjectToWorld, v.vertex );
            float lerpResult268 = lerp( 1.0 , ( unity_OrthoParams.y / unity_OrthoParams.x ) , unity_OrthoParams.w);
            fixed CAMERA_MODE300 = lerpResult268;
            float3 appendResult1129 = (float3(ase_worldPos.x , ( ase_worldPos.y * CAMERA_MODE300 ) , ase_worldPos.z));
            float3 normalizeResult1130 = normalize( appendResult1129 );
            float mulTime701 = _Time.y * 1;
            float3 appendResult56 = (float3(cos( radians( ( _Rotation + ( mulTime701 * _RotationSpeed ) ) ) ) , 0.0 , ( sin( radians( ( _Rotation + ( mulTime701 * _RotationSpeed ) ) ) ) * -1.0 )));
            float3 appendResult266 = (float3(0.0 , CAMERA_MODE300 , 0.0));
            float3 appendResult58 = (float3(sin( radians( ( _Rotation + ( mulTime701 * _RotationSpeed ) ) ) ) , 0.0 , cos( radians( ( _Rotation + ( mulTime701 * _RotationSpeed ) ) ) )));
            float3 normalizeResult247 = normalize( ase_worldPos );
            #ifdef _ENABLEROTATION_ON
                float3 staticSwitch1164 = mul( float3x3(appendResult56, appendResult266, appendResult58), normalizeResult247 );
            #else
                float3 staticSwitch1164 = normalizeResult1130;
            #endif
            o.vertexToFrag774 = staticSwitch1164;
        }

        inline fixed4 LightingUnlit( SurfaceOutput s, half3 lightDir, half atten )
        {
            return fixed4 ( 0, 0, 0, s.Alpha );
        }

        void surf( Input i , inout SurfaceOutput o )
        {
            half4 Data1189 = texCUBE( _Tex, i.vertexToFrag774 );
            half3 localDecodeHDR1189 = DecodeHDR1189( Data1189 );
            fixed4 CUBEMAP222 = ( float4( localDecodeHDR1189 , 0.0 ) * unity_ColorSpaceDouble * _TintColor * _Exposure );
            float3 ase_worldPos = i.worldPos;
            float3 normalizeResult319 = normalize( ase_worldPos );
            float lerpResult678 = lerp( saturate( pow( (0.0 + (abs( normalizeResult319.y ) - 0.0) * (1.0 - 0.0) / (_FogHeight - 0.0)) , ( 1.0 - _FogSmoothness ) ) ) , 0.0 , _FogFill);
            fixed FOG_MASK359 = lerpResult678;
            float4 lerpResult317 = lerp( unity_FogColor , CUBEMAP222 , FOG_MASK359);
            #ifdef _ENABLEFOG_ON
                float4 staticSwitch1179 = lerpResult317;
            #else
                float4 staticSwitch1179 = CUBEMAP222;
            #endif
            o.Emission = staticSwitch1179.rgb;
            o.Alpha = 1;
        }

        ENDCG
    }
}

I need to lerp to a new Cubemap as this shader's texture. Since I cant do this directly I tried this:

RenderSettings.skybox.Lerp(RenderSettings.skybox, blendedSkybox, 3f);

in my Update() method, but this did nothing. I am new to shaders - how can I lerp between these cube maps or LERP the RenderSettings skybox material?

I don't want to use a blend shader because again, this existing shader rotates and the blended ones do not.

float t = 0f;


    // Update is called once per frame
    void Update () {

        //if (Input.GetKeyDown("return"))
        //{

        //    BlendBetweenSkyboxes(skyboxes[0], skyboxes[1]);
        //}

        RenderSettings.skybox.Lerp(overallSkybox, blendedSkybox, t);

        // .. and increase the t interpolater
        t += 0.1f * Time.deltaTime;

        // now check if the interpolator has reached 1.0
        // and swap maximum and minimum so game object moves
        // in the opposite direction.
        if (t > 1.0f)
        {
            print("done");
        }
blue
  • 7,175
  • 16
  • 81
  • 179
  • Well the third parameter of `Lerp` is not "how long you want it to take?" but "what percentage?" So a value of `3` gets clamped to the range `[0,1]` and the end result is an immediate change. Assuming, of course, that the change you want to see is even affected by the call to `Lerp`, which given the rest of your question, it might not be. – Draco18s no longer trusts SE Jul 16 '18 at 20:13
  • *`Assuming that the change you want to see is even affected by the call to Lerp [...] it might not be.`* Materials and shaders are an "A or B" type setting. You can't have half of one and half of the other just by throwing a 0.5 at the system. – Draco18s no longer trusts SE Jul 17 '18 at 03:56
  • Ok. So since that is the case, what do you suggest? I need to achieve this effect – blue Jul 17 '18 at 04:29
  • I don't know. I have never messed with a system like this (I did not know that `RenderSettings.skybox.Lerp` was even a thing). Aside from creating a shader that does *both desired things* and lerping the *material values*, I don't see an alternative. – Draco18s no longer trusts SE Jul 17 '18 at 14:16
  • Ok - do you know how to make any shader/skybox rotate? I have a solution if you have the code snippet that would do that – blue Jul 17 '18 at 17:31

0 Answers0