Hi.
Please first refer to
I was playing with shaders and In a ground mesh on the xz plane, I managed to paint it with a rainbow disk of radius 5.
Now, having each point in my ground coordinates (x,0,z), I want to move those points to a position (f(x,z),0,g(x,z)), lets say to the position (x + 10.0,0,z), and paint them according to its original coordinates (x,y,z), i.e. in this example I want to get the exact rainbow disk but painted 10 units to the right.
So I made this:
If I am understanding correctly, I only needed to:
-
Make two copies of the attribute position vector, lets say
in vec3 vPosition = position and
vec3 v = position. -
Modify the coordinates of v, in this example I only need to change v.x, i.e
v.x = v.x + 10.0;
v.y = v.y;
v.z = v.z;
and make gl_Position = worldViewProjection * (v, 1.0); -
Pass the vPosition (which is equal to the unmodified position) as a varying vec3 to the fragment shader and use my previously working formulas that paint my original disk, as a function of vPosition.
This way I will have different positions for my vertexes (10 to the right), but the color will be given by their original position (the vec3 vPosition) … Right?
Well, doing so I got the desired result. The disk is painted 10 units to the right.
Playing with the lines
v.x = something
v.y = 0.0
v.z = somethin else
I get some nice paints. (commented in the playground)
Such as
v.x = v.x+v.z;
v.z = 3.0*v.z + v.x
The problem is that when I use anything besides a sum or a multiplication by a float, I get wrong pictures.
For example if
v.x = v.x*v.x;
v.y = 0.0
v.z = v.z;
Nothing is being drawn!
In order to have a clue of what is happening I did (also commented in playground)
v.x = v.x;
v.y = v.x*v.x;
v.z = v.z;
i.e. I made the graph of y seen as a function of x and z.
And I found that v.xv.x is always equal to 25. (putting v.y = v.xv.x - 25.0 gives the graph just on the xy plane). 25 is the maxium the value v.x*v.x can be, since the ground goes from (-5, -5) to (5, 5), but why it takes this value at every point on the ground?
I also put:
v.x = v.x;
v.y = v.x;
v.z = v.z;
Just to be extra sure that v.x is NOT constant. And it is not.
Yet v.x*v.x IS constant = 25. I am super puzzled. Please help
What is happening? Why is v.x*.v.x always 25? How can I get the points
v.x = v.x*v.x
v.y = 0.0
v.z = v.z
be correctly painted?
My final goal is to paint some nice complex numbers functions, something like this
but in order to do it, first of all I need to be able to deal with the basic operations +, -, *, /.