Example #1
0
atmosphere_frag_shader = shader.FragmentShader(
    'atmosphere', shader_noise_glsl + '''
	/* Animated atmospheric shader */

	uniform float time;
	varying vec3 position;
	varying vec3 normal;
	varying vec3 lightvec;
	varying vec4 color;

	void main(void) {
		float t = fbmnoise(gl_TexCoord[1].xyz * 2.0 + time * 0.003, 6);
		vec3 turb = vec3(sin(t*t), cos(t+t), 0) * 0.025;
		float h = fbmnoise(turb + position, 6) + 1.0;
		h = h*h*h*h * 0.15;
		if (h > 0.0) {
			/* Calculate the lighting */
			vec3 N = normalize(normal);
			float intensity = max(0.0, dot(N, normalize(lightvec)));
			float glare = max(0.0, dot(N, normalize(gl_LightSource[0].halfVector.xyz)));
			vec4 ambient = gl_LightSource[0].ambient;
			vec4 diffuse = gl_LightSource[0].diffuse * intensity;
			vec4 specular = gl_LightSource[0].specular * pow(glare, 64.0);
			gl_FragColor = (ambient + diffuse + specular) * color * h;
		} else {
			discard;
		}
	}
''')
atmosphere_prog = shader.ShaderProgram(vert_shader, atmosphere_frag_shader)
Example #2
0
		lightvec = gl_LightSource[0].position.xyz - v.xyz;
		color = gl_Color;
	}
''')

smooth_frag_shader = shader.FragmentShader('smooth', '''
	/* Simple per-pixel lighting shader */

	uniform float height;
	varying vec3 position;
	varying vec3 normal;
	varying vec3 lightvec;
	varying vec4 color;

	void main(void) {
		vec3 N = normalize(normal);

		/* Calculate the lighting */
		float intensity = max(0.0, dot(N, normalize(lightvec)));
		float glare = max(0.0, dot(N, normalize(gl_LightSource[0].halfVector.xyz)));
		vec4 ambient = gl_LightSource[0].ambient;
		vec4 diffuse = gl_LightSource[0].diffuse * intensity;
		vec4 specular = gl_LightSource[0].specular * pow(glare, 128.0);
		gl_FragColor = (ambient + diffuse + specular) * color;
	}
''')
smooth_prog = shader.ShaderProgram(vert_shader, smooth_frag_shader)

simple_bump_frag_shader = shader.FragmentShader('simple_bump', shader_noise_glsl + '''
	/* Simple normal mapper using perlin noise */
Example #3
0
		color = gl_Color;
	}
''')

atmosphere_frag_shader = shader.FragmentShader(
    'atmosphere', shader_noise_glsl + '''
	/* Animated atmospheric shader */
	uniform float time;
	varying vec3 position;
	varying vec3 normal;
	varying vec3 lightvec;
	varying vec4 color;
	void main(void) {
		float t = fbmnoise(position * 2.0 + time * 0.001, 2);
		vec3 turb = vec3(sin(t * 0.5), cos(t), 0) * 0.04;
		float h = fbmturbulence(turb + position * 0.5 + time * 0.002, 6) * 1.35;
		h = h*h;
		/* Calculate the lighting */
		vec3 N = normalize(normal);
		float intensity = max(0.0, dot(N, normalize(lightvec)));
		float glare = max(0.0, dot(N, normalize(gl_LightSource[0].halfVector.xyz)));
		vec4 ambient = gl_LightSource[0].ambient;
		vec4 diffuse = gl_LightSource[0].diffuse * intensity;
		vec4 specular = gl_LightSource[0].specular * pow(glare, 64.0);
		gl_FragColor = (ambient + diffuse + specular) * color * h;
	}
''')
atmosphere_prog = shader.ShaderProgram(vert_shader, atmosphere_frag_shader)
atmosphere_prog.install()
atmosphere_prog.uset1F('scale', 0.3)