Sign in to follow this  
mldaalder

OpenGL Need some pointers to my modification of Pauls Cel Shading program

Recommended Posts

mldaalder    193
Hello, For the last couple of days I've been trying to modify Pauls (as in www.paulsprojects.net) Cel Shading (the OpenGL version offcourse) example be able to handle multiple lights and colors (each light can have a diffrent color). So far I've managed to get the multiple lights working very good (just using the largest Dot product as the light to use), the shadows show very well and all. This is done the manual per Vertex lighting, not through ARB_vertex_program. Now, the colors are giving me a slight problem, mostly because I've never worked with Shaders before (not even this kind of shaders...). But the real problem is, they really are per vertex. And not smooth like the lighting. The most likly problem (or bottleneck) is that I'm assigning colors pretty much the same way as the vertexs. Namely through the use of a Color Array Pointer. Something else I would like to solve, is how to see if the vertex is occluded by something, so it doesn't get lit. And the last question is, how could I do something similar through a ARB_vertex_program shader (The one used under the button 2 of the program)? Thank you for your time, MLeoDaalder

Share this post


Link to post
Share on other sites
mldaalder    193
[looksaround]

So what's not clear about my post?

Am I the only one having this problem and is it increadibly easy and is considerd that everyone knows how to do this?


How should I post questions anyway so that I might get a respond?
Just for future questions?

Thank you,

MLeoDaalder

Share this post


Link to post
Share on other sites
zedzeek    529
i read your post a couple of times i still cant workout exactly what u want to do, perhaps a screenshot of what youve achieve sofar with a describtion of what u want to achieve

Share this post


Link to post
Share on other sites
mldaalder    193
Quote:
Original post by zedzeek
i read your post a couple of times i still cant workout exactly what u want to do, perhaps a screenshot of what youve achieve sofar with a describtion of what u want to achieve

Now that's what I call constructive! Thanks!

Ok, here is what I have:
These show that I have successfully implented multiple lights.
And a very crude lighted colors...
Cel Shading 1
Cel Shading 2


My goal is to make the colors fluid as well.
And to check for occlusion.
As shown in this picture there isn't any.
Cel Shading 3
It's most noticable in the inner ring of the torus.


Thank you for your interrest!

Share this post


Link to post
Share on other sites
zedzeek    529
im a bad explained but anyways

>>My goal is to make the colors fluid as well.<<

u mean the blockiness (staircase effect) in red on the second picture?, i believe this is caused by u saturating the color for that vertice once the color value has gone above 1.0 its not going any higher

>>And to check for occlusion.<<

thus u only want the light to affect pieces of the mesh that actually would recieve that light ie theyre not being blocked by other parts of the mesh, if thats the case then u need to look into shadowing techniques. ie if a pixel is in shadow then dont let that light contribute to its shading

Share this post


Link to post
Share on other sites
mldaalder    193
Quote:
Original post by zedzeek
im a bad explained but anyways

>>My goal is to make the colors fluid as well.<<

u mean the blockiness (staircase effect) in red on the second picture?, i believe this is caused by u saturating the color for that vertice once the color value has gone above 1.0 its not going any higher

In any of the colored parts.
The original color is r: 0.85, g: 0.75, b: 1.0
The upper left light has the color white.
The middle has the color: 1.0f, 0.0f, 0.5f
The upper right light has the color 1.0f, 1.0f, 0.0f

And this is my color/lighting part.

// Setting the initial color
for(int i=0;i<(torus.numVertices * 3);i+=3)
{
colorCoefficients[i ] = 0.95f;
colorCoefficients[i+1] = 0.75f;
colorCoefficients[i+2] = 1.0f;
//colorCoefficients[i] = float((double)i / (double)(torus.numVertices * 3.0));
//0.75f, 0.95f, 1.0f
}
int z=0;
for(i=0; i<torus.numVertices; i++)
{
lightCoefficients[i] = 0.0f;
for(int j=0; j<8; j++)
{
if(!(lightPositions[j].x == 0 && lightPositions[j].y == 0 && lightPositions[j].z == 0))
{
VECTOR3D lightDirection=(VECTOR3D(inverseModelMatrix*lightPositions[j])-torus.vertices[i].position).
GetNormalized();
if(torus.vertices[i].normal.DotProduct(lightDirection) > lightCoefficients[i])
{
lightCoefficients[i] = torus.vertices[i].normal.DotProduct(lightDirection);
if(!(lightColors[j].x == 0 && lightColors[j].y == 0 && lightColors[j].z == 0))
{
//colorCoefficients[z ] += (float(lightColors[j].x) * torus.vertices[i].normal.DotProduct(lightDirection));
//colorCoefficients[z+1] += (float(lightColors[j].y) * torus.vertices[i].normal.DotProduct(lightDirection));
//colorCoefficients[z+2] += (float(lightColors[j].z) * torus.vertices[i].normal.DotProduct(lightDirection));
colorCoefficients[z ] += float(lightColors[j].x);
colorCoefficients[z+1] += float(lightColors[j].y);
colorCoefficients[z+2] += float(lightColors[j].z);
colorCoefficients[z ] /= 2.0f;
colorCoefficients[z+1] /= 2.0f;
colorCoefficients[z+2] /= 2.0f;
}
}
}
}
z += 3;
}



