Rotating and lerping to another material with custom shader.
HI, It all started when i wanted to make a moving skybox, And it turn out to be quite as simple as changing the _Rotation
variable in the standard "6 sided skybox" shader with RenderSettings.skybox.SetFloat("_Rotation", rot += skyRotSpeed * Time.deltaTime);
.
Then it got a little more complicated when i wanted after a 20s timer to change the skybox material to another one, and oh boy this wasn't as easy as just: RenderSettings.skybox.Lerp(curSky, nextSky, skyLerpVal * Time.deltaTime);
as you can see this line should lerp to the "nextMaterial" material but surprise... it doesn't, I don't know if this is actually the way to do it but what i do know is that i am not the only one around the internet who is facing this issue and Have't found a solution.
Fast forward two hours of looking around i found a work around which is using a custom shader ( Script down There ) and it actually worked, well semi worked. It worked for actually lerping to another material but presented an issue with it:
1) Now i am not a shader expert by any means but that shader doesn't have the _Rotation
variable which presented me the loss of the ability to rotate the skybox, I tried to copy the code from the standard "6 sided skybox" shader to this custom one but no success ( NOTE: I have absolutely no experience with working with/writing shaders ).
2) I might need to swap between more than just two skyboxs, my initial thought was to just have a list of materials and iterate through it and lerp from the current one to the next using the index, but as i said, the RenderSettings.skybox.Lerp(curSky, nextSky, skyLerpVal * Time.deltaTime);
method didn't really work so if there is a better solution to swap between more than two materials i would appreciate it.
Custom Shader:
Shader "Skybox/Blended" {
Properties {
_Tint ("Tint Color", Color) = (.5, .5, .5, .5)
_Blend ("Blend", Range(0.0,1.0)) = 0.5
_FrontTex ("Front (+Z)", 2D) = "white" {}
_BackTex ("Back (-Z)", 2D) = "white" {}
_LeftTex ("Left (+X)", 2D) = "white" {}
_RightTex ("Right (-X)", 2D) = "white" {}
_UpTex ("Up (+Y)", 2D) = "white" {}
_DownTex ("Down (-Y)", 2D) = "white" {}
_FrontTex2("2 Front (+Z)", 2D) = "white" {}
_BackTex2("2 Back (-Z)", 2D) = "white" {}
_LeftTex2("2 Left (+X)", 2D) = "white" {}
_RightTex2("2 Right (-X)", 2D) = "white" {}
_UpTex2("2 Up (+Y)", 2D) = "white" {}
_DownTex2("2 Down (-Y)", 2D) = "white" {}
}
SubShader {
Tags { "Queue" = "Background" }
Cull Off
Fog { Mode Off }
Lighting Off
Color [_Tint]
Pass {
SetTexture [_FrontTex] { combine texture }
SetTexture [_FrontTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
}
Pass {
SetTexture [_BackTex] { combine texture }
SetTexture [_BackTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
}
Pass {
SetTexture [_LeftTex] { combine texture }
SetTexture [_LeftTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
}
Pass {
SetTexture [_RightTex] { combine texture }
SetTexture [_RightTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
}
Pass {
SetTexture [_UpTex] { combine texture }
SetTexture [_UpTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
}
Pass {
SetTexture [_DownTex] { combine texture }
SetTexture [_DownTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous}
}
}
Fallback "Skybox/6 Sided", 1
}
Thank you in advance.
Oh and i will definitely use some exposure.
Your answer
Follow this Question
Related Questions
Skybox not correctly alpha blending with custom Shader 1 Answer
Change Material by equipping item 0 Answers
Materia Drag & Drop Bug 0 Answers
Accessing shader colors 1 Answer
Anyway to detect for missing material from Renderer component? 1 Answer