Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Sa Jun 08, 2024 13:51

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 48 Beiträge ]  Gehe zu Seite Vorherige  1, 2, 3, 4  Nächste
Autor Nachricht
 Betreff des Beitrags:
BeitragVerfasst: So Sep 12, 2004 20:10 
Offline
DGL Member
Benutzeravatar

Registriert: Di Nov 26, 2002 22:12
Beiträge: 259
Wohnort: Dresden
Now everything works fine and the frame rates are acceptable.

_________________
Nichts auf der Welt ist so gerecht verteilt wie der Verstand. Denn jederman ist überzeugt, dass er genug davon habe.
Rene Descartes, frz. Mathematiker u. Philosoph, 1596-1650


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Sep 12, 2004 22:33 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
240fps with shadows, ok i need to work some more on my code. Are you using special ways rendering like vbo's or are they plain old glvertex3f's you use.

So ati handles setting up stencil buffers differently then nvidia? Is there a generic way that works on both? Or were you using a special ati extension?

By looking at your demo the zfail method is the way to get shadows always right. I should look into that also.

Like is said in the beginning, some things start simple.... , but things are starting to look good. A side point is that the gl3ds can be cleaned up some more and becomes easier to read as it now uses faces, they were there before, but not so easy to access. So this things turns to become a win win situation. But then again when you think you are finished some more problem can come in the way.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Sep 12, 2004 22:35 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
No, I use plain ol' glVertex-calls (aka immediate mode) in that demo, so nothing special there. And as for setting stencil up : I didn't do anything special to ATI, I just forgot to ask for a pixelformat with stencil bits, and ATI cards then give you (if you request 24 depth and 32 color bits) automatically 8 bits of stencil, NV cards don't (as it seems).

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Sep 13, 2004 18:53 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
i am running out of ideas and shadow are still not working ok. It seems that once meshes overlap holes start to occur in the shadows.

here is my main render routine

Code:
  1.  
  2. glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT);  
  3.   glLoadIdentity();
  4.  
  5.   camera.Render; //set the camera position
  6.  
  7.   //set light position
  8.   glLightfv(GL_LIGHT0, GL_POSITION, @lp); //position light
  9.  
  10.   //get the light position
  11.   objlightpos2.x:=lp[0];
  12.   objlightpos2.y:=lp[1];
  13.   objlightpos2.z:=lp[2];
  14.   objlightpos2.w:=lp[3];
  15.  
  16.   // Get the inverse model matrix
  17.   glPushMatrix;
  18.     glLoadIdentity;
  19.     glGetFloatv(GL_MODELVIEW_MATRIX, @InvMatrix);
  20.   glPopMatrix;
  21.   //Get the object space light vector
  22.   ObjLightPos2 := vectortransform4f(objlightpos2,InvMatrix);
  23.  
  24.   // Draw the light
  25.   glDisable(GL_LIGHTING);
  26.   glPushMatrix();
  27.     glTranslatef(LP[0], LP[1], LP[2]);
  28.     glColor3f(1, 1, 0);
  29.     gluSphere(LightObj, 0.2, 8, 8);
  30.   glPopMatrix();
  31.     glEnable(GL_LIGHTING);
  32.   //now on to rendering...
  33.   glrotatef(270,1,0,0); //rotate the scene...
  34.  
  35. //fill the depth buffer (ambient pass)
  36. glenable(GL_DEPTH_TEST);
  37. glDepthFunc(GL_LESS);
  38. glEnable(GL_CULL_FACE);
  39. glCullFace(GL_BACK);
  40. //ambientmode:=true;
  41. drawscene;
  42.  
  43. //prepare for shadows
  44. glDepthMask(FALSE);
  45. glEnable(GL_BLEND);
  46. glBlendFunc(GL_ONE,GL_ONE);
  47.  
  48. //for each light
  49. glDisable(GL_LIGHT0);
  50. glClear(GL_STENCIL_BUFFER_BIT);
  51. glColorMask(FALSE,FALSE,FALSE,FALSE);
  52. glEnable(GL_STENCIL_TEST);
  53. glStencilFunc(GL_ALWAYS, 0, byte(not 0));
  54. glStencilMask(byte(not 0));
  55.  
  56. makeshadows; //determine face visibility...
  57.  
  58. //zfail
  59. glEnable(GL_CULL_FACE);
  60. glCullFace(GL_FRONT);
  61. glStencilOp(GL_KEEP, GL_INCR_WRAP, GL_KEEP);
  62. drawshadows;
  63.  
  64. glCullFace(GL_BACK);
  65. glStencilOp(GL_KEEP, GL_DECR_WRAP, GL_KEEP);
  66. drawshadows;
  67.  
  68. glEnable(GL_LIGHT0);
  69. //end for each light
  70.  
  71. glCullFace(GL_BACK);
  72. //draw diffuse part
  73. glStencilFunc(GL_EQUAL, 0, byte(not 0));
  74. glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
  75. gldepthfunc(GL_EQUAL);
  76. glColorMask(TRUE,TRUE,TRUE,TRUE);
  77. //ambientmode:=false;
  78. drawscene;
  79.  
  80. //restore render settings
  81. glDepthFunc(GL_LESS);
  82. glDisable(GL_BLEND);
  83. glDisable(GL_STENCIL_TEST);
  84. glDepthMask(TRUE);
  85.  
  86. //render the gui
  87. gldisable(GL_TEXTURE_2D);
  88. glActiveTexture(GL_TEXTURE0); //go back to texture0 (just to be save)
  89.  
  90. rendergui;
  91.  
  92. //Flush the OpenGL Buffer
  93. glFlush(); //is it needed?
  94.  

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Sep 13, 2004 21:24 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
Code:
  1. glStencilFunc(GL_ALWAYS, 0, byte(not 0));