I tried to use the vector class (the dynamic array one), but something is wrong with it, so any light at 0,0,0 or a black light is not shown.

I know this isn't the best way... It's my first program trying to make my own light...

Quote:
>>And to check for occlusion.<<

thus u only want the light to affect pieces of the mesh that actually would recieve that light ie theyre not being blocked by other parts of the mesh, if thats the case then u need to look into shadowing techniques. ie if a pixel is in shadow then dont let that light contribute to its shading

Thanks for the pointer!

Share this post


Link to post
Share on other sites
mldaalder    193
Well, an update to the occlusion test...
I modified it from the Lensflare occlusion test (NeHe lesson 44).
And one thing I can say, it's killing my fps big time!
From about 85 to 20...
And it provides a completly occluded object...

But I also think this is a dual pass test.
Which means I will have to render the entire object for every light in the scene.

I suppose there isn't an better way?
Like a Vertex/Face Database?

[EDIT]
After some more fidling I got the framerate down to 0.20...
And for some reason I find this funny.
[grin]

And here is my occlusion test routine.
If I remove the glClear then I can see (sort of) what the light must see.


bool CheckShadow(TORUS* o, VECTOR3D* p, VECTOR3D* pos, VECTOR3D *dir)
{
glPushMatrix();
glLoadIdentity();

//draw torus
glDrawElements(GL_TRIANGLES, o->numIndices, GL_UNSIGNED_INT, o->indices);

// Translate to the light position
glTranslated(pos->x, pos->y, pos->z);
// Rotate to the light direction
glRotated(1.0f, dir->x, dir->y, dir->z);

GLint viewport[4]; //space for viewport data
GLdouble mvmatrix[16], projmatrix[16]; //space for transform matricex
GLdouble winx, winy, winz; //space for returned projected coords
GLdouble flareZ; //here we will store the transformed flare Z
GLfloat bufferZ; //here we will store the read Z from the buffer

glGetIntegerv (GL_VIEWPORT, viewport); //get actual viewport
glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix); //get actual model view matrix
glGetDoublev (GL_PROJECTION_MATRIX, projmatrix); //get actual projiection matrix

gluProject(p->x, p->y, p->z, mvmatrix, projmatrix, viewport, &winx, &winy, &winz);
flareZ = winz;

// we read back one pixel from th depth buffer (exactly where our flare should be drawn)
glReadPixels(winx, winy,1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &bufferZ);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

glPopMatrix();
if (bufferZ < flareZ)
return true;
else
return false;
}


And after some commenting stuff out I've found that glClear and glDrawElements are the things that slow it down.

[Edited by - mldaalder on November 27, 2004 9:38:01 AM]

Share this post


Link to post
Share on other sites
mldaalder    193
I've tried a couple of things for the shadow checking, but I haven't found it (yet)...
With it I mean a working method (not to speak of the FPS).


I also tried another implementation of the light colors.
I tried to use 3 1D textures. Representing Red, Green and Blue.
I thought of using multi texturing, but I figured out that they would cancel each other out because OpenGL fills in 0s for each missing component in glTexImage1D.

I've also tried 3D textures, but they didn't show up and (I calculated) to get a proper colors I'd have to use a texture with the size of:
256*256*256*3 = ~50MB.
Not a really good idea considering I have a 128MB Video card. :P

So any idea's for both of these 2 problems?
Or any basic ARB_fragment_program tutorials?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Partner Spotlight

  • Similar Content

    • By pseudomarvin
      I assumed that if a shader is computationally expensive then the execution is just slower. But running the following GLSL FS instead just crashes
      void main() { float x = 0; float y = 0; int sum = 0; for (float x = 0; x < 10; x += 0.00005) { for (float y = 0; y < 10; y += 0.00005) { sum++; } } fragColor = vec4(1, 1, 1 , 1.0); } with unhandled exception in nvoglv32.dll. Are there any hard limits on the number of steps/time that a shader can take before it is shut down? I was thinking about implementing some time intensive computation in shaders where it would take on the order of seconds to compute a frame, is that possible? Thanks.
    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
  • Popular Now