GLSL - pixel world positions?

Hey,
Recently I wrote a basic primitive ray marcher that produces resource-cheap shadows with variable penumbras. Though, I’ve obtained inaccurate results because of inaccurate pixel world positions. I used the pixel world positions from Martins Upits’ deferred shading example. Here’s what I mean:


A still image doesn’t fully show the effect, as the shadow offset is pretty view dependant, and moves badly with camera movement, here’s a blend file to further show it.
Is there any better way to obtain pixel world positions? Thanks in advance!

EDIT: Well the first problem (the one in screenshot) was caused from false window borders, so it’s fixed so far. But I still have the problem of camera matrix taking a frame to update which shows delay artifacts.

Attachments

raymarch_test.blend (4.5 MB)

i not understand well these script , but seem that the info of camera are grabbed in get script, that run at controller time, then applyRotation run a bit after .

there are 2 way:
or use the matrices for mouse look

or get info of cam in pre_draw (that run after the actuators)

this is the “patch” :smiley:


from bge import logic as G
import bgl
from mathutils import *
from math import *


scene = G.getCurrentScene()
cont = G.getCurrentController()
objlist = scene.objects
own = cont.owner




if not "init" in own:
    def get_cam_stuff():
        cam = scene.active_camera
        pos = cam.position
        
        own['near'] = cam.near
        own['far'] = cam.far
        
        cameraMatrix = cam.modelview_matrix
        cameraMatrix.inverted()
        campos = cam.worldPosition
        
        own['m0'] = cameraMatrix[0][0]
        own['m1'] = cameraMatrix[0][1]
        own['m2'] = cameraMatrix[0][2]
        own['m3'] = cameraMatrix[0][3]
        own['m4'] = cameraMatrix[1][0]
        own['m5'] = cameraMatrix[1][1]
        own['m6'] = cameraMatrix[1][2]
        own['m7'] = cameraMatrix[1][3]
        own['m8'] = cameraMatrix[2][0]
        own['m9'] = cameraMatrix[2][1]
        own['m10'] = cameraMatrix[2][2]
        own['m11'] = cameraMatrix[2][3]
        own['m12'] = cameraMatrix[3][0]
        own['m13'] = cameraMatrix[3][1]
        own['m14'] = cameraMatrix[3][2]
        own['m15'] = cameraMatrix[3][3]
        own["x"] = campos[0]
        own["y"] = campos[1]
        own["z"] = campos[2]
        own["init"] = 1
    get_cam_stuff()
    scene.pre_draw.append(get_cam_stuff)

Scene pre draw solution seems the right solution of my problem, haven’t tested yet though. Thanks!
Really hoping for a better way to pass data to glsl …