Scatter Sky Colorization
by Tim Dix (Raverix) · 08/08/2010 (5:40 pm) · 9 comments

Overview
This resource modifies the Scatter Sky to have more color rendering options. The changes are 100% backwards compatible, and offer a great deal more flexibility with sky color options.I created it because I have a bunch of sky boxes which are basically the same as scatter sky, just in various other hues. Now, I can drop all of my skyboxes for this.
Alright, the real core of this change is a very simple modification to the scatterSkyV.hlsl. It's a bit simplistic, but it gets the job done for me. Feel free to expand to fit your needs. First, it desaturates the existing ScatterSky, and then it colorizes it based on the color you specify.
Code
scatterSkyV.hlsl
Add the following above the function main://Raverix - SSC -->
float3 desaturate(const float3 color, const float desaturation) {
const float3 gray_conv = float3 (0.30, 0.59, 0.11);
return lerp(color, dot(gray_conv , color), desaturation);
}
uniform float4 colorize;
// <-- Raverix - SSCAdd the following before return out;
//Raverix - SSC --> #ifdef USE_COLORIZE Out.rayleighColor.rgb = desaturate(Out.rayleighColor.rgb, 1) * colorize.a; Out.rayleighColor.r *= colorize.r; Out.rayleighColor.g *= colorize.g; Out.rayleighColor.b *= colorize.b; #endif // <-- Raverix - SSC
The rest of the code just handles passing colorize to the shader.
scatterSky.h
Place this after all of the GFXShaderConstHandle declarations://Raverix - SSC --> F32 mColorizeAmt; ColorF mColorize; GFXShaderConstHandle *mColorizeSC; // <-- Raverix - SSC
scatterSky.cpp
ScatterSky::ScatterSky() - Add the following anywhere://Raverix - SSC --> mColorizeAmt = 0; mColorize.set(0,0,0); // <-- Raverix - SSC
ScatterSky::initPersistFields() - I chose to add the following fields within the ScatterSky group, but it could really go anywhere:
//Raverix - SSC -->
addField( "colorizeAmount", TypeF32, Offset( mColorizeAmt, ScatterSky ),
"Controls how much the the alpha component of colorize brigthens the sky. Setting to 0 returns default behavior." );
addField( "colorize", TypeColorF, Offset( mColorize, ScatterSky ),
"Tints the sky the color specified, the alpha controls the brigthness. The brightness is multipled by the value of colorizeAmt." );
// <-- Raverix - SSCScatterSky::packUpdate() - Find stream->write( mFogScale ); and add below:
//Raverix - SSC -->
stream->write( mColorizeAmt );
stream->write( mColorize );
// <-- Raverix - SSCScatterSky::unpackUpdate() - find stream->read( &mFogScale );
and add below:
//Raverix - SSC -->
F32 colorizeAmt;
stream->read( &colorizeAmt );
if(mColorizeAmt != colorizeAmt) {
mColorizeAmt = colorizeAmt;
mShader = NULL; //forces shader refresh
}
stream->read( &mColorize );
// <-- Raverix - SSCScatterSky::_initShader() - comment out mShader = shaderData->getShader();, and add below:
//Raverix - SSC -->
Vector<GFXShaderMacro> macros;
if ( mColorizeAmt )
macros.push_back( GFXShaderMacro( "USE_COLORIZE" ) );
mShader = shaderData->getShader( macros );
// <-- Raverix - SSCScatterSky::_initShader() - Add before the function returns:
//Raverix - SSC --> mColorizeSC = mShader->getShaderConstHandle( "$colorize" ); // <-- Raverix - SSC
ScatterSky::_render() - Add after the rest of the mShaderConsts->setSafe calls:
//Raverix - SSC --> mShaderConsts->setSafe( mColorizeSC, mColorize*mColorizeAmt ); // <-- Raverix - SSC
Usage
Obviously, you need to have a ScatterSky in your level...- colorizeAmt - Controls how much the the alpha component of colorize brigthens the sky. Setting to 0 returns default behavior.
- colorize - Tints the sky the color specified, the alpha controls the brigthness. The brightness is multipled by the value of colorizeAmt.
I've found that I leave colorizeAmt at 10, and then use the alpha component of the colorize the sky and get me all the different color variations.
Results










Enjoy!

#2
08/08/2010 (8:43 pm)
Wow, that's some colours! Be good for alien worlds and stuff. :)
#3
08/08/2010 (9:08 pm)
Pssh, blue skies are so overdone.
#4
08/09/2010 (6:28 pm)
nice code ty for share:)
#5
08/10/2010 (10:17 pm)
Very nice job
#6
08/10/2010 (10:21 pm)
What a great resource.
#7
08/11/2010 (5:56 am)
I really liked the color choices there. I kind of feel like someone that is an artist at heart picked them out.
#8
02/26/2011 (1:07 am)
Wow! This is fantastic! Thank you!
#9
specially sunscale and ambient scale.
to make it realistic, level designer have to adjust sunscale and ambient scale too.that is ok for one time adjustment.
but if any programmer try to utilize it to create a dynamic environment from script he have no way to utilize it to create a realistic environment without looking into visual output.
so i was thinking if anyway this color changing also will automatically adjust sunscale and ambient scale to make it more realistic for script side work.
i know current implementation gives more control.
so a checkbox with title "adjust with sun and ambient scale" will make them both exists.
no shader knowledge.so no idea how to make it happen
01/10/2013 (7:15 pm)
changing sky color does not affect other environment's color.specially sunscale and ambient scale.
to make it realistic, level designer have to adjust sunscale and ambient scale too.that is ok for one time adjustment.
but if any programmer try to utilize it to create a dynamic environment from script he have no way to utilize it to create a realistic environment without looking into visual output.
so i was thinking if anyway this color changing also will automatically adjust sunscale and ambient scale to make it more realistic for script side work.
i know current implementation gives more control.
so a checkbox with title "adjust with sun and ambient scale" will make them both exists.
no shader knowledge.so no idea how to make it happen

Associate Michael Hall
Distracted...
EDIT: beware giving the colorblind guy color controls :D