Deferred Engine Playground - download

I don’t remember, I’ll have a look when I find time.

SSAO is half res but the blur should be full res, for upsampling to work correctly.

The ScreenSpaceEffectParameter_InverseResolution is not stating the actual output resolution in this case. It just states the texel size of the input texture which affects the width of the blur.
So for the full res effect to correctly space out pixels i need to supply the texel size of the half res target.

The second one shouldin theory not have the *0.5f at the end, this would make the kernel smaller. I guess i played around with it and found it to work well …?

just found some issue, on the left picture show the initial scene when i start the program, on the right picture shown when i move the direction light abit. The shadow seem go wrong when i edit position, it suppose to be block by the middle wall. Any idea?

Hey @bettina4you

Can you tell me how you went about integrating SharpDX directly? Do you mix the approach with some things still done by monogame?

Hi kosmonautgames,

nice to hear from you. I still work on your engine. I have succesfully integrated a windows form with a dynamic gridview and treeview so that i can hirarchically visualize Entity, Model, Mesh, MeshPart and all their attirbutes …

Now to you question. I still work under the namespace of monogame. After adding the SharpDX references i mix the code.

But this must be done carefully, because monogame under the hood works different from what i have been used in SlimDX.

In monogame most of the time things are not applied to directx until a real draw call is started an then there are mechanism which hide some things you would normally do directly.

The trick i did for example was to write a converter back from monogame rasterizer state to sharpDX rasterizer state.

So i just create a SharpDX rasterizer state be feeding my method with your monogame rasterizer state. (and so on)

Once you know how to translate things, this is no more necessary but “for the conversion” process this was helpfull.

I will send you a community mail with that part of my Code. I hope this could be a little help.

You are a professional and will right away understand the code.

@kosmonautgames This is awesome but I can’t find any mention of the license… any chance you could add a MIT license to this project?

Sure, I guess any license is better than nothing. I recall that someone specifically said „no MIT please” but I don’t remember what that was about.

EDIT: Ah I guess I would have to spend a little more than a minute since I use Sponza atrium and some assets which have their own license

Hi! I’ve been inspecting the engine code for days and I’d like to thank you a lot for such a valuable asset. You’ve teached a lot of tricks to an old dog :wink:

However I’m reaching the point of “I won’t be able to do anything like this on my own” and thoughts are rapidly moving into “I’ll just take Kosmonaut’s code and adapt it to my game” :slight_smile: So as people has been asking I’d love if you please could include a license to the project to know what to expect in the future when reutilizing the code.

(btw, I think you can have different licenses for a project, i.e. one for the Sponza files and a different one for your code)

I also have a question about shadows for lights. It seems there are 3 configurations selectable with g_UseDepthStencilLightCulling: None, DepthBuffer and DepthBuffer+Stencil. However I’m unable to appreciate any difference between the three, other than DB+Stencil takes like 50% more time on my HW.

Could you please give an overview explanation what are the differences between those methods and their strengths/weaknesses?

Thanks!

Hi,

Thanks for the interest!

I am on mobile right now, I’ll get back to your question when I find time.

I did add a license to the github repo (MIT)

I’ve heard complaints about mit before, but i just went ahead with it since it’s better than nothing. I haven’t had time to review the others

Hi,

thanks for your time, there’s no hurry in any of my questions.

I’ve spent the weekend transplanting you point lights into my game, they look great, thanks again! (although it’s a little sad that I’ve probably spend more time transplanting them than you doing them, but hey… let’s be positive :wink: )

I’m targetting the directional light now but I’m observing a problem. I’ve taken the source code at github as is, commented out all point lights, and removed comment for the directional light. The light looks good until moved. When moved, some shadows disappear.

I’ve made a small private video to show it: https://youtu.be/j3BOVjIEmNA

After making the video I found that the directional light “going up” shown at the end of the video can be alleviated with the shadowDepth parameter so you can ignore that part. And anyways, I won’t need a shadow so high.

However I’m unable to understand nor find why the shadow disappears once you move the directional light.

At first I though that maybe the top roof geometry was being skipped because of frustum culling, but I removed the culling forcing all objects to be rendered always ( bool isUsed = true; in MeshMaterialLibrary.Draw ) but the problem persists.

Any ideas on what could be causing that? I’ve been playing a bit with the parameters but I’ve found no combination that works.

