Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Day/Night Cycle with shaders  (Read 1644 times)

0 Members and 1 Guest are viewing this topic.

stulleman

  • Newbie
  • *
  • Posts: 12
    • View Profile
Day/Night Cycle with shaders
« on: February 15, 2015, 09:49:11 pm »
Hello Forum!

I'm not sure if my question fits in here but I give it a try anyway, since I don't know any other forum where I could ask this. If you know any better forum for this specific question, please let me know.

I have my basic light propagation done so now I wanted to move on to day/night Cycles. Here (https://www.seedofandromeda.com/blogs/29-fast-flood-fill-lighting-in-a-blocky-voxel-game-pt-1) and here (https://www.seedofandromeda.com/blogs/30-fast-flood-fill-lighting-in-a-blocky-voxel-game-pt-2) I've got the idea for my solution.

I'm using the upper four bits (XXXX0000) of the Color class for my sun value (0-15) and the lower four bits for the torch value of each vertex.

I think this is the only way to pass arguments for each vertex to a shader, is it? (Vertex Attributes aren't supported by SFML?)

So because of this I'm storing both values (sun + torch) in the color attribute of a vertex.
I think my problem now is that a the vertex shader uses color values from 0-1 for r,g,b.
So I can't extract the values for sun and torches anymore. Is that right?

I'm just getting a black screen with this:

uniform float sunIntensity;

uniform float sunIntensity;

void main() {

        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
        gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
       
        int torchLight = (int)gl_Color.x & 0xF;
        int sunLight = ((int)gl_Color.x >> 4) & 0xF;
        gl_FrontColor = vec4(torchLight, torchLight, torchLight, 1.0) + vec4(sunLight, sunLight, sunLight, 1.0) * sunIntensity;