Raymarching in gl.gridshape Cube as texturing [solved]
Jun 18 2021 | 9:43 pm
I'm trying to make an interpretation of this nice tutorial from The Art of Code, where he codes a raymarching shader and uses it on a cube in Unity. https://www.youtube.com/watch?v=S8AWd66hoCo&ab_channel=TheArtofCode
However I'm getting stuck at the point where he is converting world to object coordinates to get the camera movement correct (around 20:40 in the video). unity_WorldToObject is used in a matrixmultiplication with the _WorldSpaceCameraPos. I've found that this WorldToObject should be the inverse of the world view matrix, but I have not been able to calculate this myself and apply it correctly (if tried various combinations of inverse() with mat4x4(viewMatrix), also tried with modelViewMatrix.
I've been able to import the gl.camera camera position in the shader via a <param name="campos" type="vec3" state="CAMERA_POSITION"> which seems to be similar to the _worldSpaceCameraPos in Unity, and the v.vertex seems to be the <param name="position" type="vec3" state="POSITION" /> converted to a vec4(position, 1). Rotation of the object is also not working yet, but is not necessarily my first priority, movement would already be great.
Below the patch (code is in a comment box) and some screenshots to show where I'm at. Any pointers to what would allow me to do this conversion of WorldToObject would be much appreciated!