Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
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  
  Dark lighting with multiple lights  (Read 747 times)
0 Members and 1 Guest are viewing this topic.
Offline obsidian_golem

Senior Newbie




Computer programmer / Google oracle


« Posted 2012-05-15 17:07:25 »

I am working on using multiple lights. When I add more than one light the dark parts of the lighting become darker. What am I doing wrong? Here is the important part of my shader:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
#version 120
uniform vec4 ulight1;
uniform vec4 ulight2;
uniform vec4 ulight3;
uniform vec4 ulight4;

varying vec4 v_color;
varying vec3 v_position;
varying vec3 v_normal;


vec3 ambient = vec3(0.2,0.2,0.2);
vec3 lightcolor = vec3(0.6,0.6,0.6);

vec3 phong() {
   vec3 nn = normalize(v_normal);
   vec3 dtl1 = ulight1.xyz-(v_position);
   vec3 dtl2 = ulight2.xyz-(v_position);
   vec3 dtl3 = ulight3.xyz-(v_position);
   vec3 dtl4 = ulight4.xyz-(v_position);
   float dis1 = length(dtl1);
   float dis2 = length(dtl2);
   float dis3 = length(dtl3);
   float dis4 = length(dtl4);
   float att1 = (1.0 / (1.0 + (dis1 * dis1)));
   float att2 = (1.0 / (1.0 + (dis2 * dis2)));
   float att3 = (1.0 / (1.0 + (dis3 * dis3)));
   float att4 = (1.0 / (1.0 + (dis4 * dis4)));
   float d1 = max(dot(nn,normalize(dtl1)),0.0);
   float d2 = max(dot(nn,normalize(dtl2)),0.0);
   float d3 = max(dot(nn,normalize(dtl3)),0.0);
   float d4 = max(dot(nn,normalize(dtl4)),0.0);
   vec3 lw1 = att1*(ambient+lightcolor*d1)*ulight1.w; // w of 0 = no light
  vec3 lw2 = att2*(ambient+lightcolor*d2)*ulight2.w;
   vec3 lw3 = att3*(ambient+lightcolor*d3)*ulight3.w;
   vec3 lw4 = att4*(ambient+lightcolor*d4)*ulight4.w;
   float ff = (-((ulight1.w+ulight2.w+ulight3.w+ulight4.w)-1))/2;// Increase ambient when no light
  vec3 final = vec3(ambient+ff);
   return lw1+lw2+lw3+lw4+final; //add together lights
}

Here are some screenshots.

One Light:


Two Lights:
Offline _Al3x

JGO Coder


Medals: 7
Projects: 1


Indie Games FTW!


« Reply #1 - Posted 2012-05-16 06:15:15 »

I think that the lights are further away from the "darkening" side you speak of.

As I see it, I'm standing in the z axis looking at the y axis right? if we look from the left this is what I imagine is happening:

y axis
|
|      [light/s]
|                                                                                                                              >0 (camera)
|                                                          _[surface]<-- dark side_________                        
|____________________________________________________________________________________ z axis
|

I don't know If you get what I mean. If I'm right, that's a normal behavior, but if I'm wrong, then we'll need to wait for anyone with more experience Smiley
Could you provide the coords of the lights and that surface-object-thing? Smiley

Offline UprightPath
« Reply #2 - Posted 2012-05-16 06:31:08 »

This chunk of code is my suspect.
1  
float ff = (-((ulight1.w+ulight2.w+ulight3.w+ulight4.w)-1))/2;// Increase ambient when no light

If ulight1.w + ulight2.w + ulight3.w + ulight4.w > 1, then ff's result will be a negative number, rather than a positive. Check these values if you can.

Games published by our own members! Check 'em out!
Try the Free Demo of Revenge of the Titans
Offline obsidian_golem

Senior Newbie




Computer programmer / Google oracle


« Reply #3 - Posted 2012-05-16 06:59:12 »

This chunk of code is my suspect.
1  
float ff = (-((ulight1.w+ulight2.w+ulight3.w+ulight4.w)-1))/2;// Increase ambient when no light

If ulight1.w + ulight2.w + ulight3.w + ulight4.w > 1, then ff's result will be a negative number, rather than a positive. Check these values if you can.

Oops. Removing that fixed it. That code was old and unnecessary anyway.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (31 views)
2013-05-17 21:29:12

alaslipknot (40 views)
2013-05-16 21:24:48

gouessej (70 views)
2013-05-16 00:53:38

gouessej (69 views)
2013-05-16 00:17:58

theagentd (78 views)
2013-05-15 15:01:13

theagentd (73 views)
2013-05-15 15:00:54

StreetDoggy (113 views)
2013-05-14 15:56:26

kutucuk (137 views)
2013-05-12 17:10:36

kutucuk (136 views)
2013-05-12 15:36:09

UnluckyDevil (145 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.169 seconds with 20 queries.