@froyok@mastodon.gamedev.place
@froyok@mastodon.gamedev.place avatar

froyok

@froyok@mastodon.gamedev.place

Aka Lady Bloom.

Principal Product manager on Substance 3D Painter :substance:, but stay up at night to fiddle with shader stuff.

Speaking French/English.

#gamedev #art #unrealengine #substance #opengl

nobot

This profile is from a federated server and may be incomplete. Browse more on the original instance.

froyok, to gamedev
@froyok@mastodon.gamedev.place avatar

New thread: I'm building my own game engine !

The goal is to support the needs for my custom FPS game project. 😄

Feature set goal:

  • Forward(+) renderer
  • Stencil/Shadow Volumes
  • Portals (with recursion)
  • FXAA and MSAA
  • Oren-Nayar diffuse shading
  • PBR Specular/Gloss workflow
  • Fancy Post-Effects (ex natural Bloom, SSAO)
  • HDR reflections (parallax corrected cubemap) + proxies
  • Blurry glass/window (like Doom 2016)
  • Parallax/Relief mapping + shadow

froyok,
@froyok@mastodon.gamedev.place avatar

Alright, the black/granular spots are related to z-buffer precision issues. I guess I will have to switch to a non-linear buffer at some point.

I hacked a fix meanwhile by pushing inward the shadow volume mesh faces.

The debug view of my volume is interesting to look at at least.

froyok,
@froyok@mastodon.gamedev.place avatar
froyok,
@froyok@mastodon.gamedev.place avatar

New step ! 🥳

Now that my shadow volume generation isn't borked anymore (and works with open meshes) I moved on to properly support the light itself with the shading.

Took the opportunity to rewrite my PBR stuff from scratch (ditching LearnOpenGL in favor of Filament).

A looping gif of an orange point light moving around a teapot floating above a plane and casting shadows.

froyok,
@froyok@mastodon.gamedev.place avatar

There a few issues I need to figure out now. One being the shadow volume stretching triggers too soon on some polygons.
It's likely because I use the face normal instead of the vertex normal to decide or not to offset the quads.
I wonder how old games avoided that (or if they ever did per-pixel lighting with shadow volumes ?)

Maybe you have a suggestion @TomF ? 😊

A close-up screenshot of shadow volumes on the Pixar teapot mesh, showing hard edges on the shadow conflicting with the smooth shading. This time with the debug wireframe of the shadow volume.

froyok,
@froyok@mastodon.gamedev.place avatar

One solution I had in mind was to use vertex pulling to discard drawing too many degenerate quads, as an optimization pass.

Maybe this could be the solution too to evaluate multiple vertices at once and avoid triggering the offset if the vertex of a triangle can still see the light ? 🤔

froyok,
@froyok@mastodon.gamedev.place avatar

While I'm still scratching my head on how to fix that smooth shading vs shadow volume masking, I at least got the point light attenuation working on ! 😃

A looping gif showing a point light doing rounds in a scene with a floor, pillars and a teapot and casting shadows while its radius grows and shrinks.

froyok,
@froyok@mastodon.gamedev.place avatar

So, for the smooth shading I went with a stupid "trick".

One solution often recommended it to offset the mesh surface along its vertex normal. But that created many issues with my degenerated quads on the shadow mesh.

So instead, I went with a global offset but along the light origin and the camera position. It's not as good, but seems to be good enough ?

On the bunny which has many wonky triangles, I don't have artifacts anymore. On a sphere it's perfectly smooth now ! 🥳

A screenshot of my game engine showing the classic bunny mesh with smooth shading.

froyok,
@froyok@mastodon.gamedev.place avatar

Next steps will be thinking about z-pass vs z-fail.

Modern rendering methods for stencil shadows avoid z-fail altogether and use another way to detect if the camera is inside a shadow volume.

The most recent one is about doing ray intersection with the mesh triangle to check if is between the light and the camera. They use a geometry shader to increment an atomic counter when that happen. Then use the value with the stencil to adjust the shadowing behavior.

froyok,
@froyok@mastodon.gamedev.place avatar

I want to do the same, but initially I wanted to use compute shader to do the test since I don't have access to geometry shader.

Now I wonder if vertex pulling and doing this intersection test in the same pass as the vertex shader that generate the volume wouldn't be better ?
I was planning on using the pulling to discard the rendering of some degenerate quads. So that could be great to do all that at the same time ? 🤔

froyok,
@froyok@mastodon.gamedev.place avatar

Ha, but the vertex shader is ran before any depth test, so I could potentially evaluate triangles that may not be visible. 🤔

I need to think about this a bit more.

froyok,
@froyok@mastodon.gamedev.place avatar

