Jump to content
  • Advertisement
Sign in to follow this  
PrestoChung

OpenGL Lighting sparse meshes

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

Is there some way to tweak OpenGL lighting to give better results for sparse meshes? There are very obvious planes of light & dark since lighting is calculated per-vertex.

I would prefer not to subdivide the meshes but if that's the only way...

Example

Share this post


Link to post
Share on other sites
Advertisement
You should investigate per-pixel lighting. Instead of doing your lighting calculations in the vertex shader you do them in the pixel shader. You'll need to make a few extra tweaks, like interpolating the normal across the triangle so you have a per-pixel normal available.

Share this post


Link to post
Share on other sites
Is this a good tutorial on the subject? http://www.lighthouse3d.com/opengl/glsl/

It sounds like I have to somehow make my own vertex and fragment shader? It also sounds like it depends on what version of OpenGL I have.

gluGetString(GL_VERSION) tells me I am running 1.2.2.0 Microsoft Corporation

I would assume my machine/OS is a higher version, and this 1.2.2.0 version is the one I'm working with in my program?

Share this post


Link to post
Share on other sites
And what does glGetString (GL_VERSION) give you? gluGetString is something completely different: http://msdn.microsoft.com/en-us/library/dd368660%28VS.85%29.aspx

Share this post


Link to post
Share on other sites
glGetString(GL_VERSION) gets me 3.3.0.

So is that the version of GL I'm using in my program? Or does that return the version of GL running on my machine at runtime?

Share this post


Link to post
Share on other sites
Right now I draw with these calls:
void DrawVbo()const{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, Vbo_Vert_Id);
glVertexPointer(3, GL_FLOAT, 32, 0);
glNormalPointer (GL_FLOAT, 32, (GLvoid*) (NULL + sizeof (float) * 3));
glTexCoordPointer (2, GL_FLOAT, 32, (GLvoid*) (NULL + sizeof (float) * 6));
glDrawElements(GL_TRIANGLES, NumIndices(Portal_Walls.size()), GL_UNSIGNED_BYTE, 0);
}

Is this usage compatible with using fragment shader?

Do I need to use a vertex shader if I am using a fragment shader? The vertexes are fine, I just want the fragment shader.

Do I need to change to glVertexAttribPointerARB() instead?

Share this post


Link to post
Share on other sites
Quote:
Original post by PrestoChung
Is this usage compatible with using fragment shader?

of course.
however you should change gl*Pointer to glVertexAttribPointer (i think its not necessary tho)

actually i dont know wether you need a vertex shader, as i have never encountered a situation where i only needed a fragment shader.

LightHouse3D GLSL tutorial is quite good btw ;)
EDIT:
Quote:
IF you have a pair vertex/fragment of shaders you'll need to attach both to the program.

from lighthouse3d tut... looks like you dont need both. just try it.
but youll need a vertex shader anyway for interpolating the normal :PP

Share this post


Link to post
Share on other sites
Quote:
Original post by blubberbert
of course.
however you should change gl*Pointer to glVertexAttribPointer (i think its not necessary tho)


Nope, it is not necessary, but it is a good idea, since generic vertex attributes are modern.

Share this post


Link to post
Share on other sites
Thanks.

Any clue as to why glShaderSourceARB is crashing here? I adapted the file loading from this tutorial I had to change some things. Here's my adapted code:


inline Uint32 GetFileLength(std::ifstream& file_){
if(!file_.good()){
return 0;
}

file_.seekg(0, std::ios::end);
Uint32 len = file_.tellg();
file_.seekg(std::ios::beg);

return len;
}

Sint32 LoadShader(char* filename_, GLchar* source_){
std::ifstream file;
GLint len;

file.open(filename_, std::ios::in); //open ASCII
if(!file){
return -1;
}

len = GetFileLength(file);

if( len==0 ){
return -2; //Is empty
}

source_ = new GLchar[len+1];

if ( *source_==0 ){
return -3; //Memory not reserved
}

source_[len] = '\0';

Uint32 i = 0;

while( file.good() ){
source_ = (GLchar)file.get(); //Get character from file
if( !file.eof() ){
++i;
}
}

source_ = '\0'; //0-terminate at correct position

file.close();

return 0; //No errors
}

CompileShaders(){
GLhandleARB vshadehandle;
GLhandleARB fshadehandle;
GLcharARB* vshadesource=0;
GLcharARB* fshadesource=0;
vshadehandle = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB );
fshadehandle = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB );
LoadShader("vertshader.vert", vshadesource );
LoadShader("fragshader.frag", fshadesource );
glShaderSourceARB(vshadehandle, 1, (const GLcharARB**)&vshadesource, NULL); //<-----CRASH
glShaderSourceARB(fshadehandle, 1, (const GLcharARB**)&fshadesource, NULL);
glCompileShaderARB(vshadehandle);
glCompileShaderARB(fshadehandle);
}



Share this post


Link to post
Share on other sites
check wether the extension is supported on your graphics card(it should be o.0)

anyway check your file loading code... it looks strange to me
Quote:
Original post by PrestoChung
if ( *source_==0 ){
return -3; //Memory not reserved
}

are you sure you want the content of source?? because after a new[] you dont know whats in there so why check it for 0?


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!