Last active
August 29, 2015 13:57
-
-
Save davechristian/9427160 to your computer and use it in GitHub Desktop.
This is a Mandelbrot shader, designed for the Raspberry Pi version of GLSL Hacker (though it will run on any GLSL Hacker version). Grab GLSL Hacker from: http://www.geeks3d.com/20131031/glsl-hacker-0-6-0-0-physx-3-mac-os-x-10-9-autdesk-fbx-raspberry-pi-programming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> | |
<glsl_hacker> | |
<window name="win3d01" title="Mandelbrot Demo for PiCymru (OpenGL ES 2.0)" | |
width="1920" height="1080" | |
gl_version_major="2" gl_version_minor="2" | |
build_opengl_extensions_list="0" /> | |
<gpu_program name="gpu_program" > | |
<raw_data_vs><![CDATA[ | |
attribute vec4 gxl3d_Position; | |
//attribute vec4 gxl3d_TexCoord0; | |
invariant gl_Position; | |
uniform mat4 gxl3d_ModelViewProjectionMatrix; | |
//varying vec4 Vertex_UV; | |
void main() | |
{ | |
//Vertex_UV = gxl3d_TexCoord0; | |
//gl_Position = gxl3d_ModelViewProjectionMatrix * gxl3d_Position; | |
gl_Position = gxl3d_Position; | |
} | |
]]></raw_data_vs> | |
<raw_data_ps><![CDATA[ | |
// This is the pixel shader.. the part that draws the mandelbrot - DC | |
uniform vec3 iResolution; // viewport resolution (in pixels) | |
uniform float iGlobalTime; // shader playback time (in seconds) | |
uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down), zw: click | |
void main(void) { | |
vec2 position = ( gl_FragCoord.xy / iResolution.x ); | |
float zoom = abs(sin(iGlobalTime / 1.5) * 13.0); | |
float real = (position.x - 0.5) * zoom; | |
float imaginary = (position.y - 0.3) * zoom; | |
float const_real = real; | |
float const_imaginary = imaginary; | |
float z2 = 0.0; | |
int iter_count = 0; | |
for(int iter = 0; (iter) < 25; ++iter) | |
{ | |
float temp_real = real; | |
real = (temp_real * temp_real) - (imaginary * imaginary) + const_real; | |
imaginary = 2.0 * temp_real * imaginary + const_imaginary; | |
z2 = real * real + imaginary * imaginary; | |
iter_count = iter; | |
if (z2 > 4.0) | |
break; | |
} | |
if (z2 < 4.0) | |
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); | |
else | |
gl_FragColor = vec4(mix(vec3(0.0, 0.0, 0.2), vec3(1.0, 1.0, 1.0), fract(float(iter_count)*0.02)), 1.0); | |
} | |
]]></raw_data_ps> | |
</gpu_program> | |
<script name="init_scene" run_mode="INIT" > | |
<raw_data><![CDATA[ | |
winW, winH = gh_window.getsize() | |
--font_a = gh_utils.font_create("Tahoma", 14) | |
camera_ortho = gh_camera.create_ortho(-winW/2, winW/2, -winH/2, winH/2, 1.0, -1.0) | |
gh_camera.set_viewport(camera_ortho, 0, 0, winW, winH) | |
gh_camera.set_position(camera_ortho, 0, 0, 1) | |
gpu_prog_01 = gh_node.getid("gpu_program") | |
-- local abs_path=0 | |
-- tex01 = gh_texture.create_from_file("data/233.jpg", 3, abs_path) | |
mesh_quad = gh_mesh.create_quad(winW, winH) | |
gh_object.use_opengl21(mesh_quad, 0) | |
gh_renderer.set_vsync(1) | |
gh_renderer.set_scissor_state(0) | |
]]></raw_data> | |
</script> | |
<script name="update_scene" run_mode="FRAME" > | |
<raw_data><![CDATA[ | |
elapsed_time = gh_utils.get_elapsed_time() | |
gh_renderer.set_depth_test_state(1) | |
gh_camera.bind(camera_ortho) | |
gh_renderer.clear_color_depth_buffers(0.2, 0.2, 0.2, 1.0, 1.0) | |
gh_gpu_program.bind(gpu_prog_01) | |
gh_gpu_program.uniform1f(gpu_prog_01, "iGlobalTime", elapsed_time) | |
gh_gpu_program.uniform3f(gpu_prog_01, "iResolution", winW, winH, 0) | |
-- mouse_x, mouse_y = gh_input.mouse_getpos() | |
local mouse_x = winW/2 | |
local mouse_y = winH/2 | |
gh_gpu_program.uniform4f(gpu_prog_01, "iMouse", mouse_x, winH-mouse_y, 0, 0) | |
-- gh_gpu_program.uniform1i(gpu_prog_01, "iChannel0", 0); | |
-- gh_texture.bind(tex01, 0) | |
gh_object.render(mesh_quad) | |
--gh_utils.font_render(font_a, 10, 20, 0.2, 1.0, 0.0, 1.0, "GLSL Hacker demo - Shader Toy Demo (www.shadertoy.com)") | |
]]></raw_data> | |
</script> | |
<script name="resize_scene" run_mode="SIZE" > | |
<raw_data><![CDATA[ | |
winW, winH = gh_window.getsize(0) | |
aspect = 1.333 | |
if (winH > 0) then | |
aspect = winW / winH | |
end | |
gh_camera.update_ortho(camera_ortho, -winW/2, winW/2, -winH/2, winH/2, 1.0, -1.0) | |
gh_camera.set_viewport(camera_ortho, 0, 0, winW, winH) | |
--gh_utils.font_set_viewport_info(font_a, 0, 0, winW, winH) | |
gh_mesh.update_quad_size(mesh_quad, winW, winH) | |
]]></raw_data> | |
</script> | |
</glsl_hacker> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment