Deferred Rendering Project WT EngineMG

Some time ago I started to port an XNA 4.0 project to MonoGame. The project is just a Framework, where I can try out some stuff in a deferred rendering context. The port so far went successful, only couldn’t get the MD5 model animation working.
At the moment I try to improve some parts of the code and now and then I try to implement new things.
Since it is now a MonoGame Project, I thought I show some screenshots from time to time, which I will post to this thread :slight_smile:

So here you see a simple model which is lit by a point light:

2 Likes

Cool stuff! Looking forward to the stuff you can do with the deferred rendering pipeline

Here is a small update. For some time I had an issue with the lighting:
In the GBuffer compose step (where the GBuffer data is used to generate the final image) I use a parameter for the AmbientIntensity. The value gets applied to everything, which should not be the case for a SkyBox. The SkyBox should just be rendered without lighting applied to it.
In @kosmonautgames deferred renderer I found shader functions for encoding and decoding a material type. So now I use this technique when rendering the models. Then in the GBuffer compose step I can apply lighting only to the models and output the SkyBox diffuse color without modification. Some Images:

1.Old version: AmbientIntensity at 1.0f affects both plant model and SkyBox
2.Old version: AmbientIntensity at value lower than 1.0f affects both plant model and SkyBox
3.New version: AmbientIntensity at value lower than 1.0f only affects plant model


1 Like

With the use of three directional lights, the models look like this:

1 Like

Great progress!

I think I encode several things in one value, not only mat ids and sometimes precision is not good enough, I wanted to look inti proper float encoding once I have a working computer again, but I think it’s serviceable right now

Right now this is a pretty primitive system, and it would make more sense to have 8 bits split into 4 bits for metallic (I think that was the other thing) and 4 for mat types.
But I’m not sure how well that is preserved in the 8bit output, since the gpu stores that as a float?!

Thank you :slight_smile:

Yes that’s right, “metalness” and “materialtype” get encoded to one float value. At the moment I encode the value 3 as the material type. Depending on the encoded metalness value, after decoding I get different values for the material type. For metalness = 0.0f I get materialtype = 2. For metalness = 2.0f I get materialtype = 4.

Metalness can only range from 0 to 1 though, that’s the rules for the encryption

But that’s fine since a material can’t be more than 100% metallic

Ah, ok. I should have looked at the source in more detail. Now it works as expected.

Sorry, but you’re wrong, I am at least 150% metal AF :wink:

Great progress on the engine, looks great!

Thank You :slight_smile:

At the moment I’m having an Issue with white noise occuring, not sure what is causing it. Here is a screenshot showing the problem:

have you looked through your rendertargets?

Could it be that the encryption works wrong and this pixel is identified as sky?

Your right! I checked it by switching the SkyBox on and off and the pixel color changed (from SkyBox diffuse to RenderTarget clear color). But why does the encryption fail at these pixels?

do you use the other part at all? The one that i used for metallic?

Set it to something <0.9

I set the metalness value to 0.5f at the moment and calculate the encoded value like this:

float EncodeMetalnessAndMaterialTypeFunction(float metalness, float mattype)
{
    return metalness * 0.1f * 0.5f + mattype * 0.1f;
}

Decoding the materialType like this:

float DecodeMaterialTypeFunction(float input)
{
    input *= 10;
    return trunc(input);
}

Composing like this:

...
    if (abs(materialType - 3) > 0.1f)
    {
        output.Diffuse.xyz = diffuseData.xyz;
        output.Diffuse.w = 1.0f;
    }
    else
    {
        output.Diffuse = Ambient + Diffuse + Specular;
    }
...

do you even use metalness?

No, at the moment I don’t use this value.

Then you don’t have to encode it like this

Just use this

float EncodeMetalnessAndMaterialTypeFunction(float metalness, float mattype)
{
return mattype * 0.1f;
}

If I only encode the materialType, the decoded value is one less than in the case where I also encode the metalness as 0.5f. The “white noise” is stil there…

I don’t know then, maybe you write something else in the spot, too.