Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Texgen and per pixel lighting!

This topic is 5007 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

here it is... render state pp LightPoint... void OpenGL::SetLightPoint(RS_LightPoint *in_state, Primitive *in_primitive) { glBlendFunc(GL_DST_COLOR, GL_ZERO); glEnable(GL_BLEND); GLfloat l_radius = 5.0f; GLfloat l_intensity = 1.0f / l_radius; Vector3 l_lightPosition = Vector3(3.0f, 1.0f, 0.0f); GLfloat l_plane_x[4] = {l_intensity, 0.0f, 0.0f, 0.5f - l_lightPosition.x / l_radius}; GLfloat l_plane_y[4] = {0.0f, l_intensity, 0.0f, 0.5f - l_lightPosition.y / l_radius}; GLfloat l_plane_z[4] = {0.0f, 0.0f, l_intensity, 0.5f - l_lightPosition.z / l_radius}; GLfloat l_plane_w[4] = {0.0f, 0.0f, 0.0f, 1.0f}; Texture *l_texture; // Texture 2D radial map texture. l_texture = in_state->GetScopeMap(); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, (GLuint) in_texture->GetImageData()); glEnable(GL_TEXTURE_2D); glTexGenfv(GL_S, GL_EYE_PLANE, l_plane_x); glTexGenfv(GL_T, GL_EYE_PLANE, l_plane_y); glTexGenfv(GL_R, GL_EYE_PLANE, l_plane_z); glTexGenfv(GL_Q, GL_EYE_PLANE, l_plane_w); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); glEnable(GL_TEXTURE_GEN_Q); // Texture 1D linear ramp texture. l_texture = in_state->GetRayMap(); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_1D, (GLuint) in_texture->GetImageData()); glEnable(GL_TEXTURE_1D); glTexGenfv(GL_S, GL_EYE_PLANE, l_plane_z); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glEnable(GL_TEXTURE_GEN_S); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_SUBTRACT_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_ONE_MINUS_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); glDrawElements(GL_QUADS, in_primitive->GetVertexCount(), GL_UNSIGNED_INT, in_primitive->GetQuad()); glActiveTextureARB(GL_TEXTURE1_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_1D); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); glDisable(GL_TEXTURE_GEN_Q); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); } it is difficult to make it simple! but i think we are getting there... the only thing missing here (I think) its the right equation for the l_plane_*... and tadam... per pixel lighting... the rest is pretty much rock solide! can someone help finding the right equation? Thx

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!