Moving shadows in Three.JS - three.js

Is there a way to dynamically change the 'position' of the light which casts the shadow. I only want an area around the player casted with shadows, and not the whole map.

Can be done by moving the shadowCameraTop/Right/Bottom/Left and then updating the projection matrix, or setting the position of the light itself

Related

Rendering Sprites in Three.js over 3D Object and also behind without clipping

I need a way to render a sprite always over top of a 3DObject, but it also must disappear behind it when the camera is rotated.
I first tried disabling the depth-buffer write but this will always render the Sprite in front.
Is there a way to hide it when its behind, but prevent clipping with the Object?
Edit 1:
The Problem is not exactly about z-fighting because the depthbuffer values of the sprite and the object are not equal.
The Sprite is a Billboard, so it will always face the camera, but it clips with the object, when rotating the camera.
Thank you for your help

Is there a way to create directional light in 2D?

In processing there is a function that creates directional light in 3D. But i wanna create the same effect in 2D. I think i need a vector and color info so i can create a shadow effect on a image.
Like this:
The mouse becomes a point of light and when it moves around it changes the image creating a shadow effect on it.
I can't use function that are 3D like pointLight or directionalLight so any ideas where should i start?

THREE.js Orthographic camera position not updating after *dolly* with OrbitControl

I'm using THREE.OrbitControls to dolly a THREE.OrthographicCamera. But, even thought the ortho camera renders correctly as repositioned, all that is updating on the orthographic camera is the 'zoom' property. Even after calling camera.updateProjectionMatrix(). Do I need to manually update the 'position' property of the camera based on the updated 'zoom' property? I want to display its position in my UI after dollying it.
(Note, this is a rewrite of my other question,THREE.js Orthographic camera position not updating after zoom with OrbitControl, in which I thought I was zooming with the OrbitControl but was actually dollying. Sorry about this).
Dollying in/out with an ortho cam would have an unnoticeable effect. With ortho cams there is no perception of proximity because it has no perspective. All objects appear the same in size regardless of distance from the lens because the projection rays are all parallel. The only difference you'd notice is when the objects get clipped because they're past the near or far plane.
So, the decision was made that scrolling with OrbitControls would change the zoom of the camera, narrowing in/out of the center.
If you want to force the camera to move further/closer of its focus point, you could just translate it back/forth in the z-axis with:
camera.translateZ(distance); A (-) distance would move it closer, and a (+) distance would move it further from its focus point.

Light affecting all objects and passing through walls in three.js

I have a house scene where it has number of walls, when i add directional or spot lights the light passes through walls irrespective of the direction of light positioned.How can i make my light not to pass the wall ?
That is not a way how the WebGL 3D rendering works. All materials will be affected by light. You can render a shadows: http://learningthreejs.com/blog/2012/01/20/casting-shadows/
but, that means the light on the Meshes will be always rendered and after this will be rendered a shadow. That means, if you have a meshPhong material with a high shininess, it will be rendered visible and darkened by the shadow, which is not physically possible in real.

How to create an orthographic/isometric directional light with three.js

I'm trying to create a shadow in my orthographic scene in three.js. I'd like to have a directional light so the shadow is offset from all objects equally in the scene. I am however having problems using DirectionalLight.
My first problem is that I can't get the shado to cover the entire scene, only part of it ever has a shadow. I played with the light's frustum settings, but can't figure out how to get it to cover the scene. Ideally I'd want the frustrum to match that of the camera.
The second problem is that the shadows aren't "clean". If I use a SpotLight the shadows have nice crisp borders (but obviously not the universal directionality I want). When I use a DirectionalLight the borders are misshappen and blurry.
In the samples the tile is a simply box created with CubeGeometry.
How can I create an ortographic directional light source for my scene?

Resources