Thanks a lot!

I have a function where I check what shadows need updating and it checks for objects moving or lights moving. I can’t look it up right now, but the problem should be there (on mobile)

It’s in rendermodules/shadowmaprendermodule.cs ln 302ff I think

Hi Kosmonaut, thanks for the answer. I tried to remove all ifs so that it always enters the light generation, but the problem persists.

I’ve been having a look at it. I’m by not means an expert in this field, so take my message with a grain of salt ( lucky you, my blood pression is high and I can’t :slight_smile: )

I’ve rendered the shadowmap for the first frame and subsequent frames. It is rendered differently.

First shadowmap render:

Next shadowmap render:

If you look closer, the second shadowmap shows all the balls (including the ones that are below the roof). I think for some reason the depth buffer is not working well after the first frame. It’s like it’s rendered backwards, or maybe just not using the depth information at all (like DepthStencilState.None, but I suppose the shader doesn’t use the DepthStencilState.) Or maybe it’s near-clipping the roof (but I don’t think so because of the next image)

this image is curious and probably gives some clues about the problem:

I’m hopeful I’ll be able to nail the problem tomorrow :slight_smile:

p.s. in the screenshots I forgot to disable the point lights, so the floor level looks lighted and with shadows, but most of the light as well as all the ball shadows come from the point light.

I couldn’t resist until tomorrow :slight_smile:

commenting the following line makes the directional lights work:

if (!lightViewPointChanged && hasAnyObjectMoved)

in MeshMaterialLibrary.CheckShadowMapUpdateNeeds ~ line 478

maybe should be if (lightViewPointChanged || hasAnyObjectMoved) ?

yes you are probably right.

EDIT: I’m not sure about the problem, I couldn’t replicate it on a quick test. Maybe I didn’t delete all point lights.

weird, it happens to me all the time even without removing the point lights. Just git clone, uncomment the directional light (I have to change an enum otherwise won’t compile), run and move the light.

That’s something I thought last night that is also puzzling: The line I’m commenting is common to both Directional and Point lights. If it fails in Directional lights, why doesn’t have the same problem with Point lights, if most of the code is the same?

What MG version are you on? 3.7.0.1549 here I’ll try to update my drivers later just in case.

ah i understand your problem now. I thought all shadows would disappear. I will check it out.

I also went ahead and pushed the old experimental branch with some SDF stuff you can read about on the blog: https://github.com/Kosmonaut3d/DeferredEngine/tree/SDF
https://kosmonautblog.wordpress.com/2017/05/01/signed-distance-field-rendering-journey-pt-1/

3 Likes

I fixed the problem with this commit and i also fixed the SSAO aspect ratio bug.

2 Likes

Hi Kosmonaut,

I’m still playing with directional lights and I found banding when integrating it in several scenes of my game. After some dwelling I realized that the problem also appeared in the DeferredEngine, but only became aparent when switching to Default Material.

It’s very apparent in vertical walls but it’s also happening in the floor

Any ideas of what can be causing this? ZBuffer precision maybe?

Thanks!

Banding is a problem in most 3d engines to some extent (see unity/Unreal/CryEngine) and then have the light be very close to a surface.

It’s a very known issue because of shadowmap precision, you will find a lot of resources on that if you google shadow banding.

A typical way to change this behaviour, is to add a little bias for the shadowmap. You can change it by going into the console (or Gamesettings) and playing around with ShadowBias. Big values will lead to objects looking floaty though.

EDIT: I’ll make a patch that supports the changing of this value a bit better, i noticed the code was not good enough.

1 Like

thanks for the banding explanation, I was aware of the bias and floating objects, however all examples I saw on internet where showing this problem as “shadow acne”, so I wasn’t sure if this was the same problem.

New question :wink:

When you reconstruct the position with the depth buffer, i.e.

float3 currentPos = input.ViewDir * linearDepth;

what space is the resulting currentPos on?

I’m trying to adapt the cascade shadow map example from Tim Jones and requires the positions in world space, but I’m struggling to get that position in world space because I don’t quite understand what space I’m on in the first place.

Thanks again, and sorry for the flurry of questions!

Hi again!

I wasn’t searching for it, but I realized that changing the shadow filtering type of the directional light removed the banding. I think the banding in SoftPCF3x/5x is caused by CalcShadowTermSoftPCF, which apparently is not using the DepthBias.