Jump to content
  • Advertisement
Sign in to follow this  
b3rs3rk

Colored point light

This topic is 5390 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

take a look at this picture: http://www.neoborn.com/users/b3rs3rk/pointlight.jpg this is a screen of a demo i've found on the net. There was no source. In my engine i've set up per pixel light and i get a nice diffuse light, but it's always white. The question is: how can i get a colored light? (i don't want attenuation. not yet.) i've used opengl extensions for the diffuse light.There's a way to get a colored DIFFUSE light using only opengl extensions? (i mean, without register combiners or ps? )

Share this post


Link to post
Share on other sites
Advertisement
While im not exactly 100% shure on how you set up your light(your a bit vauge on that area), but if you want to make a red light from a white one, then just multiply it with the color red.

Share this post


Link to post
Share on other sites
i've set up my light this way:


glActiveTextureARB(GL_TEXTURE0_ARB); // cube map
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB_ARB) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE1);

glActiveTextureARB(GL_TEXTURE1_ARB); // normal map
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE2);

glActiveTextureARB(GL_TEXTURE2_ARB); // decal texture
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);



if i multiply my light with a color (for example red), everything on the screen becames red, not only the point light :/

Share this post


Link to post
Share on other sites
I sugest you look at the general lambertian lighting model and take the parts you need and transfer them to texenv stages. Since full lighting model uses huge number of parameters, you can always remove some parts (that are replaced by impicite constants).

The picture you posted uses something like:
final_color = diffuse_texture * ( ambient_color + light_color * ( N dot L ) * attenuation )

Now, throwing out attenuation would result in all scene being red.

Share this post


Link to post
Share on other sites
i think that maybe i need that attenuation after all :P

but the light should be attenuated to the global ambient color, so it may be red to black if the ambient light is black or red to white if the ambient light is white and so on...

for the attenuation i modulate the result of the previous code with a 3d texture:

glActiveTextureARB(GL_TEXTURE3_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS) ;



this 3d texture is built this way:

GLuint generateColoredAttenuation(unsigned int size, GLfloat red, GLfloat green, GLfloat blue){
GLubyte* pixels;
GLuint texid;
int i, j, k;

pixels = (GLubyte*)malloc(3*size*size*size*sizeof(GLubyte));
if (pixels == NULL) return 0;

for (i = 0 ; i < size ; ++i) {
float iattn = 1.f-2.f*fabs(i/(float)(size-1)-0.5f);
for (j = 0 ; j < size ; ++j) {
float jattn = 1.f-2.f*fabs(j/(float)(size-1)-0.5f);
for (k = 0 ; k < size ; ++k) {
float kattn = 1.f-2.f*fabs(k/(float)(size-1)-0.5f);
float attn = iattn*jattn*kattn;
pixels[3*sizeof(GLubyte)*(k+size*(j+i*size))+0] = (GLubyte)(attn*255.f*red);
pixels[3*sizeof(GLubyte)*(k+size*(j+i*size))+1] = (GLubyte)(attn*255.f*green);
pixels[3*sizeof(GLubyte)*(k+size*(j+i*size))+2] = (GLubyte)(attn*255.f*blue);
}
}
}

glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_3D_EXT, texid);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexImage3DEXT(GL_TEXTURE_3D_EXT, 0, GL_RGB, size, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);

free(pixels);

return texid;
}




this is a code posted by vincoof (thanks!) some times ago.
With this i can create a 3d coloured texture, but assumes that the ambient light is black.

what should i modify?

Share this post


Link to post
Share on other sites
Using colored attenuation map is not the best approach. You'll need one map for each color. Not to mention that you need 4 times the memory for each one. And the whole concept of light color to ambient color does not work well. It totaly breaks once you use more then one light. A sugest using standard proven method and take shourcuts elsewhere.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!