Gonan Posted November 22, 2014 Share Posted November 22, 2014 I'm trying to use a fragment shader to represent moving lava, I've found a shadertoy lava but if I try to use that in leadwerks i can get a moving image but it doesn't move with the first person camera. I know that the screen coordinates that I am using need to be changed to a world based system, but I have been unable to get lava plane to have a 3D appearance, ie further away patterns look smaller and near patterns look bigger, and if I move the camera the view doesn't move. The function I am using, at its most basic starts with vec2 p = gl_FragCoord.xy; I think I have to manipulate this into a world position, but I don't have the knowledge on how this can be converted. I think I have to use various transformations that invert those made by leadwerks. Is what I am trying to do possible. Ive tried to use the shader on a material, applied to the plane, but if I do it that way I don't get the lava swirling on the screen, but it still fails to follow the camera. Ie the image of the lava remains fixed to the viewport. At the moment, I have a Lava.mdl, just like a water plane, a lava.lua script which loads a lava.shader. The script sets iGlobalTime as a float, which just counts in 0.005 increments. The other variable is a vec2 iResolution set to context:GetWidth()*2 and context:GetHeight()*2 Though if I try to divide gl_FragCood.xy by iResolution the lava fails to display except as a solid colour. Does anyone have a Fragment shader code snippet that converts coordinates back to world coordinates for Leadwerks? Thanks in anticipation. Quote Link to comment Share on other sites More sharing options...
shadmar Posted November 22, 2014 Share Posted November 22, 2014 If you are doing what I think you are you should be able to just map coordinates to your uvmap like this (but I cant really tell unless you show me your shader): in vec2 ex_texcoords0; .. vec2 p = ex_texcoords0; Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Gonan Posted November 22, 2014 Author Share Posted November 22, 2014 @shadmar, you don't need to see my shader, because you are brilliant, I passed the texcoords0 via an "out vec2" through from the vertex shader and used them as an "in vec2" in the fragment shader and it works. Thank you so much, I've been trying to get this working for 2 weeks, starting with zero knowledge of shaders, got your water effect working with the wobble shader for underwater within a couple of hours, and then tried to get lava to work. I even started going through Jamie King's youtube video course on OpenGL upto video 55, of 99, and we have just covered the world to view matrix, so thought I needed the inverse function, and was trying all sorts of combinations of matrix transforms to no avail. 2 minutes after reading your post, I was up and running. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.