That's wrong. It should be $FFFFFFFF for the last parameter.

Code:
  1. //zfail
  2. glEnable(GL_CULL_FACE);
  3. glCullFace(GL_FRONT);
  4. glStencilOp(GL_KEEP, GL_INCR_WRAP, GL_KEEP);
  5. drawshadows;
  6.  
  7. glCullFace(GL_BACK);
  8. glStencilOp(GL_KEEP, GL_DECR_WRAP, GL_KEEP);
  9. drawshadows;


If you use Z-Pass, then you need to cap your shadow volumes. Otherwise you'll the the effect described, that objectss seem to make holes in the shadow. So either go for Z-Fail (which won't work if you enter the volume) or cap your shadow volumes (front and back-cap needed). Capping should be straight forward, as you normally only need to duplicate all light-facing triangles for the front-cap and extrude those for the back-cap. That's not the best method, but it's the easiest.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Sep 15, 2004 10:00 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
for the moment the shadows seem to get only worse. I post the complete project here. Thanks in advance for your feedback on it. Maybe i am doing things all wrong or it is just an stencil mistake.


Dateianhänge:
Dateikommentar: the 3ds mesh used with texture (made by sos)
shadmesh.zip [229.16 KiB]
309-mal heruntergeladen
Dateikommentar: volume shadow test program source
shadowstest.zip [35.69 KiB]
303-mal heruntergeladen

