Vertex Kaleidoscope shader

I am trying to translate a fragment shader to a vertex shader (to optimize mobile devices)

As you can see in the image below, the vertices of the center and right edge are errors. (This is a 11 x 11 vertex plane)

Currently, UVs are displayed on the right and wrap around the center (with radial rotation). Am I guessing a few peaks in the middle of half the same value that creates the hole? And then the right side cross-fades the first UV values ​​to the final values, which creates a stretched effect.

The question is how to redefine or fix them. (Perhaps they will have two separate problems?)

kaleidoscope vertex shader

uniform vec2 _Offset; uniform float _Multiply; varying vec4 position; varying vec4 vert; varying vec2 tex; varying vec2 uv; varying float ar; #ifdef VERTEX void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; vec2 p = -1.0 + 2.0 * tex.xy; float a = atan(py,px) ; float r = sqrt(dot(p,p)); uv.x = _Multiply*a/3.1416 * 2.0 + 0.1; float sx = sin(_Multiply*r+_Offset.x); float sy = _Multiply*.1*cos(_Offset.y+_Multiply*a); uv.y = -_Offset.x + sx + sy; } #endif #ifdef FRAGMENT uniform sampler2D _MainTex; void main(void) { gl_FragColor = texture2D(_MainTex,uv*.5); } #endif ENDGLSL 
+4
source share
1 answer

enter image description here

Well, essentially rewriting the shader, I was able to get the expected results. And for beginners' advice: the greater the number of vertices in your plan, the less pixel distortion.

 GLSLPROGRAM #ifdef VERTEX varying vec2 position; uniform float _Multiply; uniform vec2 _Offset; void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; vec2 tex = vec2(gl_MultiTexCoord0); vec2 p = tex.xy - 0.5; float r = length(p); float a = atan(py, px); float sides = _Multiply; float tau = 2.0 * 3.1416; a = mod(a, tau/sides); a = abs(a - tau/sides/2.0); position = r * vec2(cos(a), sin(a)) + 0.5 + _Offset; } #endif #ifdef FRAGMENT varying vec2 position; uniform sampler2D _MainTex; void main(void) { gl_FragColor = texture2D(_MainTex, position); } #endif ENDGLSL 
+2
source

All Articles