5

I have been developing an application that needs to render a procedural sky, what I mean by this is that the sky has a day night cycle that changes depending on what time it is within the simulation.

I have seen a method somewhere in the past where they have a colormap sush as this: enter image description hereenter image description here

Now depending on some variable, such as time, somehow the code scans over the image and uses a range of colors for the texture of the sky. Also during sunrise / sunset the code will scan to a yellow,orange,red color as on the right.

I'm not sure what this is called but I think that it is what I'm after. I would love if anyone would show me or point me to an example of using this technique with opengl and C++.

On a side note my skybox is not your average shape its more of a sky-right-angle as below enter image description here

As you can see there is no top to the sky-right-angle it is only the two blue sides that you see that will have the sky rendered (Black is the BG). I was wondering if there was any way that I could render a procedural/dynamic night-day sky on these two plains (without the seam being noticeable between them also) and as a side question also have it so the top of the plains fade out to alpha no matter it its night or day

Any explanation/example on how to scan a colormap then set it as a texture in OpenGL / C++ is greatly appreciated.

xyz
  • 396
  • 3
  • 10
  • 2
    To the one who voted for close: This is actually a interesting question and neither off topic nor unclear. It's just a difficult topic. Unfortunately I have to prepare a talk right now, otherwise I'd go through the lengths of explaining multilayered sky gradient composition (which is what this texture is to be used for). – datenwolf Jun 20 '12 at 19:27
  • 1
    @datenwolf Maybe you could come by this topic again in a few days. I'm sure there are others like me who'd appreciate a well-educated answer. – s3rius Jun 20 '12 at 21:12

1 Answers1

1

Download the last project(Special Effects) in this url http://golabistudio.com/siamak/portfolio.html
The c++ source is not available but the shader source is there.
What you need to do is pass 2 textures to your shader(while rendering the plane). the first texture is your standard skybox texture. the second texture is your day/night cycle texture. at it's simplest it can be a wide gradient texture of height 1, going from blue to dark. with this second texture passed to your shader you can pick-up one pixel out of it at position of x=time and add the color to your diffuse texture(the first texture).

The next step is having the sunrise. Again at it's simplest to do this, you have to create a texture of width 2 with one side the sunrise pixels horizontally and the another the night gradient:(enlarged in width) https://i.stack.imgur.com/y8LNI.png

Now having your incoming uv coordinate for the diffuse texture(the first skybox texture) you take the following

  float2 uvpos;
  uvpos.y = IN.uv.y;//the position same as skybox texture
  uvpos.x = 0;//a sample from first horizontal pixel
  float4 colour1 = tex2D( gradientTexture, uvpos);
  uvpos.x = 0.5;//a sample from second horizontal pixel
  float4 colour2 = tex2D( gradientTexture, uvpos);

  float4 skycolor = lerp(colour1 , colour2, (your day time));
  skycolor.xyz += tex2D(skyTexture, IN.uv).xyz;

It's very simple implementation, but should get you going i think.