Per Pixel Llighting, or Per Pixel Pain :-(

Started by
0 comments, last by laeuchli 22 years, 6 months ago
Ok, one long post coming. I''m trying to do per pixel lighting on a landscape. Accutally the extent of my ambtion right now is to get my dumb geforce 2 rendering lightmaps in realtime with register combiners. The way I''m trying to do it is this. From what I understand of lighting, you have a light postion, and you have normal. You do a dot product and bingo, lights on(well, ok you still have some work to do after that, but not as difficult)! So, for my lighting, I take my light postion, and I generate a normal map texture, and dot product them together with register combiners, and then finish the equations with the final combiner. It''s not working right, so I decided to start out I''d just make a flat quad, with uniform normal map, and get the per pixel lighting working there, and then go on. Unfortanitly, I''m having trouble(hence this post). It''s not that I don''t get anything on the quad, I do, and it even resembles a lightmap(which is of course what I''m looking for), but it''s not paying attention to the postion of the light. I''m not sure why this is. Maybe I''m not gerenating the normals right? Using the register combiners wrong? I''m not sure. Below is my code. I tried to keep it down to a minimum, but I''m not totaly sure exactly which part is correct and which isn''t. If someone who has done this before could help, I''d be gratefull. Thanks,Jesse www.laeuchli.com/jesse/ #include #include #include #include #include #include #include GLuint texturest; GLuint texturest2; #define csize 256 float lightpos[]={1,0,0,1}; float color[]={ 1,1,1,1}; float ptexture[csize][csize][4]; PFNGLCOMBINERPARAMETERFVNVPROC glCombinerParameterfvNV; PFNGLCOMBINERPARAMETERFNVPROC glCombinerParameterfNV; PFNGLCOMBINERPARAMETERIVNVPROC glCombinerParameterivNV; PFNGLCOMBINERPARAMETERINVPROC glCombinerParameteriNV; PFNGLCOMBINERINPUTNVPROC glCombinerInputNV; PFNGLCOMBINEROUTPUTNVPROC glCombinerOutputNV; PFNGLFINALCOMBINERINPUTNVPROC glFinalCombinerInputNV; void setupcombiners() { glCombinerParameterfvNV=(PFNGLCOMBINERPARAMETERFVNVPROC)wglGetProcAddress("glCombinerParameterfvNV"); glCombinerParameterfNV=(PFNGLCOMBINERPARAMETERFNVPROC)wglGetProcAddress( "glCombinerParameterfNV"); glCombinerParameterivNV=(PFNGLCOMBINERPARAMETERIVNVPROC)wglGetProcAddress( "glCombinerParameterivNV"); glCombinerParameteriNV=(PFNGLCOMBINERPARAMETERINVPROC)wglGetProcAddress( "glCombinerParameteriNV"); glCombinerInputNV=(PFNGLCOMBINERINPUTNVPROC)wglGetProcAddress( "glCombinerInputNV"); glCombinerOutputNV=(PFNGLCOMBINEROUTPUTNVPROC)wglGetProcAddress( "glCombinerOutputNV"); glFinalCombinerInputNV=(PFNGLFINALCOMBINERINPUTNVPROC)wglGetProcAddress( "glFinalCombinerInputNV"); } PFNGLACTIVETEXTUREARBPROC glActiveTextureARB=NULL; PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB=NULL; void setuptext() { glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glActiveTextureARB"); glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC) wglGetProcAddress("glMultiTexCoord2fARB"); } void combinercode() { glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, 1); ///// glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, (float*)&lightpos); glCombinerParameterfvNV(GL_CONSTANT_COLOR1_NV, (float*)&color); /// glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_CONSTANT_COLOR0_NV,GL_SIGNED_IDENTITY_NV, GL_RGB); ///////////////////// glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB); //////////////// glCombinerOutputNV(GL_COMBINER0_NV, GL_RGB, GL_SPARE0_NV, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_TRUE, GL_FALSE, GL_FALSE); //////////Should Be working by now :-).... glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_CONSTANT_COLOR1_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glFinalCombinerInputNV(GL_VARIABLE_G_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA); } void blackwhite() { for(int y=0;y
Advertisement
From my dealings and understandign with per-pixel lighting is that you have to do the lighting per surface in it''s texture space (the reason for normal maps). So you have to "bring" your camera and light into it''s space then and then do your work. Im not sure if you are doing this or not since i barely glanced at your code, its 10am and I been up coding for 3 days on work of my own. Hopefully I can be more of assistance later.
Developer Journal: The Life of Corman

This topic is closed to new replies.

Advertisement