居中 UV 并将着色器转换为灰度的问题

问题描述 投票:0回答:0

我正处于学习 glsl 的初级阶段,我在一些基础知识上遇到了麻烦。在下面列出的片段着色器中,一旦我将分形应用于 vUv。 vUv 的中心射向左下角,我想将它居中到它在破裂之前的位置。我该怎么做呢?另外,如何将片段着色器的颜色更改为灰度?与它所在的粉红色到黄色相比。


#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;

#define PI 3.1415926535897932384626433832795
mat2 rotate2d(float _angle){
    return mat2(cos(_angle),-sin(_angle),
                sin(_angle),cos(_angle));
}
void main()
{
    vec2 vUv = gl_FragCoord.xy / u_resolution.xy *2.0-1.;
    
    vUv= fract(vUv*2.0);
    vUv = rotate2d( sin(u_time)*PI ) * vUv;
    vUv += vec2(.5);
    
    float angle = atan(vUv.x - 0.5, vUv.y - 0.5); 
    angle /=  ((PI) * 2.0) + 0.5;
    vec3 ty = vec3(rotate2d(angle));

  gl_FragColor = vec4(ty+0.5, 1.0);
}
three.js glsl webgl fragment-shader react-three-fiber
© www.soinside.com 2019 - 2024. All rights reserved.