Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
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 918 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

Senior Member


Medals: 7


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!
Legends of Yore - The Casual Retro Roguelike
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.

 

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

The first screenshot will be displayed as a thumbnail.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!