How to Send Custom Data to a Shader During Runtime?

Godot, Version 4.2.1

I’m trying to make a shader using the ideas from this wonderful text, but have hit a roadblock since this is my first time using Godot.

For the lineart, the code should process an edge to decide whether or not to add it to a list so a brush stroke can be drawn later. An edge is flagged if it…

  1. Has less than two adjacent tris.
  2. One tri is facing away from the camera.
  3. The angle between the adjacent tris is within/outside a threshold.

Vital to this is being able to create sets of adjacent tris for comparison.

I plan on generating a list of pairs of adjacent tris outside the program and storing them alongside the model data. This is where the roadblock is. I don’t know how to parse (I’ll figure this out on my own) and send the data to the shader (this is what I need help with).

The file format for the adjacent tris will likely look like this-

// The brackets and parenthesis are for visual separation
// and wouldn't be there in practice.
[(0.0 1.0 0.0) (1.0 1.0 0.0) (1.0 0.0 0.0)] [(1.0 0.0 0.0) (0.0 0.0 0.0) (0.0 1.0 0.0)]
[(0.0 2.0 0.0) (1.0 2.0 0.0) (1.0 1.0 0.0)] [(1.0 1.0 0.0) (0.0 1.0 0.0) (0.0 2.0 0.0)]
// And so on and so forth...

Thanks for any and all help in advance!

So you want to pass an array to a Godot shader. That’s what you are asking?

uniform vec3 my_array[4];

And here’s the documentation for the ShaderMaterial resource - you’ll want to take a look at set_shader_parameter: ShaderMaterial — Godot Engine (stable) documentation in English

1 Like