They’re flipped in EffectParameter, check out the get and set functions for Matrix. For OpenGL there are no matrices vecause of how MojoShader works. It decomposes the matrix into an array of floats basically.

So we know the position of the surface of the sphere per pixel.
We also know the position of the light center, the light radius and the camera position.

Therefore we can calculate the depth of the sphere with a pythagoras / cos(alpha) = b / c

c = distance from camera to light.

We can get the cos by making the dot product of (distance from camera to sphere surface , distance from camera to light center).

This way we can get the “b” or distance from camera to halfway between sphere surface entry and exit.
We can double the distance from the surface entry to b and get the whole travel distance for out light through the medium.

We just have to integrate some distance dependent function or fake some integral from the entry of the volume to the exit.

There are cases to consider, for example if the exit is early because an object is closer than the exit of our volume.

And if the camera is inside the volume the algorithm has to change a bit, too, since we now draw with flipped polygons, so our information is about the volume exit and not the volume entry any more.

There may be a better way to do this, but I just sat down with a piece of paper and did the math.

The shadowed algorithm is much much simpler, but much more expensive - we basically raymarch through the volume and check each raystep against our shadow map.

One could also raymarch for unshadowed volumes, but that would be needlessly expensive.

This is really cool kosmo do you have examples that use the vertex shader to do mesh warping. I took a long break because i was having problems getting the shaders to work properly with custom vertex data. Specifically the vertex shaders.

Cosmo when i tried to run your app i got a null reference first chance exception, at the render.UpdateResolution call. It looks like the clientsizedchange is triggering it, before its initialized in game1 here.

screenManager.UpdateResolution(); calls _renderer.UpdateResolution(); but it is null.

To fix that. I altered the line in the clientsized changed block with a bool to skip it when its null. so it runs thru the initialization first which it does after initialize it should fire it again which it seems to.

In game1.cs

bool isInitializedOnce = false;

in private void ClientChangedWindowSize(object sender, EventArgs e) {

…
if (isInitializedOnce) { screenManager.UpdateResolution(); }

in protected override void Initialize() { just before base.initialize

…
isInitializedOnce = true;

the above may actually just be a little monogame quirk, i don’t think was ever fixed basically the receiver is called, when its added to the sender windowclientsizedchange, then later on as well after load, i forget exactly, but im pretty sure its a quirk, anyways.

Then this line shown below errors in the class Shaders with a sharpdx (hr) handle result code