Jump to content

PicoGL Shadow casting problem


Recommended Posts

Hello all,

This is my first post, starting with a question with a problem I cannot seem to figure out.

My problem is, that I cannot get shadow casting to work, no matter what I try. I got the PicoGL demo working with my own shaders, but shadow casting stops working after I move an object outside the [1,1,1] bounduary. The game I am developping (bomberman) currently contains a 15x15 grid with bloks of 10x10x10.

My light / position code looks like this:

//Eye + light (a mess, but works)
var eyePosition = vec3.fromValues(150, 500, 150);
lightPosition = vec3.fromValues(120, 1000, 1000);
var rotation = quat.setAxisAngle(vec4.create(), vec3.fromValues(1, 0, 0), Math.PI/2.5); mat4.fromRotationTranslationScale(viewMatrix, rotation, vec3.fromValues(-map.w*5, map.l*5, -250), vec3.fromValues(1, 1, 1));
var viewProjMatrix = mat4.create();
mat4.multiply(viewProjMatrix, projMatrix, viewMatrix);
//This makes no sense yet
var lightViewMatrix = mat4.create();
mat4.fromRotationTranslationScale(lightViewMatrix, rotation, vec3.fromValues(-map.w*5, map.l*5, -500), vec3.fromValues(0.001, 0.001, 0.001));
mat4.multiply(lightProj, projMatrix, lightViewMatrix);

Shader (real render)

uniform SceneUniforms {
    mat4 viewProj;
    mat4 lightProj;
    vec3 eyePosition;
    vec3 lightPosition;

uniform mat4 uModel;

out vec3 vPosition;
out vec2 vUV;
out vec3 vNormal;
out vec4 vPositionFromLight;

void main() {
    vec4 worldPosition = uModel * position;

    vPosition = worldPosition.xyz;
    vUV = uv;
    vNormal = (uModel * vec4(normal, 0.0)).xyz;
    vPositionFromLight = lightProj * worldPosition;

    gl_Position = viewProj * worldPosition;

Demo (ignore the domain)


I got the demo working with the same shaders:



Its already taking days for me to solve this, but lights / shadow is a domain I do not really get yet. Can somebody shed some light on my shadow casting problem? Thanks!

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...