_________________
http://3das.noeska.com - create adventure games without programming
Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Sep 15, 2004 12:27 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
It seems that the biggest (maybe THE) problem right now is that your silhouette determination is not working as it should. I've changed your demo to show me the silhouette edges as lines, and directly saw that there's a problem :
Bild
I've marked some errors with red arrows. A silhouette edge should only occure where a border is between a triangle that faces the light and one that doesn't face the light. But as you can see, you have also silhouette edges between two triangles that are both facing the light. Those edges also get extruded and change the count of the stencil value, which will cause wrong results. So check your silhouette determination. I stronlgy suggest you to look at the demo from delphi3d.net, as he does all necessary things with an ASE-file and that's not hard to change to 3DS. One thing he does that you don't is for example the optimization of the meshes for shadow volume generation. Without that, your scene will also generate errors.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Sep 15, 2004 13:41 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
another question if i use zfail can i then forget about zpass? Or do i need both and need to determine which one to use per mesh and lightpos?

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Sep 15, 2004 13:45 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
No, you can only use zFail, cause that works all the time. But you normally determine if you need zFail or zPass and only render zPass when in the shadowvolume. That's because zFail eats more performance, as you need to cap the volume, what also results in more fillrate getting burned. But you normally can get away (I do that too as of now) with only zFail.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Sep 15, 2004 14:08 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
This is how things look now:

How do you render the outlines? Replacing the gl_triangles wit gl_lines in endshadow? I seem to get lines and not the triangle like things you get (bet then i changed my code in between) I redownload the version i uploaded...


Dateianhänge:
Dateikommentar: Wrong stencil count
wrong.jpg
wrong.jpg [ 48.68 KiB | 5881-mal betrachtet ]

_________________
http://3das.noeska.com - create adventure games without programming
Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Sep 15, 2004 14:21 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
In T3DSMesh.CastShadow, I changed this :
Code:
  1. glLineWidth(5);
  2. glEnable(GL_LINE_SMOOTH);
  3. glbegin(GL_LINES);
  4. ...
  5. glVertex3f(fvertex[p1].x, fvertex[p1].y, fvertex[p1].z);
  6. glVertex3f(fvertex[p2].x, fvertex[p2].y, fvertex[p2].z);
  7.  

And removed all other vertex calls. This will show you all edges in that function.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Sep 15, 2004 14:31 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
ok, i see them now also, now i have some feedback on trying to fix visibility....

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Sep 15, 2004 17:47 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
how do i determine if face is visible:

First i determine if a face is lit by the light or not:

Code:
  1.  
  2. procedure T3DSMesh.PrepareShadows(lp: T4dPoint);
  3. var
  4.   i: gluint;
  5.   side: glfloat;
  6. begin
  7.     if FNumIndices > 0 then
  8.     begin
  9.   //determine if an face is lit by the light or not
  10.   for i := 0 to (fnumIndices DIV 3) - 1 do
  11.     begin
  12.     side := FFaces[i].Plane.a*lp.x + FFaces[i].Plane.b*lp.y
  13.       + FFaces[i].Plane.c*lp.z + FFaces[i].Plane.d*lp.w;
  14.     if side > 0 then
  15.      begin
  16.       Ffaces[i].visible := true
  17.      end
  18.       else
  19.      begin
  20.       Ffaces[i].visible := false;
  21.      end;
  22.     end;
  23.   end;
  24. end;
  25.  


Now for the lit faces i have to find the neighbouring faces that are not lit. Then i found an edge. That has to be rendered. This is what i am supposed to be doing on drawing the siloute i it looks ok now but still the shadows look wrong.

