# Raymarching in gl.gridshape Cube as texturing [solved]

tmhglnd
Jun 18 2021 | 9:43 pm
Hi all!
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!

• tmhglnd
Jun 19 2021 | 10:04 am
Solved with some help from Jaromir Mulders. You can inverse the modelViewMatrix directly with <param name="modelViewInverse" type="mat4" state="MODELVIEW_MATRIX" transform="INVERSE" />. Then store the camera position as jit_out.jit_Cam_position = vec3(modelViewInverse * vec4(0, 0, 0, 1));
Share
• 🤩 ❤️
• tmhglnd
Jun 20 2021 | 11:12 pm
I've put up the final result of this study on github and my gumroad/patreon page. https://github.com/tmhglnd/gridshape-raymarcher