Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UWP Shadow #1649

Closed
JuandreG opened this issue Sep 22, 2021 · 15 comments
Closed

UWP Shadow #1649

JuandreG opened this issue Sep 22, 2021 · 15 comments

Comments

@JuandreG
Copy link

Hello again.

I have 2 questions about shadows.

1: Why is the shadows that are casted on the inside of the model displayed on the outside too? How would I go about fixing this?

Inside:
Inside

Outside:
Outside

2: How can I get the shadow to be smooth and not show the stripes that it is showing?

This is how I create the ShadowMap3D:

var shadow = new ShadowMap3D(); shadow.AutoCoverCompleteScene = true; shadow.Intensity = 0.3; shadow.IsSceneDynamic = true;

Then I add the shadow.SceneNode to a SceneNodeGroupModel3D.

holance added a commit to holance/helix-toolkit that referenced this issue Sep 24, 2021
holance added a commit that referenced this issue Sep 24, 2021
Fix shadow is showing on the back of the object #1649
@holance
Copy link
Member

holance commented Sep 24, 2021

You probably want to adjust the shadow bias to reduce the stripes.

@JuandreG
Copy link
Author

I removed the packages from my project and reinstalled them but the shadows are still showing on the back of the objects.

Maybe I'm doing something wrong, did I update the packages correctly? I just uninstalled them then reinstalled them.

I'm also using 2 directional lights, can tis cause issues?

@holance
Copy link
Member

holance commented Sep 27, 2021

Is the model single layer or double layer? Could you provide the model for us to do the test?

@JuandreG
Copy link
Author

JuandreG commented Sep 27, 2021

I can send you a model yes. Can I send it to [email protected]?

@holance
Copy link
Member

holance commented Sep 27, 2021

You can upload in this issue or send to my email [email protected].

@JuandreG
Copy link
Author

I sent the file via email. Was not able to upload it here.

@holance
Copy link
Member

holance commented Sep 28, 2021

I am not able to reproduce the issue with your model. Could you provide your light setup?
One side with shadow.
image

Other side without shadow.
image

@JuandreG
Copy link
Author

JuandreG commented Sep 29, 2021

Here are the lights I add. I add the to SceneNodeGroupModel3D.

var light1 = new DirectionalLight3D(); light1.Direction = new SharpDX.Vector3(-213, -266, -308); light1.Color = Windows.UI.Colors.White; GroupModel.AddNode(light1.SceneNode);

var light2 = new DirectionalLight3D(); light2.Direction = new SharpDX.Vector3(213, 266, 308); light2.Color = Windows.UI.Colors.White; GroupModel.AddNode(light2.SceneNode);
If I remove light2 then the view is too dark on the one side. The model has PBR Material so AmbientLight is too bright.

This is how I open the model before adding it to SceneNodeGroupModel3D.

`using (var assimpContext = new AssimpContext())
{
var group = new SceneNodeGroupModel3D();

                using (var stream = new MemoryStream())
                {
                    await stream.WriteAsync(bytes, 0, bytes.Length);
                    stream.Seek(0, SeekOrigin.Begin);

                    var assimpScene = assimpContext.ImportFileFromStream(stream, "glb");

                    using (var importer = new Importer())
                    {
                        importer.ToHelixToolkitScene(assimpScene, out HelixToolkitScene helixScene);

                        if (helixScene != null)
                        {
                            var matrix = new SharpDX.Matrix();
                            matrix = helixScene.Root.ModelMatrix;
                            matrix.ScaleVector = new SharpDX.Vector3(100, 100, 100);

                            helixScene.Root.ModelMatrix = matrix;
                        }

                        foreach (var item in helixScene.Root.Traverse())
                        {
                            if (item is MeshNode m)
                            {
                                m.IsThrowingShadow = true;
                                m.IsMSAAEnabled = true;
                                m.CullMode = SharpDX.Direct3D11.CullMode.Back;

                                (m.Material as PBRMaterialCore).RenderShadowMap = true;
                                (m.Material as PBRMaterialCore).MetallicFactor = 0.3f;
                                (m.Material as PBRMaterialCore).AmbientOcclusionFactor = 2.5f;
                                (m.Material as PBRMaterialCore).ReflectanceFactor = 0.8f;
                                (m.Material as PBRMaterialCore).EnableAutoTangent = true;
                                (m.Material as PBRMaterialCore).RenderIrradianceMap = true;
                                (m.Material as PBRMaterialCore).RenderNormalMap = false;
                                (m.Material as PBRMaterialCore).RenderEnvironmentMap = false;
                                (m.Material as PBRMaterialCore).RenderAmbientOcclusionMap = true;
                                (m.Material as PBRMaterialCore).RenderAlbedoMap = true;
                                (m.Material as PBRMaterialCore).RenderRoughnessMetallicMap = true;
                                (m.Material as PBRMaterialCore).RoughnessFactor = 0.3f;
                                (m.Material as PBRMaterialCore).ClearCoatRoughness = 0.5f;
                                (m.Material as PBRMaterialCore).ClearCoatStrength = 2.0f;
                            }
                        }

                        group.AddNode(helixScene.Root);
                    }
                }

                return group;
            }`

Thank you for your help.

@JuandreG
Copy link
Author

This is what the model looks like when I open it:
1
2

@holance
Copy link
Member

holance commented Sep 29, 2021

Which version are you using?

@JuandreG
Copy link
Author

I'm using v2.18.0. "Date Published: Sunday, September 5, 2021". But after your fix #1652 I did remove all my packages and reinstalled them from nuget.

@holance
Copy link
Member

holance commented Sep 29, 2021

You need to install nightly build, the fix is not in 2.18.0

@JuandreG
Copy link
Author

JuandreG commented Sep 29, 2021

I installed the nightly build but still the same problem. I installed from https://www.myget.org/F/helix-toolkit v2.19.0-revert-1634-win-0001.

I tested with the models of the pictures on this issue and they all look the same. No difference. Maybe you can show me your light setup and Viewport3DX setup? I can then test and see if the problem still exists.

@holance
Copy link
Member

holance commented Sep 29, 2021

The latest nightly build is 2.19.0-alpha.36

@JuandreG
Copy link
Author

Works perfectly with that version. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants