DGL
https://delphigl.com/forum/

stencil shadows again ... (outlines)
https://delphigl.com/forum/viewtopic.php?f=19&t=4076
Seite 1 von 1

Autor:  noeska [ Mi Apr 27, 2005 18:50 ]
Betreff des Beitrags:  stencil shadows again ... (outlines)

This week i started again on understanding shadow volumes. What went wrong in my previous attempt is that i never got the outline properly calculated. So i need to get that right first.

So what do i have. A list of indexes to vertexes and normals (the gl3ds format). index 1 2 3 make a face 4 5 6 make another face, etc. So from that i need to create an edge list. if i render poly lines using the edge list i should be able to render polygon shape representing the outline (Silhouette) of the mesh.

Looking at the wiki:
2 benachbarte Flächen vom Objekt, bei denen man untersuchen will ob ihre Zwischenkante zur Silhouette gehört.
Hopefully i can assume that faces are in order. If not how do i find out what faces are next to each other, comparing vertexes?

Die Position des Betrachters.
That is the light, or when i just want to render an outline, the camera position.

Die Position auf die der Betrachter sieht. (Intelligenterweise, dass Zentrum des Objekts dessen Silhouette man berechnen will.)
The coordinate where the mesh is rendered on screen (ps how bad is it when it is not right?)

The calculating part i can follow, but
Außerdem sollten Kanten die nur zu einem Polygon gehören ebenfalls zur Silhouette gezählt werden.
How do i detect that?

Thanks for your answers in advance.

Autor:  Flash [ Mi Apr 27, 2005 19:18 ]
Betreff des Beitrags:  Re: stencil shadows again ... (outlines)

noeska hat geschrieben:
Looking at the wiki:
2 benachbarte Flächen vom Objekt, bei denen man untersuchen will ob ihre Zwischenkante zur Silhouette gehört.
Hopefully i can assume that faces are in order. If not how do i find out what faces are next to each other, comparing vertexes?


Yes. This seems to be the only method. Number your vertices and look if an face uses 2 vertices a other vertex uses, too.


noeska hat geschrieben:
Die Position des Betrachters.
That is the light, or when i just want to render an outline, the camera position.

Correct.

noeska hat geschrieben:
Die Position auf die der Betrachter sieht. (Intelligenterweise, dass Zentrum des Objekts dessen Silhouette man berechnen will.)
The coordinate where the mesh is rendered on screen (ps how bad is it when it is not right?)

You can assume this. But a better way would be to make 2 vectors. one for every vertex of an edge and then take an average vector. This is sure slower because you have to calculate the vector for every edge.

noeska hat geschrieben:
The calculating part i can follow, but
Außerdem sollten Kanten die nur zu einem Polygon gehören ebenfalls zur Silhouette gezählt werden.
How do i detect that?

Normal 3D Object have no such edges (because the are closed). But you can count again if two faces use the same edge (see question2)

Autor:  LarsMiddendorf [ Do Apr 28, 2005 00:50 ]
Betreff des Beitrags: 

It can be easier:

for each triangle facing away from the light:

1) Draw the original triangle with reversed vertex order.
2) Draw the extruded triangle.
3) for each edge 0..2
if edge hasn't neighbour triangle => Draw Extruded Edge
if edge has neighbour triangle
if neighbour triangle is facing toward the light => DrawExtruded Edge

It is not wrong to extrude always all three edges of all triangles and to ignore the silhouette. It is only slow. The silhoutte can be used as an optimization when two neighbour triangles are both extruded to avoid drawing the same triangle facing front and facing back and increasing and decreasing the value in the stencil buffer.

Instead of extruding on the CPU you can duplicate your vertex list and set w of all duplicated points to zero. A vertex program can use an infinite projection matrix to extrude all vertices with w=0 or project the point on a plane a the light's radius.

Pseudo Code:
Code:
  1.        
  2. for i:=0 to Length(Triangles)-1 do
  3. begin
  4.   if Plane_Dist(Triangles[i].Plane,LightPos) <0 then
  5.   begin
  6.     // 1)
  7.     glBegin(GL_TRIANGLES);
  8.     glVertex3fv(Triangles[i].Points[2]);
  9.     glVertex3fv(Triangles[i].Points[1]);
  10.     glVertex3fv(Triangles[i].Points[0]);
  11.     glEnd();
  12.     // 2)
  13.     glBegin(GL_TRIANGLES);
  14.     glVertex3fv(ExtrudePoint(Triangles[i].Points[0]));
  15.     glVertex3fv(ExtrudePoint(Triangles[i].Points[1]));
  16.     glVertex3fv(ExtrudePoint(Triangles[i].Points[2]));
  17.     glEnd();
  18.  
  19.     for j:=0 to 2 do
  20.     begin
  21.       edge_triangle := triangles[i].edge[j];
  22.       if (edge_triangle =-1) or (Plane_Dist(Triangles[edge_triangle].Plane,LightPos)>0) then
  23.       begin
  24.       glBegin(GL_TRIANGLE_STRIP);
  25.       glVertex3fv(Triangles[i].Points[j]);
  26.       glVertex3fv(Triangles[i].Points[(j+1) mod 3]);
  27.       glVertex3fv(ExtrudePoint(Triangles[i].Points[j]));
  28.       glVertex3fv(ExtrudePoint(Triangles[i].Points[(j+1) mod 3]));
  29.       glEnd();  
  30.       end;
  31.     end;    
  32.  
  33.   end;
  34. end;
  35.  

Autor:  Flash [ Do Apr 28, 2005 15:01 ]
Betreff des Beitrags: 

What do you mean with "extrude" the triangle? :oops:

Autor:  noeska [ So Mai 08, 2005 10:39 ]
Betreff des Beitrags: 

on the inet i found: robust, geometry-independent shadow volumes by graham aldridge and eric woods. They seem not to construct an edge list. @Lars Middelnorf: is that the way you do it?

Anyway it does not seem to work for me. You can find my code at: http://www.noeska.com/downloads/dglmodel.zip

Most important are:
- gldraw in glapp.pas
- Tall3dsMesh.loadmsafromstream at //build up edges (gl3ds)
- the Tedge and Tface structures (gl3ds)
- T3dsmesh.rendershadow
- T3dsmesh.faceslight
- extendvertex

I am about to give up :cry:

EDIT:
this evening i decided to have another go. Now it works for some camera positions for some lightpositions. I think things go wrong when the camera is inside a shadow volume. For that case i believe i should 'reverse' the stencil rendering but then the results seem to be right when inside a shadow volume but not anymore when outside a shadow volume. :? I uploaded the result sofar at http://www.noeska.com/downloads/dglmodel2.zip .

PS do not use the gl3ds.pas inside the archive as only milkshape static mesh is working, the rest is broken.

Autor:  Frase [ Di Mai 10, 2005 17:21 ]
Betreff des Beitrags: 

At neHe is a Tutorial about doing Stencil Shadows. Delphi-Code is also available there.

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/