Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Sunshine light  (Read 1001 times)
0 Members and 1 Guest are viewing this topic.
Offline ap_kelly

Junior Duke




Java rocks!


« Posted 2004-10-20 10:26:07 »

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
//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.

Offline Spasi
« Reply #1 - Posted 2004-10-20 10:32:34 »

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.
Offline ap_kelly

Junior Duke




Java rocks!


« Reply #2 - Posted 2004-10-20 11:43:38 »

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
//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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
    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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Spasi
« Reply #3 - Posted 2004-10-20 12:23:19 »

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?


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).
Offline ap_kelly

Junior Duke




Java rocks!


« Reply #4 - Posted 2004-10-20 20:56:08 »

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.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (35 views)
2014-10-17 03:59:02

Norakomi (26 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (52 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (76 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!