Exemple #1
0
    def reloadShaders(self):
        with open('shaders/ocean.fragment') as f:
            fshader = shader.FragmentShader([f.read()])
        with open('shaders/ocean.vertex') as f:
            vshader = shader.VertexShader([f.read()])

        self.surfaceShader = shader.ShaderProgram(fshader, vshader)
        self.surfaceShader.use()
        self.surface.setShader(self.surfaceShader)
Exemple #2
0
def load_shader():
    s = shader.ShaderProgram()
#    s.setShader(shader.VertexShader('test_v', test_v))
    s.setShader(shader.FragmentShader('test_f', test_f))
    return s
Exemple #3
0
		varying vec3 position;

		void main(void) {
			position = gl_Vertex.xyz * 5.0;
			gl_Position = ftransform();
		}
	''')
	frag_shader = shader.FragmentShader('noise_test', shader_noise_glsl + '''
		varying vec3 position;

		void main(void) {
			float v;
			float a = atan(position.y, position.x);
			float arc = 3.14159 / 3.0;
			if (a > -arc && a < arc) {
				v = pnoise(position) * 0.5 + 0.5;
			} else if (a > arc && a < arc * 4.0) {
				v = fbmnoise(position, 4) * 0.5 + 0.5;
			} else {
				v = fbmturbulence(position, 4) * 0.5 + 0.5;
			}
			gl_FragColor = vec4(v, v, v, 1.0);
		}
	''')
	shader_prog = shader.ShaderProgram(vert_shader, frag_shader)
	shader_prog.install()
	tex = ShaderNoiseTexture()
	tex.load()
	tex.enable()
	shader_prog.uset1I('shader_noise_tex', 0)
Exemple #4
0
void main() {
    vec2 h = vec2(1.0/size.x, 0.0);
    vec2 pos = gl_TexCoord[0].st;

    vec2 v = pos - mouse;
    float d = length(v);
    v = normalize(v);
    v = v * clamp(exp(2. * d) / strength, 0., 1.);

    gl_FragColor = texture2D(tex, pos + v);
}
"""

pinch = shader.ShaderProgram()
pinch.setShader(shader.FragmentShader('pinch_f', pinch_f))
pinch.install()
pinch.uset2F('size', float(kitten.width), float(kitten.height))


@w.event
def on_mouse_motion(x, y, *args):
    pinch.uset2F('mouse', float(x) / kitten.width, float(y) / kitten.height)
    return True


strength = 50.
pinch.uset1F('strength', strength)


@w.event
Exemple #5
0
 def __init__(self):
     super(Foil, self).__init__()
     self.setShader(shader.VertexShader('foil_v', vec))
     self.setShader(shader.FragmentShader('foil_f', frag))
     self.timer = 0.
     pyglet.clock.schedule_interval(self.update, 1 / 60.0)  # update at 60Hz
Exemple #6
0
def _buildBallShader():
    ball_shader = shader.ShaderProgram(
        shader.VertexShader("""
        void main(){
            gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
        }"""),
        shader.FragmentShader("""
        uniform vec2 position;
        uniform float radius;
        uniform vec3 rgb;
        uniform vec3 shimmer;
        uniform vec2 core_position;
        uniform float core_radius;
        
        const float border_width = 1.2;
        const float shimmer_radius = 1.75;
        
        void main(){
            float r = rgb.r;
            float g = rgb.g;
            float b = rgb.b;
            
            //Calculate distance from centre of current blob.
            float distance = sqrt(
             pow((position.x - gl_FragCoord.x), 2.0) +
             pow((position.y - gl_FragCoord.y), 2.0)
            );
            
            //Calculate distance from core blob.
            float core_distance = sqrt(
             pow((core_position.x - gl_FragCoord.x), 2.0) +
             pow((core_position.y - gl_FragCoord.y), 2.0)
            );
            
            if(core_distance >= core_radius - border_width && abs(distance - radius) <= border_width){
                gl_FragColor = vec4(
                 min(1.0, r * 2.0),
                 min(1.0, g * 2.0),
                 min(1.0, b * 2.0),
                 0.95
                );
            }else{
                //Brighten the core of each blob.
                float brightness_mod = 0.05;
                if(distance < 0.75){//Draw a bright dot right in the centre.
                    brightness_mod = 0.25 + sqrt(1.0 / distance);
                }else{//Apply shimmer.
                    float shimmer_x = mod(gl_FragCoord.x + shimmer.x, shimmer[2]);
                    float shimmer_y = mod(gl_FragCoord.y + shimmer.y, shimmer[2]);
                    if(shimmer_x >= shimmer[2] - shimmer_radius){
                        shimmer_x -= shimmer[2] + shimmer_radius;
                    }
                    if(shimmer_y >= shimmer[2] - shimmer_radius){
                        shimmer_y -= shimmer[2] + shimmer_radius;
                    }
                    
                    float shimmer_distance = sqrt(pow(shimmer_x, 2.0) + pow(shimmer_y, 2.0));
                    
                    if(shimmer_distance <= shimmer_radius){
                        brightness_mod += min(0.9, sqrt(
                            shimmer_distance / shimmer_radius
                        ));
                    }else{
                        brightness_mod = 0.3;
                        r = 0.4;
                        g = 0.0;
                        b = 0.6;
                    }
                }
                
                gl_FragColor = vec4(
                 min(1.0, r * brightness_mod),
                 min(1.0, g * brightness_mod),
                 min(1.0, b * brightness_mod),
                 0.95
                );
            }
        }"""))
    _shader_message = ball_shader.link()
    if _shader_message and __debug__:
        print _shader_message
    return ball_shader