   Bad Point Light Shader? i think?
  Here is the symptom. I have a deferred renderer which correctly lights a cube via a directional light shader. When i try to use a point light however, the cube appears elongated. I checked my modelview and projection matrix, and they are certainly correct (they are the same as when the directional light is rendered). This leads me to suspect my point light shader is not correct, or I am not multiplying something correct. Also, my understanding of the stencil test for marking pixels might be a bit off in relation to drawing the point lights "mesh". what does this mesh do if the stencil test marks the pixels to be drawn? how does this "light direction/position" fit into the point light shader code? From what I read to do a spotlight, you draw a cone mesh, but... when i see examples i see peoples point light meshes to be very small. Anyways... here is the youtube link.. and shader code below it for the point light. If that looks good then i can post my light rendering functions. ">Youtube Linkvoid PointLightV( float4 position : POSITION,float2 texcoord : TEXCOORD0,out float4 oPosition : POSITION,out float2 oTex : TEXCOORD0, out float3 oPos : TEXCOORD1,uniform float4x4 ModelViewProj, uniform float4x4 ModelView,uniform float4 lightPosition){oPosition = mul(ModelViewProj, position);oTex = texcoord;oPos = mul(ModelView, lightPosition);}float3 expand(float3 v){return (2.0 * v) - 1.0;}//Blinn-Phong Lighting model, uses RTs and light variables as input.void PointLightF(float4 color : COLOR,float3 lightpos : TEXCOORD1, out float4 oColor : COLOR,float2 texcoord : TEXCOORD0, uniform float3 lightColor,uniform float4 Ke,uniform float4 Ka,uniform float4 Kd,uniform float4 Ks,uniform float kC,uniform float kL,uniform float kQ,uniform sampler2D pos,uniform sampler2D nor,uniform sampler2D dif,uniform float4x4 ModelView,uniform float3 eyeP){float4 ambient = float4( 0.0, 0.0, 0.0, 0.0);float4 diffuse = float4( 0.0, 0.0, 0.0, 0.0);float4 specular = float4( 0.0, 0.0, 0.0, 0.0);//Sample the G-Buffer and Other Accumulation Buffer float4 position4 = tex2D(pos, texcoord);float4 normal4 = tex2D(nor, texcoord);float4 diffuse4 = tex2D(dif, texcoord);float3 position3 = position4.xyz;float3 normal3 = normal4.xyz;float3 diffuse3 = diffuse4.xyz;float3 sem = float3( position4.w , normal4.w, diffuse4.w);float4 emission = sem.yyyy;float4 shininess = sem.x;float3 lightDir = float3( lightpos.xyz - position3);float d = length(lightDir);lightDir = normalize(lightDir);float attenuation = 1.0/(kC + kL * d + kQ *d *d);float3 halfAngle = normalize(lightDir + eyeP);float nDotLD = max(0.0, dot(normal3 , lightDir  ) );float nDotHA = max(0.0, dot(normal3 , halfAngle  ) );float spec_power;if(nDotLD <= 0.0) {spec_power = 0.0; }elsespec_power = pow(nDotHA, shininess);float4 LightColor = float4 (lightColor.xyz, 0.0f );ambient = Ka;diffuse = Kd * LightColor * nDotLD * attenuation; // Attenuation for Point light.specular = Ks * LightColor * spec_power* attenuation; //specular power still causing black artifacts...why?float4 colorr;colorr= float4( diffuse3, 0.0);//oColor = (emission + ambient + diffuse) *colorr + specular;    oColor = diffuse4; //for debugging and what is used in the youtube vid}also, here is my blending code   glEnable(GL_BLEND);glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR); //GL_ONElight[numlights - 1]->Render();light[0]->PLRender();glDisable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA,GL_SRC_ALPHA);Thanks in advance!! PS: you can go to my profile in youtube to see a video of what it looks like without the point light.   
  Hi, I just had a quick look over your code and nothing immediately strikes me as causing what you describe.Quote:Original post by AverageJoeSSUwhat does this mesh do if the stencil test marks the pixels to be drawn? how does this "light direction/position" fit into the point light shader code? I'm not quite sure what you mean by this.Sorry, it's quite late here, I'll have a look again tomorrow but hopefully someone can help out.;  Thanks for looking. Just in case, here is my light rendering function, which I hope can just be intuitively read. It too is late here, I'll check these values in the morning and post what they are.void Light::PLRender(){//Save the current Matrix and Prep the Lighting Matrix.glPushMatrix();   glMultMatrixf(BuildMatrix().m);   cgGLSetStateMatrixParameter(Lighting->myPLVertexParam_ModelView, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY);//Lots And Lots of customizable Lighting Values, Cool, but lots of setting!float lightPosition[3] = {position.x, position.y, position.z};float eyeP[3] = { mainCam->position.x, mainCam->position.y , mainCam->position.z };//Eye PositioncgSetParameter3fv(Lighting->myPLFragmentParam_eyeP, eyeP);//Ambient Light Value cgSetParameter4fv(Lighting->myPLFragmentParam_Ka, this->Ka);//Emissive Light ValuecgSetParameter4fv(Lighting->myPLFragmentParam_Ke, this->Ke);//Diffuse Light ValuecgSetParameter4fv(Lighting->myPLFragmentParam_Kd, this->Kd);//Specular Light ValuecgSetParameter4fv(Lighting->myPLFragmentParam_Ks, this->Ks);//Light ColorcgSetParameter3fv(Lighting->myPLFragmentParam_lightColor, this->color);//The Lights Position .... Not sure if this is working. Light doesn't move...cgSetParameter3fv(Lighting->myPLVertexParam_lightPosition, lightPosition);//Lighting Attenuation values, a Constant, Linear, and Quadradic valuecgSetParameter1fv(Lighting->myPLFragmentParam_kC, &this->kC);cgSetParameter1fv(Lighting->myPLFragmentParam_kL, &this->kL);cgSetParameter1fv(Lighting->myPLFragmentParam_kQ, &this->kQ);//Bind or 1st Render Target!glActiveTexture( GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D,Lighting->Diff2);cgGLSetTextureParameter(Lighting->myPLFragmentParam_Dif, Lighting->Diff2);//Bind our second Render Target!glActiveTexture( GL_TEXTURE1);glBindTexture(GL_TEXTURE_2D,Lighting->Pos0);cgGLSetTextureParameter(Lighting->myPLFragmentParam_Pos, Lighting->Pos0);//Bind our third render Target!glActiveTexture( GL_TEXTURE2);glBindTexture(GL_TEXTURE_2D,Lighting->Norm1);cgGLSetTextureParameter(Lighting->myPLFragmentParam_Nor, Lighting->Norm1);//Enable the -->Point Light<-- Lighting shaders, they are about to be usedLighting->EnablePLShaders();cgGLSetStateMatrixParameter(Lighting->myPLModelViewProj, CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);//-->Point Light<-- Light affectes small area so render mesh to mark certain pixels. dont use RC ShaderscgUpdateProgramParameters(Lighting->myPLVertexProgram);cgUpdateProgramParameters(Lighting->myPLFragmentProgram);RC.MeshPointer->render();//All DoneLighting->DisableLightShaders();//Clean UPglActiveTexture( GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D, 0);glActiveTexture( GL_TEXTURE1);glBindTexture(GL_TEXTURE_2D, 0);glActiveTexture( GL_TEXTURE2);glBindTexture(GL_TEXTURE_2D, 0);//Restore Last MatrixglPopMatrix();}Oh and forget about the mesh stencil test. I just confused myself, but my problem lies else where i believe.   ;  I am on to something.... I noticed that my setting for the modelviewproj matrix was only passing in the projection as you can see above.... when i changed it to pass the model view proj... i still am seeing a seperate cube only this time not as elongated... but each face of the cube is seperated and scaled outward. still a matrix issue, prolly multiplying?EDIT: Here is an updated youtube link ">Link2[Edited by - AverageJoeSSU on May 16, 2009 1:46:11 PM];  So Sorry to be hogging the forum... if you guys help me(and I solve my problem hehe) i'll sign up for a year membership ;) , but I FINALLY figured out the problem. When i draw the volume for the point light.... i am binding my g-buffer like I should... but the tex-coords are WAY off. how do you figure out what the texcoords of the point light mesh should be for the g-buffer?!?! How would i get the right tex coords for the point light shader above? i imagine something having to do with screen x and y? when i view the light volume from above .... i see the same flat image... because the g-buffer has no depth... im very confused.   ;  Could you post the code that computes and draws the light volume? Might be easier to see what's going on.   ;  Yeah. I got my light volume to sample the gbuffer correctly. I passed in the window size and then divided the WPOS by that in the shader. Now I can debug the actual lighting of the point light shader. anyways... here is the new code, along with a video//Light Init and display codeLight *Light2 = new Light(2, -10, 0, -30, m, Mat);   Light2->setEmDifAmbSpec( 1.0 , 1.0, 1.0 , 0.0, //Emissive   4.1, 4.1, 4.1, 0.0,  //Diffuse   0.0, 0.0, 0.0, 0.0,  //Ambient   4.4, 4.4, 4.4, 0.0,  //Specular   8.0 , 0.4, 0.1 , 0.03 ); //Shininess, kC, kL, kQ   Light2->setColor(1.0, 1.0, 1.0);//display function calls this light->PLRender///Light Render Codevoid Light::PLRender(){//Save the current Matrix and Prep the Lighting Matrix.glPushMatrix();cout << "PLight::Begin" << endl;glMultMatrixf(BuildMatrix().m);glMatrix4x4 mat = BuildMatrix().m;cout << mat;glGetFloatv(GL_MODELVIEW_MATRIX, modelView.m); //NOTE: MATT.. Not sure if our positioning is correct.cout << modelView;glMatrix4x4 proj = BuildMatrix().m;glGetFloatv(GL_PROJECTION_MATRIX, proj.m); //NOTE: MATT.. Not sure if our positioning is correct.cout << proj;cgGLSetStateMatrixParameter(Lighting->myPLVertexParam_ModelView, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY);//Lots And Lots of customizable Lighting Values, Cool, but lots of setting!float lightPosition[3] = {position.x, position.y, position.z};float eyeP[3] = { mainCam->position.x, mainCam->position.y , mainCam->position.z };float WindowSize[2] = { Lighting->width , Lighting->height };//Eye PositioncgSetParameter3fv(Lighting->myPLFragmentParam_eyeP, eyeP);//Ambient Light Value cgSetParameter4fv(Lighting->myPLFragmentParam_Ka, this->Ka);//Emissive Light ValuecgSetParameter4fv(Lighting->myPLFragmentParam_Ke, this->Ke);//Diffuse Light ValuecgSetParameter4fv(Lighting->myPLFragmentParam_Kd, this->Kd);//Specular Light ValuecgSetParameter4fv(Lighting->myPLFragmentParam_Ks, this->Ks);//Light ColorcgSetParameter3fv(Lighting->myPLFragmentParam_lightColor, this->color);//Window Width and Height for Sampling the G-BuffercgSetParameter2fv(Lighting->myPLFragmentParam_windowSize, WindowSize);//The Lights Position .... Not sure if this is working. Light doesn't move...cgSetParameter3fv(Lighting->myPLVertexParam_lightPosition, lightPosition);//Lighting Attenuation values, a Constant, Linear, and Quadradic valuecgSetParameter1fv(Lighting->myPLFragmentParam_kC, &this->kC);cgSetParameter1fv(Lighting->myPLFragmentParam_kL, &this->kL);cgSetParameter1fv(Lighting->myPLFragmentParam_kQ, &this->kQ);//Bind or 1st Render Target!glActiveTexture( GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D,Lighting->Diff2);cgGLSetTextureParameter(Lighting->myPLFragmentParam_Dif, Lighting->Diff2);//Bind our second Render Target!glActiveTexture( GL_TEXTURE1);glBindTexture(GL_TEXTURE_2D,Lighting->Pos0);cgGLSetTextureParameter(Lighting->myPLFragmentParam_Pos, Lighting->Pos0);//Bind our third render Target!glActiveTexture( GL_TEXTURE2);glBindTexture(GL_TEXTURE_2D,Lighting->Norm1);cgGLSetTextureParameter(Lighting->myPLFragmentParam_Nor, Lighting->Norm1);//Enable the -->Point Light<-- Lighting shaders, they are about to be usedLighting->EnablePLShaders();cgGLSetStateMatrixParameter(Lighting->myPLModelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);//-->Point Light<-- Light affectes small area so render mesh to mark certain pixels. dont use RC ShaderscgUpdateProgramParameters(Lighting->myPLVertexProgram);cgUpdateProgramParameters(Lighting->myPLFragmentProgram);RC.MeshPointer->render();//All DoneLighting->DisableLightShaders();//Clean UPglActiveTexture( GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D, 0);glActiveTexture( GL_TEXTURE1);glBindTexture(GL_TEXTURE_2D, 0);glActiveTexture( GL_TEXTURE2);glBindTexture(GL_TEXTURE_2D, 0);//Restore Last Matrix//glPopMatrix();cout << "PLight::End" << endl;}//Code that draws Mesh.. trivial kind of. RC.MeshPointer->render();void Mesh::render(){    if(true)    {glEnableClientState(GL_VERTEX_ARRAY);   glBindBuffer( GL_ARRAY_BUFFER_ARB,  id_VertBO );   glVertexPointer( 3, GL_FLOAT, 0, static_cast< void * >(0) ); // Set The Vertex Pointer To Vertex Data   glClientActiveTexture(GL_TEXTURE0); //Set the active texture to Texture 0glEnableClientState(GL_TEXTURE_COORD_ARRAY);glBindBuffer( GL_ARRAY_BUFFER_ARB,  id_MapCoordBO );   glTexCoordPointer( 2, GL_FLOAT, 0, static_cast< void * >(0) ); // Set The Vertex Pointer To TexCoord DataglEnableClientState(GL_NORMAL_ARRAY);glBindBuffer( GL_ARRAY_BUFFER_ARB , id_NormBO );   glNormalPointer( GL_FLOAT, 0, static_cast< void * >(0) );//glClientActiveTexture(GL_TEXTURE1); //Set the active texture to Texture 1  // glEnableClientState(GL_TEXTURE_COORD_ARRAY);//glBindBuffer( GL_ARRAY_BUFFER_ARB , id_TanBO );  // glTexCoordPointer(3, GL_FLOAT, 0, static_cast< void * >(0) );glBindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB ,  id_PolyBO );   glDrawElements(GL_TRIANGLES,  cmpPolySize, GL_UNSIGNED_INT , static_cast< void *>(/*cmpPoly*/0));   glDisableClientState(GL_VERTEX_ARRAY);glClientActiveTexture(GL_TEXTURE0);glDisableClientState(GL_TEXTURE_COORD_ARRAY);/*glClientActiveTexture(GL_TEXTURE1);glDisableClientState(GL_TEXTURE_COORD_ARRAY);*/   glDisableClientState(GL_NORMAL_ARRAY);glActiveTexture( GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D, 0);glActiveTexture( GL_TEXTURE1);glBindTexture(GL_TEXTURE_2D, 0);glPopMatrix();glFlush();    }    else    {   glCallList(id_displaylist);    }}[/soucrce] [Edited by - AverageJoeSSU on May 20, 2009 11:21:06 AM]