Last active
June 29, 2023 10:33
-
-
Save LeonBaudouin/5505eab338c09d9c4185431ea0cef8d4 to your computer and use it in GitHub Desktop.
Light dir + shadow Proj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const q = this._hoverEffect.$viewManager.active._components.lights._directionalLight.shadow.camera.quaternion | |
const v = vector3.set(0, 0, -1).applyQuaternion(q) | |
this.helper.setDirection(v) | |
this._mesh.material.uniforms.uLightDirection.value.copy(v) | |
// Implementation from https://gist.github.com/TimSC/8c25ca941d614bf48ebba6b473747d72 | |
vec3 projectToGround(vec3 planeNormal, vec3 planePoint, vec3 rayDirection, vec3 rayPoint ) { | |
float epsilon=0.000001; | |
float ndotu = dot(planeNormal, rayDirection); | |
vec3 w = rayPoint - planePoint; | |
float si = -dot(planeNormal, w) / ndotu; | |
vec3 Psi = w + si * rayDirection + planePoint; | |
return Psi; | |
} | |
vec4 worldPosition = modelMatrix * vec4(position, 1.0); | |
vec4 projectedPosition = vec4(projectToGround(vec3(0., 1., 0.), vec3(0., 0., 0.), uLightDirection, worldPosition.xyz), worldPosition.w); | |
projectedPosition.y += 0.01; | |
gl_Position = projectionMatrix * viewMatrix * projectedPosition; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment