- Home /
Shader Blending Question
Scroll to bottom for quick version!
I know nothing about shaders so sorry if some of this doesn't make sense.
The BlendedSky shader lets you blend between 2 skyboxes. I changed it to have 4, for night, dawn, day and dusk.
In the SubShader section in a Pass{} thing there are lines of code that combine the original 2 textures for the transition
SetTexture [_FrontTex] { combine texture }
SetTexture [_FrontTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
SetTexture [_FrontTex2] { combine previous +- primary, previous * primary }
I know nothing, so I just repeated that replacing the names _FrontTex and the numbers to the ones I added in myself. It obviously does not work.
_Blend ("Blend", Range(0.0,1.0)) = 0.5
That is at the beginning of the code, and I believe it is the slider. Does this need to be modified in any way? It is included in the SetTexture things
How would I go about having it gradually blend from the first to second to the third and finally the last one? I already have code written to control the blending process in-game, so I don't need any help there.
Quick Version
Is it possible to blend between 4 textures in a shader? If so, how?
Answer by ScroodgeM · Jul 26, 2012 at 01:13 AM
in perfomance reason it's better use blending between 2 textures
so attach tex1 to slot1 and tex2 to slot2, then blend from 0 to 1
then attach tex3 to slot1 and blend from 1 to 0
then attach tex4 to slot2 and blend from 0 to 1 again
etc
i believe that you needn't blending between more then 2 textures at once?
anyway, you can try to make such blending
http://docs.unity3d.com/Documentation/Components/SL-SetTexture.html
if you still really need all-in-one shader, i can write one for you. but do you really need it? 8)
I was doing this for a skybox, so I wanted to have the yellow/reddish sky for when the sun is setting and rising. I have found my own work around for it, so you do not need to write a shader for me. Thanks for the offer though!
may be it's better to post your solution here to close the question? 8)
Well it's not really a solution for this, but it's kind of the same thing. I have my time script set up so it knows when the time is between certain points, and I have colored fog blend colors depending on the time. It does give the scene a nice look.