Jump to content

  • Log In with Google      Sign In   
  • Create Account

Lighting - Lightmaps and bumpmaps


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Miguel71   Members   -  Reputation: 116

Like
0Likes
Like

Posted 20 October 2013 - 09:32 AM

Hi, I am currently working on a game engine and I have a problem.

 

I want to introduce lighting to my engine. I know the opengl has only 8 lights so I need to implement my own lighting system. I've tried somee simple fragment shaders to do that but the performance is poor when i use many lights. So I think that I need to use lightmaps on the static geometry.

 

My question is how can I implement bumpmapping using lightmaps(or any other way to do lighting)?



Sponsor:

#2 xantier   Members   -  Reputation: 168

Like
1Likes
Like

Posted 20 October 2013 - 09:53 AM

hello, you can consider implementing deferred rendering for complex geometry with many lights. give it a chance.



#3 Miguel71   Members   -  Reputation: 116

Like
0Likes
Like

Posted 20 October 2013 - 10:36 AM

Thanks for the reply, I will try to do some research on it as soon as possible, but, could you explain me more about how that works?



#4 kauna   Crossbones+   -  Reputation: 2844

Like
3Likes
Like

Posted 20 October 2013 - 12:11 PM

Just to point out when you say "8 lights" it means that for each rendering call you can have up to 8 lights defined. You should be able to find out which lights affect which objects (typically only few) and set the lights for each draw call. 

 

Of course, all that fixed function stuff is implemented with shaders nowadays, and making your own lighting system isn't a bad idea. 

 

Cheers!



#5 3TATUK2   Members   -  Reputation: 730

Like
1Likes
Like

Posted 20 October 2013 - 01:46 PM

Lightmaps are very suitable for static geometry lighting... and advanced directional lightmapping can even be used for semi-dynamic model lighting (light changes on model depending or their position in the map)

 

Basically you first have to know how to bake a lightmap.. I use the method described here: http://forum.unity3d.com/threads/8998-Making-lightmaps-in-Maya-(tutorial)

 

Then implementing it on the code side.. you basically have to have a "duplicate" model of your map, with identical geometry.. You use that to create the lightmap so it gets new uv's... You import the UV's from the lightmap, pass them to the fragment shader, use them to do a texture lookup with the lightmap texture using the same UV coords, and lightply in the result



#6 L. Spiro   Crossbones+   -  Reputation: 14231

Like
1Likes
Like

Posted 23 October 2013 - 09:50 PM

kauna has the best reply.

Doing baked lighting or writing a deferred renderer is an extremely long way to go out of one’s way just because of a simple misunderstanding about how many lights are supported in OpenGL.

 

To be clear: The limit on the number of lights in OpenGL’s fixed-function pipeline is limited only by the amount of memory on your machine.

The limit is 8 at a time.

There is nothing stopping you from rendering using 8 lights, then again with 8 more, and again, etc., until all 20,000 lights in your scene have been processed (never try this at home kids).

Lighting is additive, so each pass simply adds on top of the previous.

 

 

Also mentioned was that you really should be using shaders anyway.  Deferred renderers requires shaders in the first place, and it is still much easier to switch to shaders than to bake and use lightmaps.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#7 Miguel71   Members   -  Reputation: 116

Like
1Likes
Like

Posted 24 October 2013 - 06:26 AM

Thanks for the replies! Although I am going to use the old opengl(probably 2.1) I dont want to use the fixed-function functionality, and I have sucessfully implemented lighting by shaders. The thing is that I want to do per fragment lighting, wich I found to be slow when using multiple lights.

 

I've done some research about deferred rendering and it seams to be my best option. I've sucessfuly made the G-Buffer but i'm having trouble doing the light pass. I'm not sure if I should create another topic about that or not, but i will post part of my code and stuff.

 

normals

BFJCBl0.png

 

position

pVKulul.png

 

diffuse

 

Bslwqml.png

 

I think those are okay. Here is my shader that generates those:

varying vec4 color;
varying vec2 texCoords;

varying vec3 N;

varying vec3 pos;

void main() {
    color = gl_Color.rgba;
    gl_Position = ftransform();
    texCoords = gl_MultiTexCoord0.xy;

    N = normalize(gl_NormalMatrix * gl_Normal);
	
	pos = vec4(ftransform()).xyz;
}

varying vec4 color;
varying vec2 texCoords;
uniform sampler2D textureSampler;

varying vec3 N;
varying vec3 v;

varying vec3 pos;

void main()
{
	gl_FragData[0] = color * texture2D(textureSampler, texCoords);
	gl_FragData[1] = vec4(N, 1.0);
	gl_FragData[2] = vec4(pos, 1.0);
	gl_FragData[3] = vec4(texCoords, 0.0, 1.0);
}

and here is my lighting shader

varying vec2 texCoords;

void main() {
    gl_Position = ftransform();
    texCoords = gl_MultiTexCoord0.xy;
}
varying vec2 texCoords;
uniform sampler2D DSampler;//Diffuse
uniform sampler2D NSampler;//Normals
uniform sampler2D PSampler;//Positions
void main(){
	vec3 lpos = vec3(0, 0, 52);
	
	vec3 v = texture2D(PSampler, texCoords).rgb;
	vec3 N = texture2D(NSampler, texCoords).rgb;
	
	vec3 L = normalize(lpos - v);   
	vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.0);  
	Idiff = clamp(Idiff, 0.0, 1.0);
	
	gl_FragColor = Idiff * texture2D(DSampler, texCoords);
}

What is wrong with those. Everything is black.

 

Thanks.



#8 L. Spiro   Crossbones+   -  Reputation: 14231

Like
1Likes
Like

Posted 25 October 2013 - 03:30 AM

First you do max(dot(N,L), 0.0);, which always produces a negative number or 0, and then you do clamp(Idiff, 0.0, 1.0);, which clamps between 0 and 1.

The only value that can get through that unharmed is 0, and all other values will become 0.


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#9 Miguel71   Members   -  Reputation: 116

Like
0Likes
Like

Posted 25 October 2013 - 10:49 AM

Well, to be honest I don't know how to fix that, i tried putting a minus before max(dot(N,L), 0.0), but that didnt work, so I removed clamp, but that didn't affect anything idk why.

Also, it actualy is working, I probably set the light in a bad position or something. My problem now is that it is upside down and the light is a bit strange. Here are some pictures of it in comparison with forward rendering:

 

Forward rendering

KJg5Im1.png

 

Deferred rendering

 

DVLdeIq.png

 

Idk what is wrong with it. Can somebody help me?

Thanks again. smile.png

 

PS:

Also, could someone tell me if you deferred rendering or forward rendering in your game/engine?


Edited by Miguel71, 25 October 2013 - 10:52 AM.


#10 3TATUK2   Members   -  Reputation: 730

Like
1Likes
Like

Posted 25 October 2013 - 04:18 PM

I use forward rendering with some nice tricks for simple&fast dynamic lighting. I find filling the gbuffer of deferred is just too large an overhead... So it's really only worth it if you have "A LOT" of *active* (on screen and visible) dynamic lights.

 

 

This is all done on a crappy card at ~200 FPS






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS