Jump to content

Fragment Shader: Lava stays with the view, but I want it to be part of the world, help


Gonan
 Share

Recommended Posts

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.

Link to comment
Share on other sites

@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.

  • Upvote 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...