0 votes

I'm trying to create a beam (laser) between two blocks.
It must looks like this (found in Internet):
enter image description here

At now I have a long scaled block in the center. I'm trying to write a shader for it. I'm using a texture and trying mix it with colour to get right result. But it's not working.

Current status:
enter image description here

Thanks a lot!

in Engine by (65 points)

1 Answer

+1 vote
Best answer

where are you using the shader in?
it seems you didn't connect the UV input to the UV of the texture, so it wont work

also, you dont need to use a texture for that, you can generate that pattern in a colorramp

by (289 points)
selected by

Thank you for your response!
I've made a few steps to get desired result.
1. Fix a shader. Connect it to UV.
2. Use 2 crossed cubes with Z scale equal 0.00001 to build a beam
3. Apply that shader to cubes

Now it looks like this:
enter image description here

you can use the colorramp for the diffuse alpha too. in fact, I think your diffuse socket is useless, the colorramp can specify the color and feed the emission output directly, no need for diffuse in this case

anyway, is it what you want or is there still something wrong?

Seems it's OK for me.
Do you know how I can connect ColorRamp to UV?. If I just replace TexUniform with ColorRamp it doesn't work.

your texture is basically 1px width and many pixels height, which means X is always the same, it is the Y coordinate that changes the color. so your UV must be split into X, Y, and Z(vector to scalar node), and you feed the Y into the colorramp

Now it's look great! Thanks a lot!
The final shader:
enter image description here

you could still optimize those nodes a bit ;) but its good!

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.