+1 vote

I have created an ocean shader! Unfortunately its a shader. So I need a function outside so that the user can sample the wave displacement at a point something like-

func get_displace(point):
    var new_pos = Vector3(point.x, 0.0, point.y)
    #Calculate the wave at the specified point at the specified TIME.
    return new_pos

So is there someway to get a value in gscript that reflects off of the TIME shader variable.

asked May 11, 2018 in Engine by SIsilicon (3,511 points)

Did you ever figure out how to do this? I tried myself but ended up going the other way, making uniform float elapsed = 0.0 and feeding it a value in _process. I'm honestly not sure if this a good idea or not but it's worked for my case.

Yeah I ended up using that solution as well.

Could one of you guys please show the code that feeds the shader's uniform a value from _process?

1 Answer

0 votes

I know that this question's over a year old, but I thought I ought to at least give an answer. I eventually just fed a custom time variable into the shader for every time _process is called.

var time = 0
func _process(delta):
    shader_mat.set_uniform_value("time", time)
    time += delta
answered Aug 15 by SIsilicon (3,511 points)

I don't see anything wrong answering an old question, other people can still find the solution, it shouldn't be necessarily targeted towards the original poster.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.