0 votes

Hi ! New to Godot Engine and definitely new to shaders.
Currently ı'm working on godot's shader system and found this great tutorial
https://www.youtube.com/watch v=U91nqeUe1qQ&list=PLhqJJNjsQ7KHqNMYmTwtsYTeTrqrRP_fP&index=2

Though the tutorial pretty good,i think it doesn't tell detailed about what mesh system does and how it works.
For example,he used;
COLOR = texture(TEXTURE,tiled_uvs + waves_uv_offset*amplitude);
But i think he didn't tell enough about use of these functions.
I couldn't understand that and tried make a research about it,but couldn't found a clear
expression about where use 'COLOR' does,what mean 'texture','tileduvs + wavesuv_offset*amplitude);

I found https://docs.godotengine.org/en/3.0/tutorials/shading/shading_language.html as well,but couldn't find what expression I'm wanting to read,found it's so mixed.

asked Mar 28 in Engine by rpggeek (33 points)
edited Mar 28 by rpggeek

1 Answer

+1 vote
Best answer

-COLOR is the result color of the fragment function of the canvas_item shader

-texture(texture,uv) is the function that reads the color from the specified texture in the specified uv coordinate(uv=vec2(0,0) means left up corner pixel of the texture, uv=vec2(1,1) means right bottom corner pixel)

-TEXTURE is the "default" texture, the texture you have chosen for the sprite in the editor

-tilesuvs, wavesuv_offset and amplitude are custom uniform variables(shader's equivalent of gdscript variables) that the guy added to achieve the effect.

Read the updated 3.2 documentation here:
https://docs.godotengine.org/en/3.2/tutorials/shading/index.html
https://docs.godotengine.org/en/3.2/tutorials/shading/shading_reference/canvas_item_shader.html
https://docs.godotengine.org/en/3.2/tutorials/shading/intro_to_shaders_water_workshop.html

answered Mar 29 by 2plus2makes5 (169 points)
selected Mar 31 by rpggeek

Hi,thanks for answer !
But i can't understand the use of COLOR in this code.

COLOR = texture(TEXTURE,tiled_uvs + waves_uv_offset*amplitude);

This code change coordinates of pixels,doesn't change colours.

A line like that basically says that in the current point of the sprite needs to have the same color as the color of the specified texture in the specified uv coordinate.

That code passed as uv parameter changes the point where to read the color of the texture, if you use the usual UV the result will be normal, but if you program the shader so that it picks one uv lower, then the next one higher etc you will have a distorted wavy result, use TIME and you will have a moving wavy result.

The fragment shader doesn't affect the shape of the sprite, If you notice the sprite remains a rect, it doesn't become a wave, the wave movement is an illusion created by "moving" the texture inside the rectangular sprite(=by changing the uv).

If you wanted to actually affect the shape of a mesh(i don't know about the sprite) to make it like a wave you need to change the position of the VERTEX in the vertex shader.

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.