0 votes

I want to draw a basic line using fragment() function,but i don't know how to.

in Engine by (33 points)

1 Answer

+3 votes

Are you sure you want to use shaders to do this?

You can draw lines without a shader by simply using the Line2D node, or by drawing it in code inside the _draw function:

extends Node2D

func _draw():
    draw_line(Vector2(10, 10), Vector2(50, 30), Color(1, 1, 0))

If you know all that but want to do it in a fragment shader, this is a whole different story... you'd probably need to use the distance field of such line (a formula giving the distance from it) and then output pixels of the color of your choice when that distance is lower than some amount, which sounds quite involved for what you want to achieve.

by (27,774 points)

Yes i am sure i want to use shaders because i'm trying to learn shader programming.
Found a bunch of examples about shader programming on shadertoy,but seems godot use a bit different shader code style and documentation about it is very poor i think.

See Migrating to Godot’s shading language for shader code differences.

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.