Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Before I say anything else: I'm using dual lightmaps, meaning I need to blend both a near and a far.

So I've been working on this for a while now, I have a whole day/night cycle set up for renderers and lighting, and everything is working fine and not process intensive.

The only problem I'm having is figuring out how I could blend two lightmaps together, I've figured out how to switch lightmaps, but the problem is that looks kind of abrupt and interrupts the experience.

I've done hours of research on this, tried all kinds of shaders, pixel by pixel blending, and everything else to no real avail. Pixel by pixel blending in C# turned out to be a bit process intensive for my liking, though I'm still working on cleaning it up and making it run more smoothly. Shaders looked promising, but I couldn't find a shader that could properly blend two lightmaps.

Does anyone have any leads on how I could accomplish this? I just need some sort of smooth transition between my daytime and nighttime lightmap. Perhaps I could overlay the two textures and use an alpha channel? Or something like that?

share|improve this question
    
If you have Pro, maybe you can render the two lightmap textures into a third, and then use this third texture as a lightmap? That should be just like pixel blending, but massively faster. –  Nevermind Feb 20 '13 at 5:39
    
I do have Pro. How would I go about rendering the two lightmap textures together? This was my main lead but I've been trying to figure out the code/process to accomplish it. –  Timothy Williams Feb 20 '13 at 6:17
    
Umm create a material that blends two textures, use Graphics.Blit() to render it? I've never done this, but looking in the manual, it should work. –  Nevermind Feb 20 '13 at 7:29
    
So create a new material that can blend two textures to an output, apply the Afar-1 and Bfar-1, then use the outgoing texture for the lightmap variable? –  Timothy Williams Feb 20 '13 at 22:59
    
Yeah, something like that. I'd test it, but I don't have access to Pro version at the moment. –  Nevermind Feb 21 '13 at 8:09

2 Answers 2

There is a skybox shader that blends between two sets of skybox textures. Think day and night cycle!

If you want to build or animate the skybox from script, use skyboxmaterial.SetFloat("_Blend", yourBlend) to change the blending; can also use SetTexture material functions to setup or change the textures.

Video tutorial about day/night cycle: http://www.youtube.com/watch?v=FTfv9JhkmIA

The example code goes as follows:

Shader "RenderFX/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 }
        SetTexture [_FrontTex2] { combine previous +- primary, previous * primary }
    }
    Pass {
        SetTexture [_BackTex] { combine texture }
        SetTexture [_BackTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
        SetTexture [_BackTex2] { combine previous +- primary, previous * primary }
    }
    Pass {
        SetTexture [_LeftTex] { combine texture }
        SetTexture [_LeftTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
        SetTexture [_LeftTex2] { combine previous +- primary, previous * primary }
    }
    Pass {
        SetTexture [_RightTex] { combine texture }
        SetTexture [_RightTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
        SetTexture [_RightTex2] { combine previous +- primary, previous * primary }
    }
    Pass {
        SetTexture [_UpTex] { combine texture }
        SetTexture [_UpTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
        SetTexture [_UpTex2] { combine previous +- primary, previous * primary }
    }
    Pass {
        SetTexture [_DownTex] { combine texture }
        SetTexture [_DownTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
        SetTexture [_DownTex2] { combine previous +- primary, previous * primary }
    }
}

Fallback "RenderFX/Skybox", 1
}
share|improve this answer
1  
The question asked about lightmaps, not skybox. Thanks for the link though, this looks like it'll be useful to me. –  jhocking Jun 29 '13 at 16:44

If you know how to switch, why not to go on with creating a number of transition lightmaps on the background thread, and then enable the transitions when the lightmaps are ready?

You can also have a look at an interesting asset on AssetStore: https://www.assetstore.unity3d.com/en/#!/content/5674

I guess it includes the lightmaps blending, although I don't know the way how.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.