I'm trying to prevent shadow swimming when moving the directional light around to cover only the visible part of my scene. Despite rounding the translation components in light space, they swimming artifacts are still there.
I even tried pointing the light directly down (with a scale of 2 and shadow map size of 32) and translated the directional light along the world x-axis by -1 and +1. The shadows still changed. I can only assume they aren't using normal orthographic projection. The shadows seem to move more when near the edge too.
Has anyone had luck preventing shadow swimming in SceneKit, or knows what projection matrix is being used for the directional light shadows?
Related
I have an odd behaviour in certain conditions when I have two geometries one above the other and the first one at least has alpha value != 0.
I am using a program for the SCNMaterial, program is in metal and does simple stuff, color out is of the type
float4(color.x * alpha, color.y * alpha, color.z * alpha, alpha)
The geometry doesn't really influence the behaviour, but for the shake of explanation I have a SCNPlane on the back and an SCNCyclinder on the front.
It all looks good until camera it's perpendicular +/- 30 degs more or less, see below
As you can see you have a bluish background and then a cylinder few centimeters in front of it, it is semi transparent and we can clearly see the bluish behind it.
Whenever the camera get passed +/- 30 from being perpendicular, we can see through the background because it is not anymore rendered in corrispondence of the cylinder, see the one on the left
Basically when it is parpendicular or so the two layers are summed up and give the correct result, when reached that cone of angles only the layer on the top is rendered.
What I am missing here to make it as it should.
Not using any priority for the rendering as I am aware.
Thank you.
I'm using physically based lighting to light my scene in ARKit, however, I also want to add shadows to make it more realistic. I tried adding a directional light and setting the intensity as low as possible but I still am not able to reach my desired effect. I basically want a light to only cast shadows and have no effect on the lighting in the scene.
Is there any way I can achieve this effect?
You should use correct SCNShadowMode property.
From the apple's documentation:
Each shadow mode may have a positive or negative effect on rendering performance, depending on the contents of the scene. Test your app to determine which shadow mode provides the best balance between performance and quality for the scenes you want to render.
case forward:
SceneKit renders shadows during lighting computations.
case deferred:
SceneKit renders shadows in a post-processing pass.
case modulated:
SceneKit renders shadows by projecting the light’s gobo image. The light does not illuminate the scene.
So your desired option is should be modulated.
I hope it helped!
P.S. If this answer is useful to you, don't forget to press up arrow and mark it as a correct. Best of luck!
Update.
Lights source:
Directional:
- Intensity - 1000.
- Mode - dynamic.
- Color #000000 (rgb(0, 0, 0)).
- Shadow Mode: modulated.
I'm having trouble casting a shadow in my scene. Steps I've taken:
shadowMapEnabled attribute added to the React3 element
the directional light in my scene has verbatim the properties I see here in the react-three-renderer example
all three meshes (one cube and two planes) in the scene have castShadow and receiveShadow
I have a black cube in the image below to show where the directional light is eminating from.
Here's a gist of my code. (abbreviated)
Try reducing the shadow camera's near value, it looks too high. If you can provide a full example it may be easier to diagnose what's happening
Additionally try to place a different object at the "lookAt" target for the light, this should help identify in which direction it will face
http://www.youtube.com/watch?v=gZNdfVwkttM - you can see all of the problem described on this video if you can't see pictures.
All of walls in all images below have a semitransparent PNG texture. Each square wall, floor and ceiling tile is a separate GeometryModel3D (I know that is no good for performance but...). The floor and the ceiling of the central cube have no any geometry and textures - so they have a color the same as Window.Background (black). But the effect considered appears in any way of transparency obtaining: texture for ImageBrush with transparency, Material.Color (for example DiffuseMAterial.Color) where Color has alpha channel, ImageBrush as material where ImageBrush has Opacity - all the way I have the same problem.
All of walls consists of two triangles. Where are no explicit normals , because I define triangle indices so normals culculated automatically by WPF.
http://imagepost.ru/images/i/ma/image00001.png
It also haven't any back material or extra triangles from the back side.
As you can see there is no problem if you look only from +Z to -Z (standing on the blue square and looking to the red square - that is the second picture).
But if you look backward (from red to blue - the first picture) there is no transparency!
Well, I desided to look from the yellow square (third picture).
And then I walked nearer - you can see what was happening (pictures from 4 to 6).
There are no geometry construction error or texture mapping error or lighting error! It is some kind of clipping, I guessed! In addition there are some interested pictures 7 and 8 to prove my guess.
The last picture shows the white background of the window that hosted Viewport3D (previous was black), and my guess about clipping confirmed - WPF just not painted this part of the scene and we can see the window background!
BUT! If this happens from various looks, why the look from +Z to -Z (second picture) seems well?!
You need to sort the triangles based on their distances from the viewpoint. Only then, wpf will be able to blend the transparent textures.
DirectX is able to blend triangles on top of each other but only when drawing them back to front
http://www.ericsink.com/wpf3d/2_Transparency.html
What i'm trying to do is making a "light projector" with visible ray(like with fog) also called volumetric light;
and which project a image (bitmap) ;
Because i would like to keep this project connected with a wpf application ( to get brush, position, rotation from data), i've choose to use WPF 3D
But it seem that WPF can't handle light projection or render ray.
So to do that, i have extruded each pixel of my source bitmap into a polygon colored by a solidColorBrush of the pixel color.
and keep the pixel order with (x,y) position.
For performance issue, i've set all the bitmaps to 32x32 px ( 1024 polygon for only one light !!)
But the result is too pixelated as you can see on the picture.
Moreover, it probably take much memory for nothing ...
my question is, how can i make it smooth or even rethink the extrusion system to optimize performance ...
Is any other tehnology that can be integrated into a wpf application and do that better or easier ?
Thanks, and sorry my English is pretty bad ...
alt text http://www.visualdmx.fr/pic_example.png