PDA

View Full Version : shading lighting



AeroSujan
12-16-2011, 03:45 AM
Dear Friends
I have created surface using QUADS in opengl. Now I have shaded the object suing two lights, light0 and light1 with some values for -z and +z. I have also calculated the normals during the vertex calculation for QUAD points. So my shading is coming somewhat ok. But I want more brightness. How can I achieve more brightness. Please any help would be highly appreciated. Thanks Sujan

This is my shading algorithm


void CRevolutionProjView::OnViewShade()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
glMatrixMode(GL_MODELVIEW);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
GLfloat ambientLight0[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat diffuseLight0[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat specularLight0[] = { 0.0f, 0.0f, 1.0f, 1.0f };
GLfloat emissionLight0[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat position0[] = {0.0f,0.0f,-1000.0f,1.0f};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight0);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight0);
glLightfv(GL_LIGHT0, GL_EMISSION, emissionLight0);
glLightfv(GL_LIGHT0, GL_POSITION, position0);

GLfloat ambientLight1[] = { 0.4f, 0.4f, 0.4f, 1.0f };
GLfloat diffuseLight1[] = { 0.3f, 0.3f, 0.3f, 1.0f };
GLfloat specularLight1[] = { 0.0f, 0.0f, 1.0f, 1.0f };
GLfloat emissionLight1[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat position1[] = {0.0f,0.0f,1000.0f,1.0f};
glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight1);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight1);
glLightfv(GL_LIGHT1, GL_SPECULAR, specularLight1);
glLightfv(GL_LIGHT1, GL_EMISSION, emissionLight1);
glLightfv(GL_LIGHT1, GL_POSITION, position1);

Invalidate();
wglMakeCurrent(NULL,NULL);
}

thokra
12-16-2011, 06:26 AM
OpenGL interprets RGBA values for light sources as the intensity of the respective channel (although at the moment I'm not quite sure how an alpha intensity value makes sense at all). You're basically simulating how many photons a light source emits per wavelength (which is a constant in this case). So if you want something to apperar brighter, you're gonna have to increase the amount of photons the light source emits, i.e. increse the ambient, diffuse and specular intensities.

The ambient, diffuse and specular material properties simulated by OpenGL are somewhat different, as they approximate the amount of photons per wavelength reflected by the surface the material is applied to. You can vary the apparent brightness by choosing different values here as well. If you want maximum reflection, choose the biggest value for a channel or all channels (e.g. (1, 1, 1) or (255, 255, 255) or (255, 0, 0) a.s.o.).

Ultimately you can only get a very limited simulation of light with fixed-function OpenGL, since the maximum amount of incoming light is clampled to 1.0 which is completely physically inaccurate.