Jump to content
XCOMUFO & Xenocide

Geoscape Shader


dteviot

Recommended Posts

A couple of screenshots to show the problem with Daylight and bump mapping on the Geoscape.

Image 03 is day/night only, no bumping.

Image 02, is day/night with bump logic separated. (note that terrain gets dark because bump logic regards earth as a giant "bump".)

Image 01 is the current shader, which incorrectly combines bump and nighttime. Note that there are lights showing in the dark daylight areas.

01_RKsBumpMap.JPG

02_BumpAndNightDecoupled.JPG

03_BumpTurnedOff.JPG

Any ideas on how to fix would be appreciated. I have vague idea of only using east/west information for bump map, and ignore north/south.

Edited by dteviot
Link to comment
Share on other sites

Mhhh one may argue that the calculation should be done from transformed light direction and that night lights get started before it is completely dark :) ... however, what you have to do is use the unmodified (undistorted normal) to do the blending ( TextureDay * ( 1 - S ) + TextureN * S ). So that means that the S have to be calculated before doing Normal = RealNormal * BumpTexture(x,y) :) --- Not actual code but pseudo code ---

 

Greetings

Red Knight

Link to comment
Share on other sites

Red Knight, here's my Geoscape shader maths, please explain what I'm doing wrong.

 

We can get the day/night by taking the dot product of the earth's normal (with no bump map) and the sun's direction.

So, a positive value means daylight, and a negative value means night.

 

float sunlight = dot(Input.TangentToWorld[2], Input.LightDirection);

 

However, this gives us a light that's maximum at the "sun at midday" position, and fading as we move to the day/night boundry (terminator.)

What we want is a light that quickly brightens from night, and then remains constant at max.

(we also want a small amount of light all the time, so that we can see the underlying map, even at night.)

 

float ambient = clamp(sunlight * 3, 0.25, 1.0)

 

Night is essentially the inverse of sunlight, except that lights start going on slightly before nightfall occurs, and they turn off completely.

 

float night = clamp((0.2 - sunlight) * 3, 0.0, 1.0)

 

Putting this together, this gives the image I showed with day/night, but no bump.

 

Output.Color = (diffuseTexture * ambient) + (nightTexture * night);

 

When I add mix bump with ambient, I get the image with day/night and bump (with it looking like the sun never reaches europe)

 

float bump = max(dot(normalFromMap, Input.LightDirection), 0)

 

Output.Color = (diffuseTexture * ambient * bump) + (nightTexture * night);

Link to comment
Share on other sites

  • 5 months later...

I may have finally found a solution to bump mapping the earth.

Shader X6, Chapter 2.1 "The care and feeding of normal vectors", shows how to apply bump maps to spheres.

Now if I can just figure out the Partial Differential Matrices that the chapter is full of. :(

Link to comment
Share on other sites

×
×
  • Create New...