This is my changed castshadow routine:
Code:
  1.  
  2. procedure T3DSMesh.CastShadow(lp: T4dPoint);
  3. var
  4.   i, j, k, jj: GLuint;
  5.   p1, p2: GLuint;
  6.   v1, v2: T3DPoint;
  7. begin
  8.   if FShadDisplaylist > 0 then glcalllist(FShadDisplaylist)
  9.   else
  10.   begin
  11.  
  12.     if FNumIndices > 0 then
  13.     begin
  14.  
  15.     glbegin(GL_QUADS);
  16.   j:=0;
  17.   //use lit faces to render the shadow volume
  18.   for i := 0 to (FNumIndices DIV 3) - 1 do
  19.     if Ffaces[i].visible then
  20.       for j := 0 to 1 do
  21.         begin
  22.          k := Ffaces[i].neighbour[j];
  23.          //an edge occurs when the other face is not visible...
  24.          if (not Ffaces[k-1].visible) then
  25.           begin
  26.           p1 := Ffaces[i].vertex[j];
  27.           jj := (j+1) mod 3;
  28.           p2 := Ffaces[i].vertex[jj];
  29.  
  30.           v1.x := (fVertex[p1].x - lp.x) * extend;
  31.           v1.y := (fVertex[p1].y - lp.y) * extend;
  32.           v1.z := (fVertex[p1].z - lp.z) * extend;
  33.           v2.x := (fVertex[p2].x - lp.x) * extend;
  34.           v2.y := (fVertex[p2].y - lp.y) * extend;
  35.           v2.z := (fVertex[p2].z - lp.z) * extend;
  36.  
  37.           glVertex4f(fvertex[p2].x, fvertex[p2].y, fvertex[p2].z,1.0);
  38.           glVertex4f(fvertex[p1].x, fvertex[p1].y, fvertex[p1].z,1.0);
  39.           glVertex4f(fvertex[p1].x + v1.x, fvertex[p1].y + v1.y, fvertex[p1].z + v1.z,0.0);
  40.           glVertex4f(fvertex[p2].x + v2.x, fvertex[p2].y + v2.y, fvertex[p2].z + v2.z,0.0);
  41.  
  42.           end;
  43.         end;
  44.  
  45.         glend;
  46.    end;
  47.    end;
  48. end;
  49.  


zfail still looks wrong
zpass almost looks good

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Sep 15, 2004 22:07 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
Have you implemented the optimizations for the mesh I've posted on the first page? Otherwise you WILL get shadow errors, as 3DS sometimes have duplicate vertices in them, and the function I posted fixes that.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Sep 15, 2004 23:08 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
it did not help, but (like everything :x ) i may have implemented it wrong. Here it is:
Code:
  1.  
  2. function glCompareVertex(v1,v2: T3DPoint): boolean;
  3. begin
  4.   Result := (Abs(v1.x - v2.x) < 0.0001) and
  5.             (Abs(v1.y - v2.y) < 0.0001) and
  6.             (Abs(v1.z - v2.z) < 0.0001);// and
  7. //            (Abs(1.0 - 1.0) < 0.0001);           //??
  8. end;
  9.  
  10. function T3DSMesh.FindVertex(const v: T3DPoint): Cardinal;
  11.   var
  12.     ivert: Integer;
  13.   begin
  14.     Result := 0;
  15.     for ivert := 0 to FNumIndices-1 do
  16.     begin
  17.       if glCompareVertex(v, fvertex[ivert]) then
  18.       begin
  19.         Result := ivert;
  20.         Exit;
  21.       end;
  22.     end;
  23.   end;
  24.  
  25. procedure TAll3DSMesh.OptimizeTriangleList;
  26. var
  27.   itri: Integer;
  28.   m: integer;
  29. begin
  30.   for m := 0 to FNumMeshes - 1 do
  31.   begin
  32.     if FMesh[m].FNumIndices > 0 then
  33. for itri := 0 to (Fmesh[m].FnumIndices div 3) -1 do
  34. begin
  35. Fmesh[m].fFaces[itri].vertex[0] := Fmesh[m].FindVertex(Fmesh[m].Fvertex[Fmesh[m].fFaces[itri].vertex[0]]);
  36. Fmesh[m].fFaces[itri].vertex[1] := Fmesh[m].FindVertex(Fmesh[m].Fvertex[Fmesh[m].fFaces[itri].vertex[1]]);
  37. Fmesh[m].fFaces[itri].vertex[2] := Fmesh[m].FindVertex(Fmesh[m].Fvertex[Fmesh[m].fFaces[itri].vertex[2]]);
  38. end;
  39. end;
  40. end;
  41.  

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 48 Beiträge ]  Gehe zu Seite Vorherige  1, 2, 3, 4  Nächste
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 14 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.015s | 16 Queries | GZIP : On ]