Sunshine light

Hi,

I’m trying to simulate sunshine in an outdoor environment. I’ve tried searching these forums, but typing ‘sun’ and ‘light’ into the search you can imagine the number of hits I get back!

Anyway, here are the values I’m using


//Lights settings
float[] light_ambient = new float[] { 0.1f, 0.1f, 0.1f, 0.1f };
float[] light_diffuse = new float[] { 1.0f, 1.0f, 1.0f, 0.0f };
float[] light_specular = new float[] { 1.0f, 1.0f, 1.0f, 0.0f };
float[] light_position = new float[] { X_POS, Y_POS, Z_POS, 1.0f };

//Materials settings
float[] mat_ambient = new float[] { 0.2f, 0.2f, 0.2f, 0.0f };
float[] mat_diffuse = new float[] { 0.2f, 0.2f, 0.2f, 0.0f };
float[] mat_specular = new float[] { 1.0f, 1.0f, 1.0f, 0.0f };
float[] mat_shininess = new float[] { 1.0f };


but my scene is still very dark, the models are almost completely back. Does anyone have any ideas what the correct settings should be?

If any of the guys working on Tribal Trouble or Wurm Online see this post, what values are you using?

Cheers,

Andy.

The material diffuse value should be 1.0, 1.0, 1.0, 1.0 (at least, near that).

The OpenGL spec has the exact lighting equations. Your scene is dark, because lightness ~= ambience + light_diffuse * material_diffuse, and material_diffuse is too low.

EDIT: Use 1.0 for your alpha values.

Well I tried what you suggested and it’s still very dark, here are the latest values.


//Lights settings
float[] light_ambient = new float[] { 1.0f, 1.0f, 0.0f, 1.0f };
float[] light_diffuse = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };
float[] light_specular = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };
float[] light_position = new float[] { X_POS, Y_POS, Z_POS, 1.0f };

//Materials settings
float[] mat_ambient = new float[] { 0.5f, 0.5f, 0.5f, 1.0f };
float[] mat_diffuse = new float[] { 0.8f, 0.8f, 0.8f, 1.0f };
float[] mat_specular = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };
float   mat_shininess = 1.0f;

This is the code I’m using to enable the light



    GL.glLightfv (GL11.GL_LIGHT1, GL11.GL_AMBIENT, light_ambient);
    GL.glLightfv (GL11.GL_LIGHT1, GL11.GL_DIFFUSE, light_diffuse);
    GL.glLightfv (GL11.GL_LIGHT1, GL11.GL_SPECULAR, light_specular);
    GL.glLightfv (GL11.GL_LIGHT1, GL11.GL_POSITION, light_position);    
    GL11.glEnable(GL11.GL_LIGHT1);
    GL11.glEnable(GL11.GL_LIGHTING);

    //Materials initialization and activation
    GL.glMaterialfv (GL11.GL_FRONT, GL11.GL_AMBIENT, mat_ambient);
    GL.glMaterialfv (GL11.GL_FRONT, GL11.GL_DIFFUSE, mat_diffuse);
    GL.glMaterialfv (GL11.GL_FRONT, GL11.GL_SPECULAR, mat_specular);
    GL.glMaterialf (GL11.GL_FRONT, GL11.GL_SHININESS, mat_shininess);    


I’ve uploaded a screenshot to the projects page of my website.

http://games.swizel-studios.com/projects.html

However the models seem to be flat shaded, now I’m fairly sure you have to use glNormal3f if you want the model to work with lights, and I have that code written. But I use display lists to draw my model on the screen, will display lists actually remember the normals, what happens when I rotate my model using glRotatef, will the normals be rotated too?

Any thoughts are appreciated.

Thanks,

Andy.

[quote]I’m fairly sure you have to use glNormal3f if you want the model to work with lights, and I have that code written. But I use display lists to draw my model on the screen, will display lists actually remember the normals, what happens when I rotate my model using glRotatef, will the normals be rotated too?
[/quote]
Yes, you absolutely need to specify normals for lighting to work and will be handled properly when rotated.

Your light/material setup looks ok (those are FloatBuffers and not arrays, right?). But, how/when are you specifying the light position? Also, don’t use 1.0 for shininess. That’s the specular exponent and values >= 16.0 (up to 128.0) should be used (that is, for most shinny materials).

No the values are float arrays, I have my own class (notice the GL instead og GL11) that takes these and converts them to FloatBuffers in the background. That way I can easily cut and paste existing OpenGL code I find on the internet into my applcations.

rant

When I move to Java1.5 my code will look exactly like that from the Redbook, I’m not a fan of changing the method signatures in LWJGL from those of the OpenGL spec, so I made a class and put them back.

/rant

Andyway, I’ll check my normal code to make sure that looks ok, and I’ll adjust the shininess to be >=16

Thanks,

Andy.