I’m trying to code a lighting shader and I’m wondering if there is an easy way to get a fragments world position. I tried looking in the normal map example but that code is made for getting position according to screen position, not world. Any ideas? Thanks.
You could try calculating the inverse frustum (or just the inverse of the view and projection matrices separately) in the vertex shader, then passing it as an output to the fragment shader.
I tried seeing if I could do that, but the version of glsl that defold uses doesn’t ahve the inverse function and I don’t know a single thing about matrices, let alone inversing one.
I noticed that the default sprite shader gets a world position by default for each of its vertices, so you can simply forward it to the fragment shader and the render pipeline will take care of the interpolation between vertices.
So in the sprite vertex shader:
// positions are in world space
attribute highp vec4 position;
...
var_worldpos = position;
And in the sprite fragment shader:
varying highp vec4 var_worldpos;
You can then reference the fragment’s world position through the var_worldpos variable.
wait, if that’s the correct way to do it then i guess thats not my issue, because that’s what I’ve been doing. I’m trying to make a point light and the light keeps pointing towards the bottom left corner rather than encompassing a full circle.
I’m not sure what you mean. You should post your fragment shader code if you need help with your fragment shader, as well as a screenshot of the result you’re getting.