Board index FlightGear Development Effects and shaders

Geometry shader for cliffs

An exciting "new" option in FlightGear, that includes reflections, lightmaps, the particle system etc.. A lot is yet to be discovered/implemented!

Re: Geometry shader for cliffs

Postby frtps » Mon Apr 13, 2020 2:50 am

The saga continues. It turns out that the nice cliff lighting in my above post was a lucky choice of view position - I was mistakenly mixing eye coordinates and model coordinates in the calculations and consequently if I was looking from roughly the direction of the sun things looked sort of OK, but the lighting changed depending on the view point. Further investigation has revealed better answers to my original questions:

frtps wrote in Sun Mar 29, 2020 7:16 am:
1. I am perturbed by a comment in the urban-ALS.vert shader that world scenery 2.0 generates incorrect binormals, normals and tangents. Is this still the case?


The situation is a little nuanced. The OSGUtil::TangentSpaceGenerator (TSG) that FG uses will defer to any normals already present in the geometry, and does not recalculate normals if any are supplied. As the normals calculated by Terragear are loaded before TSG is run, requesting normal generation in an effect is a no-op. Furthermore, binormals and tangents based on the UV coordinates of the vertices are corrected by TSG to make them perpendicular to the supplied normals. Somewhat more puzzling, if normals are not supplied in the geometry, the normals that are calculated by the TSG do not seem to reach the vertex shader pointing in the right direction. I speculate that a coordinate transformation is missing.

2. If, say, I calculate the binormal and tangent directions in the vertex shader, is it true that these will be averaged for each vertex across all triangles having that vertex, or only those triangles that the shader is called with? Obviously I don't want the flat areas at the top of a cliff to influence the normal that is then interpolated across the cliff face.


I was a bit confused. The normals for each vertex are assigned by Terragear and averaged over all triangles (of whatever material) containing the node. The binormals and tangents are calculated by TSG for each triangle and are identical for each vertex belonging to the triangle. The only averaging taking place in the OpenGL pipeline is within a triangle, not between triangles.

3. Is there a way to get the plain old normal for the triangle that a fragment is part of rather than some interpolated normal?


I've found one way: if the simgear code that calls TSG is altered to remove the normals while calling TSG, the generated binormals and tangents will not be corrected against the "terragear" normals. If the cross-product of these is performed in the vertex shader, a normal perpendicular to the face results. I have done this and confirmed that it works based on the value of normal dot lighting direction in the course of a day.

So what does this mean for cliffs? Well (with a relatively non-intrusive change in the call to TSG in Simgear) I can light them properly. However, the vertical divisions between cliff faces become quite stark for certain lighting directions, and I will now explore either adding some noise or some further nodes along and down the cliff face.
frtps
 
Posts: 145
Joined: Sun Aug 05, 2018 10:58 am

Previous

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 7 guests