using of COLOR in shader programming ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rpggeek

Hi ! New to Godot Engine and definitely new to shaders.
Currently ı’m working on godot’s shader system and found this great tutorial
YouTube 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’,'tiled_uvs + waves_uv_offset*amplitude);

I found Shading language — Godot Engine (3.0) documentation in English as well,but couldn’t find what expression I’m wanting to read,found it’s so mixed.

:bust_in_silhouette: Reply From: 2plus2makes5

-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

-tiles_uvs, waves_uv_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:

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.

rpggeek | 2020-03-29 21:28

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.

2plus2makes5 | 2020-03-30 16:55