In the end I had to use a compute shader (can't use atomic counter in vertex/fragment with the framework I use).

So here is a (borked) version of my compute shader doing ray intersection with my shadow meshes to see if they intersect between the light/camera.
In which case it flips the shadow mask. Allowing to detect if the camera is inside a volume.

(Not yet reliable, as my intersection test was done in a hurry.)

Video showing the shadow volume rendering and how the shadows display properly when the camera is shadowed as well. It sometimes look wrong however depending on the camera angle and position.

froyok,
@froyok@mastodon.gamedev.place avatar

"Look mom, no z-fail !" :D

froyok,
@froyok@mastodon.gamedev.place avatar

What's great is that now I have a setup with a compute shader, I should be able to expand its usage to more stuff.

Grouping several task in one big compute for example.
Right now I pre-generate degenerate quads for the meshes, but maybe I could generate the silhouette mesh from the compute. Do the intersection tests as well as the same time... and maybe even raster with it ?

(Software raster is another can of worms, not sure I wanna open that yet.)

froyok,
@froyok@mastodon.gamedev.place avatar

Also I do one compute pass per mesh drawn, but I could group all the meshes in a single big SSBO and iterate over all the triangles in a single pass instead.

froyok,
@froyok@mastodon.gamedev.place avatar

So, this is the z-pass only stencil shadowing working, with an additional triangle intersection test (done on CPU for now).

Shadowed to non-shadowed transition is now fully smooth ! :)

(By nature, going into a shadowed area would invert everything, shadows would become lit.)

Video showing the camera moving around cubes from outside a shadow volume to inside one, without the rendering being inverted (shadowed are becoming lit).

froyok,
@froyok@mastodon.gamedev.place avatar

Okay, the whole system works but I'm now facing a bug...

When the camera is perfectly parallel/sitting on the face of a shadow volume it leads to masking issue.

As soon as I move a bit away, everything is good.

I wonder how to fix that. 🤔

Video showing strange flickers in the shadow even when the camera is move left/right or looking around.

froyok,
@froyok@mastodon.gamedev.place avatar

Alright, ported the code back to the compute shader and it globally works !

I stumbled upon a corner case however, I need to rethink how I handle non-closed meshes.

froyok,
@froyok@mastodon.gamedev.place avatar

There are a few papers that tackles this subject, so I'm not worried.

The biggest thing that worries me right now is the z-fight when the camera overlap a shadow volume triangle.
Stumbled on it again today in Sponza.

I wonder if I could avoid it with some magic jitter placed in the right place. 🤔

froyok,
@froyok@mastodon.gamedev.place avatar

Meanwhile, little breakdown of my system: it takes 0.5ms to render a light on my RX 5600 XT:

  • 0.09ms for the compute based ray-casting
  • 0.3ms for drawing shadow volumes
  • 0.02ms for setting up stencil buffer
  • 0.07ms for drawing meshes with PBR shading

Video showing a light moving around the sponza scene. A teapot, sphere, pyramid and bunny mesh in the middle cast shadows on the floor.

froyok,
@froyok@mastodon.gamedev.place avatar

Okay, took some time today to finally try out Tony McMapface tone curve in my engine.

Compared to my custom one (inspired by old stuff in Kajiya), it really behave better, look at the blue being really blue !

Screenshot from my game engine showing a blue light lighting up a bunny and pillars, there is a very bright red cube as well. This is using Tony McMapface.

froyok,
@froyok@mastodon.gamedev.place avatar

Been a while since I wrote about this.
The compute rewriting is taking some time. But I'm mostly there !

So now I have several compute dispatch that process the scene meshes each frame, per light, and write that into a common buffer.
Then a single drawcall render it into the stencil buffer.

froyok,
@froyok@mastodon.gamedev.place avatar

I don't use degenerative quads anymore, it's almost fully runtime !

On blender export side I only add the index for the neighbor vertex of an edge per triangle.

So my map layout is:

  • Index1
  • Index2
  • Index3
  • Neighbour1
  • Neighbour2
  • Neighbour3

Then the compute pass does the rest.

froyok,
@froyok@mastodon.gamedev.place avatar

With that neighbor vertex info I can check if an edge is at the border between light and shadow and decide or not to generate a silhouette quad.

That works... but it's a bit borked because right now I generate too much quads. 😅

A screenshot of game engine showing the wireframe of a shadow volume from a sphere from a back view. It shows that each quads generate a line/quad and the view is very busy.

froyok,
@froyok@mastodon.gamedev.place avatar

I got most of the compute thingy working and performance look promising, but... I have some random edges not projecting leading to some flipping.

I'm unsure yet how I could make this more robust. It happens even on simple cubes.

froyok,
@froyok@mastodon.gamedev.place avatar

Fixed.
Banged hard my head on this one, turns out I just needed to add some epsilons in the right places. :)

Looping gif of a moving point light outside of the image casting shadow on a pillar and the floor.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • JUstTest
  • InstantRegret
  • mdbf
  • ethstaker
  • magazineikmin
  • cubers
  • rosin
  • thenastyranch
  • Youngstown
  • osvaldo12
  • slotface
  • khanakhh
  • kavyap
  • DreamBathrooms
  • provamag3
  • Durango
  • everett
  • tacticalgear
  • modclub
  • anitta
  • cisconetworking
  • tester
  • ngwrru68w68
  • GTA5RPClips
  • normalnudes
  • megavids
  • Leos
  • lostlight
  • All magazines