diff --git a/.gitignore b/.gitignore index 6af68d0ce..0321c2355 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .DS_Store .DS_Store? bin/ +Export/ ndll/*/lime* ndll/*/liblime* ndll/*/nme* diff --git a/README.md b/README.md index 2754d8245..1dd1ef021 100644 --- a/README.md +++ b/README.md @@ -39,5 +39,36 @@ For example, frameworks like [OpenFL](http://github.com/openfl) leverage lime to - The lime GL wrapper code is based on WebGL Api. It matches very closely. Including types and constants. - The lime native parts were forked from [nme](http://github.com/haxenme/nme) (native media engine) and merged into openfl-native - but now (and lastly) been merged into lime and joined forces to create an agnostic, cross platform starting point to widen the haxe landscape for all frameworks and framework developers. +- See the wiki for a 1.0 wrapper [roadmap](https://github.com/openfl/lime/wiki/lime-wrapper-1.0-Roadmap). Expect docs, diagrams and breakdowns of how to get started using lime soon. See the examples/ folder for the basics for now. + +# Using Development Builds + + git clone https://github.com/openfl/lime + haxelib dev lime lime + git clone https://github.com/openfl/lime-build + haxelib dev lime-build lime-build + +After cloning, "lime/ndll" will be empty. You can build binaries for a platform, use "lime rebuild" or "openfl rebuild", such as: + + lime rebuild windows + lime rebuild windows,blackberry + lime rebuild linux -64 + lime rebuild android -debug + +If you are running Linux, you will (probably) need to install additional packages to build from the source. For an Ubuntu system, it may look like this: + + sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev g++ g++-multilib gcc-multilib + +For other platforms, the dependencies will be similar to compiling standard Lime/OpenFL applications for the platform, for example, you will need Visual Studio for Windows builds, Xcode for Mac and iOS builds, etc. Platforms which require "setup" step, such as Android, should have that completed, such as "lime setup android" + +The default "rebuild" for each target compiles all needed binaries, such as x86, armv5 and arm7 for release and debug. You can use "-debug", "-release", "-64" and "-32" to specify that you only want to rebuild one kind of binary. You can use commas to separate multiple builds. + +There is also a helpful "-rebuild" flag you can use in combination with other Lime/OpenFL commands, to rebuild the required binaries in addition to the meaning of the original command. For example, this will test the current application for Windows, while first building release platform binary before packaging: + + lime test windows -rebuild + +To return to release builds: + + haxelib dev lime diff --git a/examples/HerokuShaders/project.lime.xml b/examples/HerokuShaders/project.lime.xml deleted file mode 100644 index 84f4ab655..000000000 --- a/examples/HerokuShaders/project.lime.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/HerokuShaders/src/Main.hx b/examples/HerokuShaders/src/Main.hx deleted file mode 100644 index 1fc98e60e..000000000 --- a/examples/HerokuShaders/src/Main.hx +++ /dev/null @@ -1,330 +0,0 @@ - - //Ported and modified from OpenFL examples - //underscorediscovery - -import lime.utils.Assets; -import lime.LiME; - - //Import GL stuff from Lime -import lime.gl.GL; -import lime.gl.GLBuffer; -import lime.gl.GLProgram; -import lime.gl.GLShader; - - //utils -import lime.utils.Float32Array; -import lime.geometry.Matrix3D; -import lime.InputHandler.MouseEvent; - - //import the shader code for the examples - //todo : Port to assets like latest openfl example -import shaders.FragmentShader_4278_1; -import shaders.FragmentShader_5359_8; -import shaders.FragmentShader_5398_8; -import shaders.FragmentShader_5454_21; -import shaders.FragmentShader_5492; -import shaders.FragmentShader_5733; -import shaders.FragmentShader_5805_18; -import shaders.FragmentShader_5812; -import shaders.FragmentShader_5891_5; -import shaders.FragmentShader_6022; -import shaders.FragmentShader_6043_1; -import shaders.FragmentShader_6049; -import shaders.FragmentShader_6147_1; -import shaders.FragmentShader_6162; -import shaders.FragmentShader_6175; -import shaders.FragmentShader_6223_2; -import shaders.FragmentShader_6238; -import shaders.FragmentShader_6284_1; -import shaders.FragmentShader_6286; -import shaders.FragmentShader_6288_1; -import shaders.VertexShader; - -class Main { - - public var lib : LiME; - - - //A bunch of these shaders are expensive so for most users this is - //is a bad idea to just abuse their system when they run the sample. - //You can set the below value to true to see them though. - public var include_slow_expensive_examples : Bool = false; - public var slow_end_index : Int = 6; - - private var mouse_x : Int = 0; - private var mouse_y : Int = 0; - - //The maximum time to spend on a shader example before cycling - //We start really quickly, - //a) because we want to make sure the user knows there are more than 1 and - //b) because the first index is fixed, but the randomness can pick a new one - private static var maxTime = 2; - - //The current active shader example in the list - private var currentIndex:Int; - - //The OpenGL values - private var buffer:GLBuffer; - private var currentProgram:GLProgram; - private var positionAttribute:Dynamic; - private var timeUniform:Dynamic; - private var mouseUniform:Dynamic; - private var resolutionUniform:Dynamic; - private var backbufferUniform:Dynamic; - private var surfaceSizeUniform:Dynamic; - private var startTime:Dynamic; - private var vertexPosition:Dynamic; - - public function new() {} - - //Ready is called by lime when it has created the window etc. - //We can start using GL here. - public function ready( _lime : LiME ) { - - //Store a reference, in case we want it - lib = _lime; - - // Init the shaders and view - init(); - - } //ready - - public function init() { - - //Find the starting index - currentIndex = (include_slow_expensive_examples ? 0 : slow_end_index); - - //Create a vertex buffer, for a Quad, bind it and submit it once using STATIC draw so it stays in GPU - buffer = GL.createBuffer(); - GL.bindBuffer(GL.ARRAY_BUFFER, buffer); - GL.bufferData(GL.ARRAY_BUFFER, new Float32Array ([ -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0 ]), GL.STATIC_DRAW); - - //start the mouse center screen - //lime stores the window size in it's config (as well as other window options) - mouse_x = Std.int(lib.config.width/2); - mouse_y = Std.int(lib.config.height/2); - - //Compile the shader selected - compile(); - - } //init - - //lime will call this when the mouse moves, so we can get a position - public function onmousemove( e:MouseEvent ) { - - mouse_x = Std.int(e.x); - mouse_y = Std.int(e.y); - - } //onmousemove - - //we also set this on mouse down, so mobile has some interactivity (could also use ontouchdown) - public function onmousedown( e:MouseEvent ) { - - mouse_x = Std.int(e.x); - mouse_y = Std.int(e.y); - - } //onmousedown - - //called each frame by lime for logic (called before render) - public function update() { - - //check if we have passed the max time for watching this shader - var time = haxe.Timer.stamp() - startTime; - if (time > maxTime && fragmentShaders.length > 1) { - - //Pick a random example to show - - #if !mobile - if( include_slow_expensive_examples ) { - currentIndex = Std.random( fragmentShaders.length - 1 ); - } else { - currentIndex = slow_end_index + Std.random( (fragmentShaders.length - slow_end_index - 1) ); - } - #else - currentIndex = Std.random( fragmentShaders.length - 1 ); - #end - - //recompile using this index - compile(); - - //switch time if after the first one - if(maxTime == 2) maxTime = 10; - - } //if time is passed max time - - } //update - - - //Called each frame by lime, when the window wants to render - public function render() { - - //Set the viewport to the config window size - GL.viewport( 0, 0, lib.config.width, lib.config.height ); - - //If the shader failed to link or compile we don't render yet - if (currentProgram == null) return; - - //The current time is the time since the last shader started, and now - var time = haxe.Timer.stamp() - startTime; - - //Activate the current shader - GL.useProgram(currentProgram); - - //Pass the attributes to the shaders - GL.uniform1f( timeUniform, time ); - GL.uniform2f( mouseUniform, (mouse_x / lib.config.width) * 2 - 1, (mouse_y / lib.config.height) * 2 - 1 ); - GL.uniform2f( resolutionUniform, lib.config.width, lib.config.height ); - GL.uniform1i( backbufferUniform, 0 ); - GL.uniform2f( surfaceSizeUniform, lib.config.width, lib.config.height ); - - //Point to the buffer we created earlier to draw - GL.bindBuffer( GL.ARRAY_BUFFER, buffer ); - GL.vertexAttribPointer( positionAttribute, 2, GL.FLOAT, false, 0, 0 ); - GL.vertexAttribPointer( vertexPosition, 2, GL.FLOAT, false, 0, 0 ); - - //Clear the screen - GL.clearColor(0, 0, 0, 1); - GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT ); - - //And finally draw the quad! - GL.drawArrays (GL.TRIANGLES, 0, 6); - - } //render - - private function compile ():Void { - - var program = GL.createProgram (); - var vertex = VertexShader.source; - - //When on web specifically we prefix the shader with a required precision qualifier - #if desktop - var fragment = ""; - #else - var fragment = "precision mediump float;"; - #end - - fragment += fragmentShaders[currentIndex].source; - - var vs = createShader(vertex, GL.VERTEX_SHADER); - var fs = createShader(fragment, GL.FRAGMENT_SHADER); - - //Woops, this didn't compile so jump out - //todo : Add compiler logs. - if (vs == null || fs == null) { - return; - } - - //Attach the shaders to the program - GL.attachShader(program, vs); - GL.attachShader(program, fs); - //Clean up unnecessary shader references (they are stored by index in the Program) - GL.deleteShader(vs); - GL.deleteShader(fs); - - //Link the program on the GPU - GL.linkProgram (program); - - //Check if linking was good - if (GL.getProgramParameter (program, GL.LINK_STATUS) == 0) { - - trace( GL.getProgramInfoLog(program) ); - trace( "VALIDATE_STATUS: " + GL.getProgramParameter (program, GL.VALIDATE_STATUS)); - trace( "ERROR: " + GL.getError() ); - return; - - } //GL.LINK_STATUS == 0 - - //If we had an existing program? Clean up - if (currentProgram != null) { - GL.deleteProgram (currentProgram); - } - - //Store the new program - currentProgram = program; - //Activate the new program - GL.useProgram(currentProgram); - - //Make sure that the attributes are referenced correctly - positionAttribute = GL.getAttribLocation(currentProgram, "surfacePosAttrib"); - vertexPosition = GL.getAttribLocation (currentProgram, "position"); - //As well as enabled - GL.enableVertexAttribArray (vertexPosition); - GL.enableVertexAttribArray(positionAttribute); - - //And for the uniforms, we store their location because it can change per shader - timeUniform = GL.getUniformLocation(program, "time"); - mouseUniform = GL.getUniformLocation(program, "mouse"); - resolutionUniform = GL.getUniformLocation(program, "resolution"); - backbufferUniform = GL.getUniformLocation(program, "backbuffer"); - surfaceSizeUniform = GL.getUniformLocation(program, "surfaceSize"); - - //So that we can calculate the new shader running time - startTime = haxe.Timer.stamp(); - - } //compile - - //Take a source shader, compile it, check for errors and return the GLShader - private function createShader( source:String, type:Int ) : GLShader { - - var shader = GL.createShader (type); - - GL.shaderSource(shader, source); - GL.compileShader(shader); - - if (GL.getShaderParameter(shader, GL.COMPILE_STATUS) == 0) { - return null; - } - - return shader; - - } //createShader - - -#if !mobile - - //The list of shaders to cycle through - private static var fragmentShaders:Array = [ - //These are the more expensive ones, excluded by default - FragmentShader_6223_2, - FragmentShader_6175, - FragmentShader_6162, - FragmentShader_6049, - FragmentShader_5359_8, - FragmentShader_4278_1, - //These are the ok ones - FragmentShader_6286, - FragmentShader_6288_1, - FragmentShader_6284_1, - FragmentShader_6238, - FragmentShader_6147_1, - FragmentShader_6043_1, - FragmentShader_6022, - FragmentShader_5891_5, - FragmentShader_5805_18, - FragmentShader_5812, - FragmentShader_5733, - FragmentShader_5454_21, - FragmentShader_5492, - FragmentShader_5398_8 - - ]; - -#else //!mobile - - //These are mobile ones - private static var fragmentShaders:Array = [ - FragmentShader_6284_1, - FragmentShader_6238, - FragmentShader_6147_1, - FragmentShader_5891_5, - FragmentShader_5805_18, - FragmentShader_5492, - FragmentShader_5398_8 - ]; - -#end //if !mobile - - -} //Main class - - diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_4278_1.hx b/examples/HerokuShaders/src/shaders/FragmentShader_4278_1.hx deleted file mode 100644 index 517463dee..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_4278_1.hx +++ /dev/null @@ -1,98 +0,0 @@ -package shaders; - - -class FragmentShader_4278_1 { - - - //http://glsl.heroku.com/e#4278.1 - - - public static var source = " - - uniform float time; - uniform vec2 resolution; - uniform vec2 mouse; - - mat3 genRotMat(float a0,float x,float y,float z){ - float a=a0*3.1415926535897932384626433832795/180.0; - return mat3( - 1.0+(1.0-cos(a))*(x*x-1.0), - -z*sin(a)+(1.0-cos(a))*x*y, - y*sin(a)+(1.0-cos(a))*x*z, - z*sin(a)+(1.0-cos(a))*x*y, - 1.0+(1.0-cos(a))*(y*y-1.0), - -x*sin(a)+(1.0-cos(a))*y*z, - -y*sin(a)+(1.0-cos(a))*x*z, - x*sin(a)+(1.0-cos(a))*y*z, - 1.0+(1.0-cos(a))*(z*z-1.0) - ); - } - - float cubeDist(vec3 p){ - return max(abs(p.x),max(abs(p.y),abs(p.z))); - } - - void main(){ - float spread=1.0; - float total=0.0; - float delta=0.01; - float cameraZ=-1.75; - float nearZ=-1.0; - float farZ=1.0; - float gs=0.0; - int iter=0; - vec3 col=vec3(0.0,0.0,0.0); - vec3 ray=vec3(0.0,0.0,0.0); - mat3 rot=genRotMat(sin(time/4.13)*360.0,1.0,0.0,0.0); - rot=rot*genRotMat(sin(time/4.64)*360.0,0.0,1.0,0.0); - rot=rot*genRotMat(sin(time/4.24)*360.0,0.0,0.0,1.0); - vec2 p=vec2(0.0,0.0); - p.x=gl_FragCoord.x/resolution.y-0.5*resolution.x/resolution.y; - p.y=gl_FragCoord.y/resolution.y-0.5; - ray.xy+=p.xy*spread*(nearZ-cameraZ); - vec3 rayDir=vec3(spread*p.xy*delta,delta); - vec3 tempDir=rayDir*rot; - vec3 norm; - ray.z=nearZ; - bool refracted=false; - for(int i=0;i<250;i++){ - vec3 temp; - vec3 tempc; - float val; - temp=ray.xyz*rot; - tempc=temp; - float thres=0.5; - if(tempc.x<0.0)tempc.x=abs(tempc.x); - if(tempc.x=farZ)break; - } - col.x=col.x/float(iter); - col.y=col.y/float(iter); - col.z=col.z/float(iter); - gl_FragColor=vec4(col,1.0); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_5359_8.hx b/examples/HerokuShaders/src/shaders/FragmentShader_5359_8.hx deleted file mode 100644 index 1ea8d2f4a..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_5359_8.hx +++ /dev/null @@ -1,146 +0,0 @@ -package shaders; - - -class FragmentShader_5359_8 { - - - //http://glsl.heroku.com/e#5359.8 - - - public static var source = " - - uniform float time; - uniform vec2 resolution; - - - // NEBULA - CoffeeBreakStudios.com (CBS) - // Work in progress.... - // - // 3148.26: Switched from classic to simplex noise - // 3148.27: Reduced number of stars - // 3249.0: Switched to fast computed 3D noise. Less quality but ~ 2x faster - // 3249.5: Removed use of random number generator to gain performance - // 3265.0: Added rotation: glsl.heroku.com/e#3005.1 - // 3265.6: Faster random number generator - // 5359.0: Added Barrel distortion and different starfield: http://glsl.heroku.com/e#5334.3 - - //Utility functions - - vec3 fade(vec3 t) { - return vec3(1.0,1.0,1.0); - } - - vec2 rotate(vec2 point, float rads) { - float cs = cos(rads); - float sn = sin(rads); - return point * mat2(cs, -sn, sn, cs); - } - - vec4 randomizer4(const vec4 x) - { - vec4 z = mod(x, vec4(5612.0)); - z = mod(z, vec4(3.1415927 * 2.0)); - return(fract(cos(z) * vec4(56812.5453))); - } - - float rand(vec2 co){ - return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); - } - - // Fast computed noise - // http://www.gamedev.net/topic/502913-fast-computed-noise/ - - const float A = 1.0; - const float B = 57.0; - const float C = 113.0; - const vec3 ABC = vec3(A, B, C); - const vec4 A3 = vec4(0, B, C, C+B); - const vec4 A4 = vec4(A, A+B, C+A, C+A+B); - - float cnoise4(const in vec3 xx) - { - vec3 x = mod(xx + 32768.0, 65536.0); - vec3 ix = floor(x); - vec3 fx = fract(x); - vec3 wx = fx*fx*(3.0-2.0*fx); - float nn = dot(ix, ABC); - - vec4 N1 = nn + A3; - vec4 N2 = nn + A4; - vec4 R1 = randomizer4(N1); - vec4 R2 = randomizer4(N2); - vec4 R = mix(R1, R2, wx.x); - float re = mix(mix(R.x, R.y, wx.y), mix(R.z, R.w, wx.y), wx.z); - - return 1.0 - 2.0 * re; - } - float surface3 ( vec3 coord, float frequency ) { - - float n = 0.0; - - n += 1.0 * abs( cnoise4( coord * frequency ) ); - n += 0.5 * abs( cnoise4( coord * frequency * 2.0 ) ); - n += 0.25 * abs( cnoise4( coord * frequency * 4.0 ) ); - n += 0.125 * abs( cnoise4( coord * frequency * 8.0 ) ); - n += 0.0625 * abs( cnoise4( coord * frequency * 16.0 ) ); - - return n; - } - - vec2 barrelDistortion(vec2 coord) { - vec2 cc = coord;// - 0.5; - float dist = dot(cc, cc); - return coord + cc * (dist * dist) * .4; - } - - void main( void ) { - float rads = radians(time*3.15); - //vec2 position = gl_FragCoord.xy / resolution.xy; - vec2 position=barrelDistortion(-1.0+2.0*((gl_FragCoord.xy)/resolution.xy)); - vec2 positionStars = ( gl_FragCoord.xy - resolution.xy*.5 ) / resolution.x; - position += rotate(position, rads); - float n = surface3(vec3(position*sin(time*0.1), time * 0.05)*mat3(1,sin(1.0),0,0,.8,.6,0,-.6,.8),0.9); - float n2 = surface3(vec3(position*cos(time*0.1), time * 0.04)*mat3(1,cos(1.0),0,0,.8,.6,0,-.6,.8),0.8); - float lum = length(n); - float lum2 = length(n2); - - vec3 tc = pow(vec3(1.0-lum),vec3(sin(position.x)+cos(time)+4.0,8.0+sin(time)+4.0,8.0)); - vec3 tc2 = pow(vec3(1.1-lum2),vec3(5.0,position.y+cos(time)+7.0,sin(position.x)+sin(time)+2.0)); - vec3 curr_color = (tc*0.8) + (tc2*0.5); - - - // 256 angle steps - float angle = atan(positionStars.y,positionStars.x)/(2.*3.14159265359); - angle += rads*0.5; - angle -= floor(angle); - - float rad = length(positionStars); - - float color = 0.0; - for (int i = 0; i < 10; i++) { - float angleFract = fract(angle*256.); - float angleRnd = floor(angle*256.)+1.; - float angleRnd1 = fract(angleRnd*fract(angleRnd*.7235)*45.1); - float angleRnd2 = fract(angleRnd*fract(angleRnd*.82657)*13.724); - float t = time+angleRnd1*10.; - float radDist = sqrt(angleRnd2+float(i)); - - float adist = radDist/rad*.1; - float dist = (t*.1+adist); - dist = abs(fract(dist)-.5); - color += max(0.,.5-dist*40./adist)*(.5-abs(angleFract-.5))*5./adist/radDist; - - angle = fract(angle+.61); - } - float color1 = color*rad; - - //curr_color += color/(n+n2); - - - gl_FragColor = vec4(curr_color, 1.0)+vec4( color1,color1,color,color1)/(n+n2); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_5398_8.hx b/examples/HerokuShaders/src/shaders/FragmentShader_5398_8.hx deleted file mode 100644 index 0f91088d6..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_5398_8.hx +++ /dev/null @@ -1,44 +0,0 @@ -package shaders; - - -class FragmentShader_5398_8 { - - - //http://glsl.heroku.com/e#5398.8 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - - void main( void ) { - - float scale = resolution.y / 100.0; - float ring = 50.0; - float radius = resolution.x*1.0; - float gap = scale*.5; - vec2 pos = gl_FragCoord.xy - resolution.xy*.5; - - float d = length(pos); - - // Create the wiggle - d += (sin(pos.y*0.25/scale+time)*sin(pos.x*0.25/scale+time*.5))*scale*2.0; - - // Compute the distance to the closest ring - float v = mod(d + radius/(ring*2.0), radius/ring); - v = abs(v - radius/(ring*2.0)); - - v = clamp(v-gap, 0.0, 1.0); - - d /= radius; - vec3 m = fract((d-1.0)*vec3(ring*-.5, -ring, ring*.25)*0.5); - - gl_FragColor = vec4( m*v, 1.0 ); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_5454_21.hx b/examples/HerokuShaders/src/shaders/FragmentShader_5454_21.hx deleted file mode 100644 index 1f1605329..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_5454_21.hx +++ /dev/null @@ -1,141 +0,0 @@ -package shaders; - - -class FragmentShader_5454_21 { - - - //http://glsl.heroku.com/e#5454.21 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - - // from http://glsl.heroku.com/e#5484.0 - vec3 asteroids( vec2 position ) { - - // 256 angle steps - float angle = atan(position.y,position.x)/(2.*3.14159265359); - angle -= floor(angle); - float rad = length(position); - - float color = 0.0; - for (int i = 0; i < 5; i++) { - float angleFract = fract(angle*256.); - float angleRnd = floor(angle*256.)+1.; - float angleRnd1 = fract(angleRnd*fract(angleRnd*.7235)*45.1); - float angleRnd2 = fract(angleRnd*fract(angleRnd*.82657)*13.724); - float t = -time+angleRnd1*10.; - float radDist = sqrt(angleRnd2+float(i)); - - float adist = radDist/rad*.1; - float dist = (t*.1+adist); - dist = abs(fract(dist)-.5); - color += max(0.,.5-dist*40./adist)*(.5-abs(angleFract-.5))*5./adist/radDist; - - angle = fract(angle+.61); - } - - return vec3( color )*.3; - } - - // from http://glsl.heroku.com/e#5248.0 - #define BIAS 0.1 - #define SHARPNESS 3.0 - vec3 star(vec2 position, float BLADES) { - float blade = clamp(pow(sin(atan(position.y,position.x )*BLADES)+BIAS, SHARPNESS), 0.0, 1.0); - vec3 color = mix(vec3(-0.34, -0.5, -1.0), vec3(0.0, -0.5, -1.0), (position.y + 1.0) * 0.25); - float d = 1.0/length(position) * 0.075; - color += vec3(0.95, 0.65, 0.30) * d; - color += vec3(0.95, 0.45, 0.30) * min(1.0, blade *0.7) * d; - return color; - } - - vec3 star2(vec2 position, float BLADES) { - float blade = clamp(pow(sin(atan(position.y,position.x )*BLADES + time*.5)+BIAS, 8.0), 0.0, 1.0); - vec3 color = mix(vec3(-0.34, -0.5, -0.0), vec3(0.0, -0.5, -0.0), (position.y + 1.0) * 0.25); - float d = 1.0/length(position) * 0.075; - color += vec3(0.95, 0.65, 0.30) * d; - color += vec3(0.95, 0.45, 0.30) * min(1.0, blade *0.7)*0.5; - return max(color.rgb, 0.0)*.5; - } - - - // Tweaked from http://glsl.heroku.com/e#4982.0 - float hash( float n ) { return fract(sin(n)*43758.5453); } - - float noise( in vec2 x ) - { - vec2 p = floor(x); - vec2 f = fract(x); - f = f*f*(3.0-2.0*f); - float n = p.x + p.y*57.0; - float res = mix(mix(hash(n+0.0), hash(n+1.0),f.x), mix(hash(n+57.0), hash(n+58.0),f.x),f.y); - return res; - } - - vec3 cloud(vec2 p) { - vec3 f = vec3(0.0); - f += 0.5000*noise(p*10.0)*vec3(.45, .55, 1.0); - f += 0.2500*noise(p*20.0)*vec3(.85, .45, 1.0); - f += 0.1250*noise(p*40.0)*vec3(1.0, .00, 0.3); - f += 0.0625*noise(p*80.0)*vec3(1.0, 1.0, 1.0); - return f*.5; - } - - const float SPEED = 0.005; - const float SCALE = 80.0; - const float DENSITY = 1.5; - const float BRIGHTNESS = 10.0; - vec2 ORIGIN = resolution.xy*.5; - - float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } - - vec3 layer(float i, vec2 pos, float dist, vec2 coord) { - float a = pow((1.0-dist),20.0); - float t = i*10.0 - time*i*i; - float r = coord.x - (t*SPEED); - float c = fract(a+coord.y + i*.543); - vec2 p = vec2(r, c*.5)*SCALE*(4.0/(i*i)); - vec2 uv = fract(p)*2.0-1.0; - float m = clamp((rand(floor(p))-DENSITY/i)*BRIGHTNESS, 0.0, 1.0); - return clamp(star(uv*.5, 6.0)*m*dist, 0.0, 1.0); - } - - void main( void ) { - - vec2 pos = gl_FragCoord.xy - ORIGIN ; - float dist = length(pos) / resolution.y; - vec2 coord = vec2(pow(dist, 0.1), atan(pos.x, pos.y) / (3.1415926*2.0)); - - // Nebulous cloud - vec3 color = cloud(pos/resolution); - - // Background stars - float a = pow((1.0-dist),20.0); - float t = time*-.05; - float r = coord.x - (t*0.005); - float c = fract(a+coord.y + 0.0*.543); - vec2 p = vec2(r, c*.5)*4000.0; - vec2 uv = fract(p)*2.0-1.0; - float m = clamp((rand(floor(p))-.9)*10.0, 0.0, 1.0); - color += clamp((1.0-length(uv*2.0))*m*dist, 0.0, 1.0); - - color += asteroids(pos/resolution.x); - - // Flying stars into black hole - color += layer(2.0, pos, dist, coord); - color += layer(3.0, pos, dist, coord); - color += layer(4.0, pos, dist, coord); - - color += star2(pos/resolution, 2.0); - - gl_FragColor = vec4(color, 1.0); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_5492.hx b/examples/HerokuShaders/src/shaders/FragmentShader_5492.hx deleted file mode 100644 index 988852255..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_5492.hx +++ /dev/null @@ -1,140 +0,0 @@ -package shaders; - - -class FragmentShader_5492 { - - - //http://glsl.heroku.com/e#5492.0 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - - - // Helper constants - #define F2 0.366025403 - #define G2 0.211324865 - #define K 0.0243902439 // 1/41 - - // Permutation polynomial - float permute(float x) { - return mod((34.0 * x + 1.0)*x, 289.0); - } - - // Gradient mapping with an extra rotation. - vec2 grad2(vec2 p, float rot) { - #if 1 - // Map from a line to a diamond such that a shift maps to a rotation. - float u = permute(permute(p.x) + p.y) * K + rot; // Rotate by shift - u = 4.0 * fract(u) - 2.0; - return vec2(abs(u)-1.0, abs(abs(u+1.0)-2.0)-1.0); - #else - #define TWOPI 6.28318530718 - // For more isotropic gradients, sin/cos can be used instead. - float u = permute(permute(p.x) + p.y) * K + rot; // Rotate by shift - u = fract(u) * TWOPI; - return vec2(cos(u), sin(u)); - #endif - } - - float srdnoise(in vec2 P, in float rot, out vec2 grad) { - - // Transform input point to the skewed simplex grid - vec2 Ps = P + dot(P, vec2(F2)); - - // Round down to simplex origin - vec2 Pi = floor(Ps); - - // Transform simplex origin back to (x,y) system - vec2 P0 = Pi - dot(Pi, vec2(G2)); - - // Find (x,y) offsets from simplex origin to first corner - vec2 v0 = P - P0; - - // Pick (+x, +y) or (+y, +x) increment sequence - vec2 i1 = (v0.x > v0.y) ? vec2(1.0, 0.0) : vec2 (0.0, 1.0); - - // Determine the offsets for the other two corners - vec2 v1 = v0 - i1 + G2; - vec2 v2 = v0 - 1.0 + 2.0 * G2; - - // Wrap coordinates at 289 to avoid float precision problems - Pi = mod(Pi, 289.0); - - // Calculate the circularly symmetric part of each noise wiggle - vec3 t = max(0.5 - vec3(dot(v0,v0), dot(v1,v1), dot(v2,v2)), 0.0); - vec3 t2 = t*t; - vec3 t4 = t2*t2; - - // Calculate the gradients for the three corners - vec2 g0 = grad2(Pi, rot); - vec2 g1 = grad2(Pi + i1, rot); - vec2 g2 = grad2(Pi + 1.0, rot); - - // Compute noise contributions from each corner - vec3 gv = vec3(dot(g0,v0), dot(g1,v1), dot(g2,v2)); // ramp: g dot v - vec3 n = t4 * gv; // Circular kernel times linear ramp - - // Compute partial derivatives in x and y - vec3 temp = t2 * t * gv; - vec3 gradx = temp * vec3(v0.x, v1.x, v2.x); - vec3 grady = temp * vec3(v0.y, v1.y, v2.y); - grad.x = -8.0 * (gradx.x + gradx.y + gradx.z); - grad.y = -8.0 * (grady.x + grady.y + grady.z); - grad.x += dot(t4, vec3(g0.x, g1.x, g2.x)); - grad.y += dot(t4, vec3(g0.y, g1.y, g2.y)); - grad *= 40.0; - - // Add contributions from the three corners and return - return 40.0 * (n.x + n.y + n.z); - } - - - vec2 complex_mul(vec2 factorA, vec2 factorB){ - return vec2( factorA.x*factorB.x - factorA.y*factorB.y, factorA.x*factorB.y + factorA.y*factorB.x); - } - - vec2 torus_mirror(vec2 uv){ - return vec2(1.)-abs(fract(uv*.5)*2.-1.); - } - - float sigmoid(float x) { - return 2./(1. + exp2(-x)) - 1.; - } - - float smoothcircle(vec2 uv, float radius, float sharpness){ - return 0.5 - sigmoid( ( length( (uv - 0.5)) - radius) * sharpness) * 0.5; - } - - - void main() { - - vec2 posScale = vec2(2.0); - - vec2 aspect = vec2(1.,resolution.y/resolution.x); - vec2 uv = 0.5 + (gl_FragCoord.xy * vec2(1./resolution.x,1./resolution.y) - 0.5)*aspect; - float mouseW = atan((mouse.y - 0.5)*aspect.y, (mouse.x - 0.5)*aspect.x); - vec2 mousePolar = vec2(sin(mouseW), cos(mouseW)); - vec2 offset = (mouse - 0.5)*4.; - offset = - complex_mul(offset, mousePolar) +time*0.0; - vec2 uv_distorted = uv; - - float filter = smoothcircle( -mouse + 0.5 +uv_distorted, 0.15, 64.); - uv_distorted = complex_mul(((uv_distorted - 0.5)*mix(2., 12., filter)), mousePolar) + offset; - - vec2 p = uv_distorted; - vec2 g1, g2; - // vec2 p = ( gl_FragCoord.xy / resolution.xy ) * 6.0; - float n1 = srdnoise(p*0.5, 0.0*time, g1); - float n2 = srdnoise(p*2.0 + g1*0.5, 0.51*time, g2); - float n3 = srdnoise(p*4.0 + g1*0.5 + g2*0.25, 0.77*time, g2); - gl_FragColor = vec4(vec3(0.4, 0.5, 0.6) + vec3(n1+0.75*n2+0.5*n3), 1.0); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_5733.hx b/examples/HerokuShaders/src/shaders/FragmentShader_5733.hx deleted file mode 100644 index 1d0e00289..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_5733.hx +++ /dev/null @@ -1,37 +0,0 @@ -package shaders; - - -class FragmentShader_5733 { - - - //http://glsl.heroku.com/e#5733.0 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - varying vec2 surfacePosition; - - - void main( void ) { - vec2 p = surfacePosition; - float speed = 0.25; - vec3 color = vec3(0.5,0.2,0.1); - vec2 loc = vec2(cos(time/4.0*speed)/1.9-cos(time/2.0*speed)/3.8, - sin(time/4.0*speed)/1.9-sin(time/2.0*speed)/3.8 - ); - float depth; - for(int i = 0; i < 100; i+=1){ - p = vec2(p.x*p.x-p.y*p.y,2.0*p.y*p.x)+loc; - depth = float(i); - if((p.x*p.x-p.y*p.y) >= 25.0) break; - } - gl_FragColor = vec4(clamp(color*depth*0.9, 0.0, 2.0)*mod(gl_FragCoord.y, 2.0), 2.0 ); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_5805_18.hx b/examples/HerokuShaders/src/shaders/FragmentShader_5805_18.hx deleted file mode 100644 index e99d299e6..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_5805_18.hx +++ /dev/null @@ -1,57 +0,0 @@ -package shaders; - - -class FragmentShader_5805_18 { - - - //http://glsl.heroku.com/e#5805.18 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - - float function_f (float x) { - return + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x+200.0)*0.1)) - - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x+100.0)*0.1)) - + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp(x*0.1)) - - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x-100.0)*0.1)) - + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x-200.0)*0.1)) - + sin(x*0.1 - time*10.0 + mouse.x * 10.0)*50.0; - } - - float function_g (float x) { - return - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x+200.0)*0.1)) - + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x+100.0)*0.1)) - - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp(x*0.1)) - + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x-100.0)*0.1)) - - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x-200.0)*0.1)) - + sin(x*0.1 + time*5.0 - mouse.x * 10.0)*50.0; - } - - - void main( void ) { - - vec3 color_1 = vec3(0.25, sin(time), cos(time)); - vec3 color_2 = vec3(0.5, 0.25, cos(time)); - - vec2 pos = gl_FragCoord.xy; - - pos.y -= resolution.y / 2.0; - pos.x -= resolution.x / 2.0; - - float intensity_f = 16.0 / abs(pos.y - function_f(pos.x)); - intensity_f = pow(intensity_f, 0.5); - - float intensity_g = 16.0 / abs(pos.y - function_g(pos.x)); - intensity_g += pow(intensity_g, 0.5); - - gl_FragColor = vec4((color_1 * intensity_f + color_2 * intensity_g)*mod(gl_FragCoord.y, 2.0), 1); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_5812.hx b/examples/HerokuShaders/src/shaders/FragmentShader_5812.hx deleted file mode 100644 index d3c8c6d4a..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_5812.hx +++ /dev/null @@ -1,57 +0,0 @@ -package shaders; - - -class FragmentShader_5812 { - - - //http://glsl.heroku.com/e#5812 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - - float random(vec2 v) - { - return fract(sin(dot(v ,vec2(13.9898,78.233))) * (10000.0+time*0.05)); - } - - void main( void ) - { - const int numColors = 3; - vec3 colors[numColors]; - colors[0] = vec3( 0.3, 0.8, 0.8); - colors[1] = vec3( 0.8, 0.9, 0.4); - colors[2] = vec3( 0.4, 0.4, 0.5); - - vec2 screenPos = gl_FragCoord.xy; - vec2 screenPosNorm = gl_FragCoord.xy / resolution.xy; - vec2 position = screenPosNorm + mouse / 4.0; - - // calc block - vec2 screenBlock0 = floor(screenPos*0.16 + vec2(time,0) + mouse*3.0); - vec2 screenBlock1 = floor(screenPos*0.08 + vec2(time*1.5,0) + mouse*5.0); - vec2 screenBlock2 = floor(screenPos*0.02 + vec2(time*2.0,0)+mouse*10.0); - float rand0 = random(screenBlock0); - float rand1 = random(screenBlock1); - float rand2 = random(screenBlock2); - - float rand = rand1; - if ( rand2 < 0.05 ) { rand = rand2; } - - // block color - vec3 color = mix( colors[0], colors[1], pow(rand,5.0) ); - if ( rand < 0.05 ) { color=colors[2]; } - - float vignette = 1.6-length(screenPosNorm*2.0-1.0); - vec4 finalColor = vec4(color*vignette, 1.0); - - gl_FragColor = finalColor; - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_5891_5.hx b/examples/HerokuShaders/src/shaders/FragmentShader_5891_5.hx deleted file mode 100644 index 55a4e3883..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_5891_5.hx +++ /dev/null @@ -1,53 +0,0 @@ -package shaders; - - -class FragmentShader_5891_5 { - - - //http://glsl.heroku.com/e#5891.5 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - - const float Tau = 6.2832; - const float speed = .02; - const float density = .04; - const float shape = .04; - - float random( vec2 seed ) { - return fract(sin(seed.x+seed.y*1e3)*1e5); - } - - float Cell(vec2 coord) { - vec2 cell = fract(coord) * vec2(.5,2.) - vec2(.0,.5); - return (1.-length(cell*2.-1.))*step(random(floor(coord)),density)*2.; - } - - void main( void ) { - - vec2 p = gl_FragCoord.xy / resolution - mouse; - - float a = fract(atan(p.x, p.y) / Tau); - float d = length(p); - - vec2 coord = vec2(pow(d, shape), a)*256.; - vec2 delta = vec2(-time*speed*256., .5); - - float c = 0.; - for(int i=0; i<3; i++) { - coord += delta; - c = max(c, Cell(coord)); - } - - gl_FragColor = vec4(c * d); - - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_6022.hx b/examples/HerokuShaders/src/shaders/FragmentShader_6022.hx deleted file mode 100644 index 238817324..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_6022.hx +++ /dev/null @@ -1,97 +0,0 @@ -package shaders; - - -class FragmentShader_6022 { - - - //http://glsl.heroku.com/e#6022.0 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - varying vec2 surfacePosition; - - float rand(vec2 co){ - return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43748.5453); - } - float cerp(float a, float b, float i) - { - if(i<0.) - i += 1.; - i *= 3.14159265; - i = (1.-cos(i))/2.; - return a*(1.-i)+b*i; - } - float lerp(float a, float b, float i) - { - if(i<0.) - i+=1.; - return a*(1.-i)+b*i; - } - vec3 lerp(vec3 a, vec3 b, float i) - { - if(i<0.) - i+=1.; - return a*(1.-i)+b*i; - } - float posrand(vec2 pos, float width, float height) - { - return rand(vec2(int(pos.x*width),int(pos.y*height))); - } - float tdposrand(vec2 pos, float width, float height) - { - float n1, n2, n3, n4, n5, n6; - n1 = posrand(pos,width,height); - n2 = posrand(vec2(pos.x+1./width,pos.y),width,height); - n3 = posrand(vec2(pos.x,pos.y+1./height),width,height); - n4 = posrand(vec2(pos.x+1./width,pos.y+1./height),width,height); - n5 = cerp(n1,n2,pos.x*width-float(int(pos.x*width))); - n6 = cerp(n3,n4,pos.x*width-float(int(pos.x*width))); - return cerp(n5,n6,pos.y*height-float(int(pos.y*height))); - } - - vec3 readcolpath(vec3 one, vec3 two, vec3 thr, vec3 fou, float i) - { - int num = int(i*3.); - if(num==0) - return lerp(one,two,i*3.-float(num)); - if(num==1) - return lerp(two,thr,i*3.-float(num)); - if(num==2) - return lerp(thr,fou,i*3.-float(num)); - return fou; - } - void main( void ) { - - vec2 position = surfacePosition+.5; - vec2 odd = vec2(0,time/5.); - vec3 col1 = vec3(1.,0.25,0.); - vec3 col2 = vec3(.45,0.2,0.); - vec3 col3 = vec3(0.2,.1,0.); - vec3 col4 = vec3(.4,.3,.25); - float color = 0.0; - position = position*(1.+1./12.)+vec2(length(vec2(tdposrand(position-odd,2.,2.),tdposrand(position*4.3-odd,2.,2.))))/12.; - if(position.y>0.) - { - //color += tdposrand(position-odd,1000.,1000.)/5.; - color += tdposrand(position-odd,50.,50.)/8.; - color += tdposrand(position-odd,20.,20.)/3.; - color += tdposrand(position-odd,10.,10.)/2.; - color += tdposrand(position-odd,5.,5.); - color /= position.y*1.; - } - else - { - color = 16.0; - } - gl_FragColor = vec4( vec3( color/2. )*readcolpath(col1,col2,col3,col4,color/16.), 1.0 ); - - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_6043_1.hx b/examples/HerokuShaders/src/shaders/FragmentShader_6043_1.hx deleted file mode 100644 index af7a013f6..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_6043_1.hx +++ /dev/null @@ -1,150 +0,0 @@ -package shaders; - - -class FragmentShader_6043_1 { - - - //http://glsl.heroku.com/e#6043.1 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - - //.h - vec3 sim(vec3 p,float s); - vec2 rot(vec2 p,float r); - vec2 rotsim(vec2 p,float s); - - //nice stuff :) - vec2 makeSymmetry(vec2 p){ - vec2 ret=p; - ret=rotsim(ret,5.08052); - ret.x=abs(ret.x); - return ret; - } - - float makePoint(float x,float y,float fx,float fy,float sx,float sy,float t){ - float xx=x+tan(t*fx)*sx; - float yy=y-tan(t*fy)*sy; - return 0.5/sqrt(abs(x*xx+yy*yy)); - } - - - - //util functions - const float PI=5.08052; - - vec3 sim(vec3 p,float s){ - vec3 ret=p; - ret=p+s/2.0; - ret=fract(ret/s)*s-s/2.0; - return ret; - } - - vec2 rot(vec2 p,float r){ - vec2 ret; - ret.x=p.x*cos(r)-p.y*sin(r); - ret.y=p.x*sin(r)+p.y*cos(r); - return ret; - } - - vec2 rotsim(vec2 p,float s){ - vec2 ret=p; - ret=rot(p,-PI/(s*2.0)); - ret=rot(p,floor(atan(ret.x,ret.y)/PI*s)*(PI/s)); - return ret; - } - //Util stuff end - - - - vec2 complex_mul(vec2 factorA, vec2 factorB){ - return vec2( factorA.x*factorB.x - factorA.y*factorB.y, factorA.x*factorB.y + factorA.y*factorB.x); - } - - vec2 torus_mirror(vec2 uv){ - return vec2(1.)-abs(fract(uv*.5)*2.-1.); - } - - float sigmoid(float x) { - return 2./(1. + exp2(-x)) - 1.; - } - - float smoothcircle(vec2 uv, float radius, float sharpness){ - return 0.5 - sigmoid( ( length( (uv - 0.5)) - radius) * sharpness) * 0.5; - } - - - void main() { - - vec2 posScale = vec2(2.0); - - vec2 aspect = vec2(1.,resolution.y/resolution.x); - vec2 uv = 0.5 + (gl_FragCoord.xy * vec2(1./resolution.x,1./resolution.y) - 0.5)*aspect; - float mouseW = atan((mouse.y - 0.5)*aspect.y, (mouse.x - 0.5)*aspect.x); - vec2 mousePolar = vec2(sin(mouseW), cos(mouseW)); - vec2 offset = (mouse - 0.5)*2.*aspect; - offset = - complex_mul(offset, mousePolar) +time*0.0; - vec2 uv_distorted = uv; - - float filter = smoothcircle( uv_distorted, 0.12, 100.); - uv_distorted = complex_mul(((uv_distorted - 0.5)*mix(2., 6., filter)), mousePolar) + offset; - - - vec2 p=(gl_FragCoord.xy/resolution.x)*2.0-vec2(1.0,resolution.y/resolution.x); - p = uv_distorted; - p.y=-p.y; - p=p*2.0; - - p=makeSymmetry(p); - - float x=p.x; - float y=p.y; - - float t=time*0.1618; - - float a= - makePoint(x,y,3.3,2.9,0.3,0.3,t); - a=a+makePoint(x,y,1.9,2.0,0.4,0.4,t); - a=a+makePoint(x,y,0.8,0.7,0.4,0.5,t); - a=a+makePoint(x,y,2.3,0.1,0.6,0.3,t); - a=a+makePoint(x,y,0.8,1.7,0.5,0.4,t); - a=a+makePoint(x,y,0.3,1.0,0.4,0.4,t); - a=a+makePoint(x,y,1.4,1.7,0.4,0.5,t); - a=a+makePoint(x,y,1.3,2.1,0.6,0.3,t); - a=a+makePoint(x,y,1.8,1.7,0.5,0.4,t); - - float b= - makePoint(x,y,1.2,1.9,0.3,0.3,t); - b=b+makePoint(x,y,0.7,2.7,0.4,0.4,t); - b=b+makePoint(x,y,1.4,0.6,0.4,0.5,t); - b=b+makePoint(x,y,2.6,0.4,0.6,0.3,t); - b=b+makePoint(x,y,0.7,1.4,0.5,0.4,t); - b=b+makePoint(x,y,0.7,1.7,0.4,0.4,t); - b=b+makePoint(x,y,0.8,0.5,0.4,0.5,t); - b=b+makePoint(x,y,1.4,0.9,0.6,0.3,t); - b=b+makePoint(x,y,0.7,1.3,0.5,0.4,t); - - float c= - makePoint(x,y,3.7,0.3,0.3,0.3,t); - c=c+makePoint(x,y,1.9,1.3,0.4,0.4,t); - c=c+makePoint(x,y,0.8,0.9,0.4,0.5,t); - c=c+makePoint(x,y,1.2,1.7,0.6,0.3,t); - c=c+makePoint(x,y,0.3,0.6,0.5,0.4,t); - c=c+makePoint(x,y,0.3,0.3,0.4,0.4,t); - c=c+makePoint(x,y,1.4,0.8,0.4,0.5,t); - c=c+makePoint(x,y,0.2,0.6,0.6,0.3,t); - c=c+makePoint(x,y,1.3,0.5,0.5,0.4,t); - - vec3 d=vec3(a+b,b+c,c)/32.0; - - gl_FragColor = vec4(d.x,d.y,d.z,1.0); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_6049.hx b/examples/HerokuShaders/src/shaders/FragmentShader_6049.hx deleted file mode 100644 index 2ecc48a0a..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_6049.hx +++ /dev/null @@ -1,202 +0,0 @@ -package shaders; - - -class FragmentShader_6049 { - - - //http://glsl.heroku.com/e#6049.0 - - - public static var source = " - - uniform vec2 resolution; - uniform float time; - uniform vec2 mouse; - - //Util Start - float PI=3.14159265; - - vec2 ObjUnion( - in vec2 obj0, - in vec2 obj1) - { - if (obj0.x0.0) fp.x=-fp.x; - if (fp.x>0.0) return vec3(0.0,0.0,0.0); - else return vec3(1.0,1.0,1.0); - } - - //Scene End - - float raymarching( - in vec3 prp, - in vec3 scp, - in int maxite, - in float precis, - in float startf, - in float maxd, - out float objid) - { - const vec3 e=vec3(0.1,0,0.0); - vec2 s=vec2(startf,0.0); - vec3 c,p,n; - float f=startf; - for(int i=0;i<256;i++){ - if (abs(s.x)maxd||i>maxite) break; - f+=s.x; - p=prp+scp*f; - s=obj(p); - objid=s.y; - } - if (f>maxd) objid=-1.0; - return f; - } - - - vec3 camera( - in vec3 prp, - in vec3 vrp, - in vec3 vuv, - in float vpd) - { - vec2 vPos=-1.0+2.0*gl_FragCoord.xy/resolution.xy; - vec3 vpn=normalize(vrp-prp); - vec3 u=normalize(cross(vuv,vpn)); - vec3 v=cross(vpn,u); - vec3 scrCoord=prp+vpn*vpd+vPos.x*u*resolution.x/resolution.y+vPos.y*v; - return normalize(scrCoord-prp); - } - - vec3 normal(in vec3 p) - { - //tetrahedron normal - const float n_er=0.01; - float v1=obj(vec3(p.x+n_er,p.y-n_er,p.z-n_er)).x; - float v2=obj(vec3(p.x-n_er,p.y-n_er,p.z+n_er)).x; - float v3=obj(vec3(p.x-n_er,p.y+n_er,p.z-n_er)).x; - float v4=obj(vec3(p.x+n_er,p.y+n_er,p.z+n_er)).x; - return normalize(vec3(v4+v1-v3-v2,v3+v4-v1-v2,v2+v4-v3-v1)); - } - - vec3 render( - in vec3 prp, - in vec3 scp, - in int maxite, - in float precis, - in float startf, - in float maxd, - in vec3 background, - in vec3 light, - in float spec, - in vec3 ambLight, - out vec3 n, - out vec3 p, - out float f, - out float objid) - { - objid=-1.0; - f=raymarching(prp,scp,maxite,precis,startf,maxd,objid); - if (objid>-0.5){ - p=prp+scp*f; - vec3 c=obj_c(p); - n=normal(p); - vec3 cf=phong(p,prp,n,light,c,spec,ambLight); - return vec3(cf); - } - f=maxd; - return vec3(background); //background color - } - - void main(void){ - - //Camera animation - vec3 vuv=vec3(0,1,0); - vec3 vrp=vec3(time*4.0,0.0,0.0); - float mx=mouse.x*PI*2.0; - float my=mouse.y*PI/2.01; - vec3 prp=vrp+vec3(cos(my)*cos(mx),sin(my),cos(my)*sin(mx))*12.0; //Trackball style camera pos - float vpd=1.5; - vec3 light=prp+vec3(5.0,0,5.0); - - vec3 scp=camera(prp,vrp,vuv,vpd); - vec3 n,p; - float f,o; - const float maxe=0.01; - const float startf=0.1; - const vec3 backc=vec3(0.0,0.0,0.0); - const float spec=8.0; - const vec3 ambi=vec3(0.1,0.1,0.1); - - vec3 c1=render(prp,scp,256,maxe,startf,60.0,backc,light,spec,ambi,n,p,f,o); - c1=c1*max(1.0-f*.015,0.0); - vec3 c2=backc; - if (o>0.5){ - scp=reflect(scp,n); - c2=render(p+scp*0.05,scp,32,maxe,startf,10.0,backc,light,spec,ambi,n,p,f,o); - } - c2=c2*max(1.0-f*.1,0.0); - gl_FragColor=vec4(c1.xyz*0.75+c2.xyz*0.25,1.0); - - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_6147_1.hx b/examples/HerokuShaders/src/shaders/FragmentShader_6147_1.hx deleted file mode 100644 index db7783374..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_6147_1.hx +++ /dev/null @@ -1,72 +0,0 @@ -package shaders; - - -class FragmentShader_6147_1 { - - - //http://glsl.heroku.com/e#6147.1 - - - public static var source = " - - #define PI 3.14159265 - uniform float time; - uniform vec2 mouse, resolution; - - vec3 sim(vec3 p,float s); //.h - vec2 rot(vec2 p,float r); - vec2 rotsim(vec2 p,float s); - - vec2 makeSymmetry(vec2 p){ //nice stuff :) - vec2 ret=p; - ret=rotsim(p, 6.0); - ret.x=abs(ret.x); - return ret; - } - - float makePoint(float x,float y,float fx,float fy,float sx,float sy,float t){ - - float xx=x+tan(t * fx)*sy; - float yy=y-tan(t * fx)*sy; - return 0.8/sqrt(abs(x*xx+yy*yy)); - } - - vec2 sim(vec2 p,float s){ - vec2 ret=p; - ret=p+s/2.0; - ret=fract(ret/s)*s-s/2.0; - return ret; - } - - vec2 rot(vec2 p,float r){ - vec2 ret; - ret.x=p.x*cos(r)-p.y*sin(r); - ret.y=p.x*sin(r)+p.y*cos(r); - return ret; - } - - vec2 rotsim(vec2 p,float s){ - float k = atan(p.x, p.y); - vec2 ret=rot(p,floor((k + PI/(s*2.0)) / PI*s)*(PI/s)); - return ret; - } - - void main( void ) { - vec2 p=(gl_FragCoord.xy/resolution.x)*2.0-vec2(1.0,resolution.y/resolution.x); - p=makeSymmetry(p); - float x=p.x; - float y=p.y; - float t=time*0.2; - float a= makePoint(x,y,3.3,2.9,0.3,0.3,t); - // a=a+makePoint(x,y,1.8,1.7,0.5,0.4,t); - float b=makePoint(x,y,1.2,1.9,0.3,0.3,t); - // b=b+makePoint(x,y,0.7,2.7,0.4,0.4,t); - float c=makePoint(x,y,3.7,0.3,0.3,0.3,t); - // c=c+makePoint(x,y,0.8,0.9,0.4,0.5,t); - gl_FragColor = vec4(a/5.,b/5.,c/5.,1.0); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_6162.hx b/examples/HerokuShaders/src/shaders/FragmentShader_6162.hx deleted file mode 100644 index 176580610..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_6162.hx +++ /dev/null @@ -1,105 +0,0 @@ -package shaders; - - -class FragmentShader_6162 { - - - //http://glsl.heroku.com/e#6162.0 - - - public static var source = " - - #define PI 3.141592653589793 - - #define ZOOM (4. - sin(time/2.)*3.) - - #define MAX_ITERATION 6 - #define ITERATION_BAIL sqrt(PI/2.) - - #define MAX_MARCH 50 - #define MAX_DISTANCE 2.3 - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - - float DE(vec3 p) - { - vec3 w = p; - float dr = 1.; - float r = 0.; - for (int i=0; iITERATION_BAIL) break; - - dr*=pow(r, 7.)*8.+1.; - - float x = w.x; float x2 = x*x; float x4 = x2*x2; - float y = w.y; float y2 = y*y; float y4 = y2*y2; - float z = w.z; float z2 = z*z; float z4 = z2*z2; - - float k3 = x2 + z2; - float k2 = inversesqrt( pow(k3, 7.) ); - float k1 = x4 + y4 + z4 - 6.0*y2*z2 - 6.0*x2*y2 + 2.0*z2*x2; - float k4 = x2 - y2 + z2; - - w = vec3(64.0*x*y*z*(x2-z2)*k4*(x4-6.0*x2*z2+z4)*k1*k2, - -16.0*y2*k3*k4*k4 + k1*k1, - -8.0*y*k4*(x4*x4 - 28.0*x4*x2*z2 + 70.0*x4*z4 - 28.0*x2*z2*z4 + z4*z4)*k1*k2); - w+=p; - } - return .5*log(r)*r/dr; - } - - bool inCircle(vec3 p, vec3 d) - { - float rdt = dot(p, d); - float rdr = dot(p, p) - 1.253314137315501; // sqrt(PI/2) - return (rdt*rdt)-rdr>0.; - } - - - void main( void ) - { - vec2 pos = (gl_FragCoord.xy*2.0 - resolution.xy) / resolution.y; - - vec2 m = vec2(sin(time), cos(time))/ZOOM; - //m = ((.5-mouse)*PI*2.)/ZOOM; - m.y = clamp(m.y, -PI/2.+.01, PI/2.-.01); - - vec3 camOrigin = vec3(cos(m.x)*cos(m.y), sin(m.y), cos(m.y)*sin(m.x))*2.0; - vec3 camTarget = vec3(0.0, 0.0, 0.0); - vec3 camDir = normalize(camTarget - camOrigin); - vec3 camUp = normalize(vec3(0.0, 1.0, 0.0)); - vec3 camSide = normalize(cross(camDir, camUp)); - vec3 camCDS = cross(camDir, camSide); - - vec3 ray = normalize(camSide*pos.x + camCDS*pos.y + camDir*ZOOM); - - float col = 0., col2 = 0., col3 = 0.; - if (inCircle(camOrigin, ray)) - { - float m = 1.0, dist = 0.0, total_dist = 0.0; - - for(int i=0; iMAX_DISTANCE) break; - } - - col = m; - col2 = m*2.5-total_dist; - col3 = m*1.5-total_dist; - if (total_dist>MAX_DISTANCE) col = 0.; - } - - gl_FragColor = vec4(col, col2/2., col3*2., 1.0); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_6175.hx b/examples/HerokuShaders/src/shaders/FragmentShader_6175.hx deleted file mode 100644 index 83f085d88..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_6175.hx +++ /dev/null @@ -1,238 +0,0 @@ -package shaders; - - -class FragmentShader_6175 { - - - //http://glsl.heroku.com/e#6175.0 - - - public static var source = " - - uniform float time; - uniform vec2 resolution; - uniform vec4 mouse; - uniform sampler2D tex0; - uniform sampler2D tex1; - - const float M_PI = 3.14159265358979323846; - - struct SphereIntersection - { - // IN: - vec4 sphere; - vec3 ro; - vec3 rd; - // OUT: - float t; - vec3 pos; - vec3 normal; - float depth; - }; - - float saturate(float f) - { - return clamp(f,0.0,1.0); - } - - vec3 saturate(vec3 v) - { - return clamp(v,vec3(0,0,0),vec3(1,1,1)); - } - - // ... I went on the internet and I found THIS - float rand(vec2 co) - { - return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); - } - - // Theta, Phi (r == 1) - vec2 normalToSpherical(vec3 normal) - { - vec2 spherical; - // Flip ZY. - normal.yz = normal.zy; - spherical.x = atan(normal.y,normal.x); // Theta - spherical.y = acos(normal.z); // Phi - return spherical; - } - - // Input: Theta, Phi - vec3 sphericalToCartesian(vec2 s) - { - vec3 cart; - cart.x = cos(s.x) * sin(s.y); - cart.y = sin(s.x) * sin(s.y); - cart.z = cos(s.y); - // Flip ZY - cart.yz = cart.zy; - return cart; - } - - // Ray origin, Ray direction, (Sphere center, Sphere radius) - void raySphere(inout SphereIntersection i) - { - vec4 sphere = i.sphere; - vec3 ro = i.ro; - vec3 rd = i.rd; - vec3 sc = sphere.xyz; - float sr = sphere.w; - vec3 sd = ro-sc; - // a == 1 - float b = 2.0*dot(rd,sd); - float c = dot(sd,sd)-(sr*sr); - float disc = b*b - 4.0*c; - if(disc<0.0) - { - i.t = -1.0; - return; - } - float t = (-b-sqrt(disc))/2.0; - i.t = t; - i.pos = ro+rd*t; - i.normal = normalize(i.pos-sphere.xyz); - i.depth = 2.0*sr*dot(normalize(sd),i.normal); - } - - vec3 sphereNormal(vec4 sphere, vec3 point) - { - return normalize(point-sphere.xyz); - } - - float sphereFunction(vec2 coord) - { - coord.x -= time/4.0; - coord.y += sin(time/4.0); - float thetaCoeff = 24.0; - float phiCoeff = 16.0; - float height = 0.8; - height += (sin(3.0*coord.y)*sin(4.0*coord.x))/10.0; - height += (sin(16.0*coord.y)*sin(24.0*coord.x))/10.0; - return height; - } - - vec3 sphereFunctionNormal(vec2 coord, vec4 sphere) - { - // Approximates the local slope of the heightfield function - float d = 0.01; - vec2 s0coord = coord; // Center - vec2 s1coord = coord+vec2(d,0); // +X = +Theta - vec2 s2coord = coord+vec2(0,-d); // +Y = -Phi - // Sample heightfield - float s0 = sphereFunction(s0coord) * sphere.w; - float s1 = sphereFunction(s1coord) * sphere.w; - float s2 = sphereFunction(s2coord) * sphere.w; - // Convert samples to cartesian - vec3 s0c = sphericalToCartesian(s0coord)*s0; - vec3 s1c = sphericalToCartesian(s1coord)*s1; - vec3 s2c = sphericalToCartesian(s2coord)*s2; - // Tangent space - vec3 x = s1c-s0c; - vec3 y = s2c-s0c; - vec3 normal = normalize(cross(y,x)); - return normal; - } - - void rayMarchSphere(inout SphereIntersection i) - { - const float NUM_SAMPLES = 50.0; - vec3 pos = i.pos; - vec3 dir = i.rd; - float stepSize = i.depth/NUM_SAMPLES; - - // No hit - i.t = -1.0; - - for(float s = 0.0; s < NUM_SAMPLES; s++) - { - if(s == 0.0) - { - pos += dir*stepSize*rand(gl_FragCoord.xy); - } - vec3 v = pos-i.sphere.xyz; - float height = length(v); - vec3 n = v/height; - vec2 sCoord = normalToSpherical(n); - float testHeight = sphereFunction(sCoord)*i.sphere.w; - testHeight += 0.000001; // Prevent floating point error - if(height<=testHeight) - { - i.t = length(pos-i.ro); - i.pos = pos; - i.normal = n; - i.normal = sphereFunctionNormal(sCoord,i.sphere); - return; - } - pos += dir*stepSize; - } - return; - } - - vec3 lighting(vec3 point, vec3 N, vec3 light, vec3 color) - { - vec3 toLight = light-point; - vec3 L = normalize(toLight); - return color*saturate(dot(N,L)); - } - - void rayMarchedSphereIntersection(inout SphereIntersection i) - { - // First intersect the sphere - raySphere(i); - // Then raymarch the heightfield - if(i.t > 0.0) - { - rayMarchSphere(i); - } - } - - void main(void) - { - vec2 screenPos = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy; - vec2 screenPosAR = vec2(screenPos.x*(resolution.x/resolution.y),screenPos.y); - - vec3 rayDir = normalize(vec3(screenPosAR.x,screenPosAR.y,1.0)); - vec3 light = vec3(sin(time/4.0)*3.0,cos(time/5.0)*3.0,-2.0); - vec4 sphere = vec4(0.0,0.0,3.0,2.2); - - SphereIntersection inter; - inter.ro = vec3(0,0,0); - inter.rd = rayDir; - inter.sphere = sphere; - rayMarchedSphereIntersection(inter); - //raySphere(inter); - - vec3 color; - if(inter.t > 0.0) - { - float shadowFactor = 1.0; - SphereIntersection shadowInter; - vec3 lightDir = normalize(light-inter.pos); - shadowInter.ro = inter.pos; - shadowInter.rd = lightDir; - shadowInter.pos = inter.pos+lightDir*0.1; - shadowInter.sphere = sphere; - shadowInter.depth = sphere.w; - rayMarchSphere(shadowInter); - if(shadowInter.t > 0.0) - { - //shadowFactor = 0.0; - } - // Some crazy colors - vec3 diffuse = normalize(normalize(inter.pos-sphere.xyz)+vec3(abs(sin(time/4.0)),abs(cos(time/5.0)),abs(sin(time/5.0)*2.0))); - color.xyz = lighting(inter.pos, inter.normal, light, diffuse) * shadowFactor; - color.xyz += saturate(inter.normal.zzz+0.50)*diffuse; // Some fake backlighting - } - else - { - color.xyz = vec3(0,0,0); - } - - gl_FragColor.xyz = color; - gl_FragColor.w = 1.0; - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_6223_2.hx b/examples/HerokuShaders/src/shaders/FragmentShader_6223_2.hx deleted file mode 100644 index 9319db739..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_6223_2.hx +++ /dev/null @@ -1,50 +0,0 @@ -package shaders; - - -class FragmentShader_6223_2 { - - - //http://glsl.heroku.com/e#6223.2 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - - // a raymarching experiment by kabuto - //fork by tigrou ind (2013.01.22) - //optimized - - #define MAXITER 90 - #define MAXITER_SQR MAXITER*MAXITER - - vec3 field(vec3 p) { - p = abs(fract(p)-.5); - p *= p; - return sqrt(p+p.yzx*p.zzy)-.015; - } - - void main( void ) { - vec3 dir = normalize(vec3((gl_FragCoord.xy-resolution*.5)/resolution.x,1.)); - float a = time * 0.4; - vec3 pos = vec3(time*0.6 + sin(time)*0.2,sin(time)*0.25,-3.0); - - vec3 color = vec3(0); - for (int i = 0; i < MAXITER; i++) { - vec3 f2 = field(pos); - vec3 rep = vec3(1.0,0.7+sin(time)*0.7, 1.3); - float f = min(min(min(f2.x,f2.y),f2.z), length(mod(pos-vec3(0.1),rep)-0.5*rep)-0.10); - pos += dir*f; - color += float(MAXITER-i)/(f2+.01); - } - vec3 color3 = vec3(1.-1./(1.+color*(.09/float(MAXITER_SQR)))); - color3 *= color3; - gl_FragColor = vec4(vec3(color3.r+color3.g+color3.b),1.); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_6238.hx b/examples/HerokuShaders/src/shaders/FragmentShader_6238.hx deleted file mode 100644 index b10cf18bb..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_6238.hx +++ /dev/null @@ -1,41 +0,0 @@ -package shaders; - - -class FragmentShader_6238 { - - - //http://glsl.heroku.com/e#6238.0 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - - void main( void ) { - - vec3 color1 = vec3(1.7, 0.25, 0.5); - vec3 color2 = vec3(0.5, 0.7, 0.25); - vec3 color3 = vec3(0.25, 0.5, 0.7); - - vec2 point1 = resolution/2.0 + vec2(sin(time*2.0) * 10.0, cos(time*2.0) * 5.0); - vec2 point2 = resolution/2.0 + vec2(sin(time)*75.0, cos(time)*50.0); - vec2 point3 = resolution/2.0 + vec2(sin(time)*25.0, sin(time*2.0)*50.0)*2.0; - - vec2 dist1 = gl_FragCoord.xy - point1; - float intensity1 = pow(32.0/(0.01+length(dist1)), 2.0); - - vec2 dist2 = gl_FragCoord.xy - point2; - float intensity2 = pow(3.0/(0.01+length(dist2)), 2.0); - - vec2 dist3 = gl_FragCoord.xy - point3; - float intensity3 = pow(62.0/(0.01+length(dist3)), 1.0); - - gl_FragColor = vec4((color1*intensity1 + color2*intensity2 + color3*intensity3)*mod(gl_FragCoord.y, 2.0),1.0); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_6284_1.hx b/examples/HerokuShaders/src/shaders/FragmentShader_6284_1.hx deleted file mode 100644 index 3d3c5bf48..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_6284_1.hx +++ /dev/null @@ -1,33 +0,0 @@ -package shaders; - - -class FragmentShader_6284_1 { - - - //http://glsl.heroku.com/e#6284.1 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - - void main( void ) { - - vec2 position = ( gl_FragCoord.xy / resolution.xy ) + mouse / 1.0; - - float color = 0.0; - color += sin( position.x * cos( time / 15.0 ) * 80.0 ) + cos( position.y * cos( time / 15.0 ) * 10.0 ); - color += sin( position.y * sin( time / 10.0 ) * 40.0 ) + cos( position.x * sin( time / 25.0 ) * 40.0 ); - color += sin( position.x * sin( time / 5.0 ) * 10.0 ) + sin( position.y * sin( time / 35.0 ) * 80.0 ); - color *= sin( time / 10.0 ) * 0.5; - - gl_FragColor = vec4( vec3( color, color * 0.1, sin( color + time / 9.0 ) * 0.75 ), 1.0 ); - - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_6286.hx b/examples/HerokuShaders/src/shaders/FragmentShader_6286.hx deleted file mode 100644 index 3c2ea52bf..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_6286.hx +++ /dev/null @@ -1,36 +0,0 @@ -package shaders; - - -class FragmentShader_6286 { - - - //http://glsl.heroku.com/e#6286.0 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - varying vec2 surfacePosition; - - void main( void ) { - vec2 p = surfacePosition; - float speed = 0.45; - vec3 color = vec3(.4,.1,.8); - vec2 loc = vec2(cos(time/1.6*speed)/1.9-cos(time/.8*speed)/3.8, - sin(time/1.6*speed)/1.9-sin(time/.8*speed)/3.8 - ); - float depth; - for(int i = 0; i < 100; i+=1){ - p = vec2(p.x*p.x-p.y*p.y,2.0*p.x*p.y)+loc; - depth = float(i); - if((p.x*p.x+p.y*p.y) >= 4.0) break; - } - gl_FragColor = vec4(clamp(color*depth*0.05, 0.0, 10.0)*mod(gl_FragCoord.y, 2.0), 1.0 ); - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/FragmentShader_6288_1.hx b/examples/HerokuShaders/src/shaders/FragmentShader_6288_1.hx deleted file mode 100644 index 747f2323d..000000000 --- a/examples/HerokuShaders/src/shaders/FragmentShader_6288_1.hx +++ /dev/null @@ -1,45 +0,0 @@ -package shaders; - - -class FragmentShader_6288_1 { - - - //http://glsl.heroku.com/e#6288.1 - - - public static var source = " - - uniform float time; - uniform vec2 mouse; - uniform vec2 resolution; - - - void main( void ) - { - - vec2 uPos = ( gl_FragCoord.xy / resolution.xy );//normalize wrt y axis - //suPos -= vec2((resolution.x/resolution.y)/2.0, 0.0);//shift origin to center - - uPos.x -= 1.0; - uPos.y -= 0.5; - - vec3 color = vec3(0.0); - float vertColor = 0.0; - for( float i = 0.0; i < 15.0; ++i ) - { - float t = time * (0.9); - - uPos.y += sin( uPos.x*i + t+i/2.0 ) * 0.1; - float fTemp = abs(1.0 / uPos.y / 100.0); - vertColor += fTemp; - color += vec3( fTemp*(10.0-i)/10.0, fTemp*i/10.0, pow(fTemp,1.5)*1.5 ); - } - - vec4 color_final = vec4(color, 1.0); - gl_FragColor = color_final; - } - - "; - - -} \ No newline at end of file diff --git a/examples/HerokuShaders/src/shaders/VertexShader.hx b/examples/HerokuShaders/src/shaders/VertexShader.hx deleted file mode 100644 index cc358e56d..000000000 --- a/examples/HerokuShaders/src/shaders/VertexShader.hx +++ /dev/null @@ -1,23 +0,0 @@ -package shaders; - - -class VertexShader { - - - public static var source = " - - attribute vec3 position; - attribute vec2 surfacePosAttrib; - varying vec2 surfacePosition; - - void main() { - - surfacePosition = surfacePosAttrib; - gl_Position = vec4( position, 1.0 ); - - } - - "; - - -} \ No newline at end of file diff --git a/examples/SimpleOpenGL/Assets/.keep b/examples/SimpleOpenGL/Assets/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/SimpleOpenGL/src/Main.hx b/examples/SimpleOpenGL/src/Main.hx deleted file mode 100644 index 6fcb0035d..000000000 --- a/examples/SimpleOpenGL/src/Main.hx +++ /dev/null @@ -1,208 +0,0 @@ - - //Ported and modified from OpenFL samples - //underscorediscovery - -import lime.utils.Assets; -import lime.LiME; - - //Import GL stuff from lime -import lime.gl.GL; -import lime.gl.GLBuffer; -import lime.gl.GLProgram; - - //utils -import lime.utils.Float32Array; -import lime.geometry.Matrix3D; - - -class Main { - - public var lib : LiME; - - //Shader stuff for drawing - private var shaderProgram:GLProgram; - private var vertexAttribute:Int; - - //The vertices are stored in here for GL - private var vertexBuffer:GLBuffer; - - //Some value to mess with the clear color - private var red_value : Float = 1.0; - private var red_direction : Int = 1; - - var end_dt : Float = 0.016; - var dt : Float = 0.016; - - public function new() { } - - public function ready( _lime : LiME ) { - - //Store a reference - lib = _lime; - - // Init the shaders and view - init(); - - } //ready - - - public function init() { - - //Set up shaders - createProgram(); - - //Create a set of vertices - var vertices : Float32Array = new Float32Array([ - 100.0, 100.0, 0.0, - -100.0, 100.0, 0.0, - 100.0, -100.0, 0.0, - -100.0, -100.0, 0.0 - ]); - - //Create a buffer from OpenGL - vertexBuffer = GL.createBuffer(); - //Bind it - GL.bindBuffer( GL.ARRAY_BUFFER, vertexBuffer ); - //Point it to the vertex array! - GL.bufferData( GL.ARRAY_BUFFER, vertices, GL.STATIC_DRAW ); - - } //init - - //Called each frame by lime for logic (called before render) - public function update() { - - dt = haxe.Timer.stamp() - end_dt; - end_dt = haxe.Timer.stamp(); - - //an awful magic number to change the value slowly - red_value += (red_direction * 0.3) * dt; - - if(red_value >= 1) { - red_value = 1; - red_direction = -red_direction; - } else if(red_value <= 0) { - red_value = 0; - red_direction = -red_direction; - } - - } //update - - //Called by lime - public function onmousemove(_event:Dynamic) { - } - //Called by lime - public function onmousedown(_event:Dynamic) { - } - //Called by lime - public function onmouseup(_event:Dynamic) { - } - //Called by lime - public function onkeydown(_event:Dynamic) { - } - //Called by lime - public function onkeyup(_event:Dynamic) { - } - - - //Called by lime - public function render() { - - //Set the viewport for GL - GL.viewport( 0, 0, lib.config.width, lib.config.height ); - - //Set the clear color to a weird color that bounces around - GL.clearColor( red_value, red_value*0.5, red_value*0.3, 1); - //Clear the buffers - GL.clear( GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT ); - - //Work out the middle of the viewport - var positionX = (lib.config.width / 2) * (red_value*2); - var positionY = (lib.config.height / 2) * (red_value*2); - - //Create the projection and modelview matrices - var projectionMatrix = Matrix3D.createOrtho (0, lib.config.width, lib.config.height, 0, 1000, -1000); - var modelViewMatrix = Matrix3D.create2D (positionX, positionY, 1, 0); - - //Bind the shader pointers to the vertex GL Buffer we made in init - GL.bindBuffer (GL.ARRAY_BUFFER, vertexBuffer); - GL.vertexAttribPointer (vertexAttribute, 3, GL.FLOAT, false, 0, 0); - - //Set the projection values in the shader so they can render accordingly - var projectionMatrixUniform = GL.getUniformLocation (shaderProgram, "projectionMatrix"); - var modelViewMatrixUniform = GL.getUniformLocation (shaderProgram, "modelViewMatrix"); - - //Update the GL Matrices - GL.uniformMatrix3D (projectionMatrixUniform, false, projectionMatrix); - GL.uniformMatrix3D (modelViewMatrixUniform, false, modelViewMatrix); - - //And finally, Draw the vertices with the applied shaders and view - GL.drawArrays (GL.TRIANGLE_STRIP, 0, 4); - - } //render - - - //Shader initialize - private function createProgram() : Void { - - var vertexShaderSource = - - "attribute vec3 vertexPosition; - - uniform mat4 modelViewMatrix; - uniform mat4 projectionMatrix; - - void main(void) { - gl_Position = projectionMatrix * modelViewMatrix * vec4(vertexPosition, 1.0); - }"; - - var fragmentShaderSource = - "void main(void) { - gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); - }"; - - //Create the GPU shaders - var vertexShader = GL.createShader( GL.VERTEX_SHADER ); - var fragmentShader = GL.createShader( GL.FRAGMENT_SHADER ); - - //Set the shader source and compile it - GL.shaderSource( vertexShader, vertexShaderSource ); - GL.shaderSource( fragmentShader, fragmentShaderSource ); - - //Try compiling the vertex shader - GL.compileShader( vertexShader ); - if (GL.getShaderParameter (vertexShader, GL.COMPILE_STATUS) == 0) { - throw "Error compiling vertex shader"; - } //COMPILE_STATUS - - //Now try compile the fragment shader - GL.compileShader( fragmentShader ); - if (GL.getShaderParameter(fragmentShader, GL.COMPILE_STATUS) == 0) { - throw "Error compiling fragment shader"; - } //COMPILE_STATUS - - //Create the GPU program - shaderProgram = GL.createProgram(); - - //Attach the shader code to the program - GL.attachShader( shaderProgram, vertexShader ); - GL.attachShader( shaderProgram, fragmentShader ); - - //And link the program - GL.linkProgram( shaderProgram ); - if (GL.getProgramParameter (shaderProgram, GL.LINK_STATUS) == 0) { - throw "Unable to initialize the shader program."; - } //LINK_STATUS - - //Set the shader active - GL.useProgram( shaderProgram ); - //Fetch the vertex attribute - vertexAttribute = GL.getAttribLocation (shaderProgram, "vertexPosition"); - //And enable it (disable by default) - GL.enableVertexAttribArray (vertexAttribute); - - } //createProgram - - -} //Main - - diff --git a/haxelib.json b/haxelib.json index eb5206faa..6baa4df50 100644 --- a/haxelib.json +++ b/haxelib.json @@ -1,11 +1,11 @@ { "name": "lime", - "url": "http://www.limeframework.com", + "url": "http://github.com/openfl/lime", "license": "MIT", "tags": [], "description": "A powerful native backend for Haxe projects", - "version": "1.0.0", - "releasenote": "Initial release", + "version": "0.9.1", + "releasenote": "Minor update", "contributors": [ "singmajesty", "underscorediscovery" ], "dependencies": {} } diff --git a/include.xml b/include.xml index cfe4a4ef5..a8e014317 100644 --- a/include.xml +++ b/include.xml @@ -30,5 +30,6 @@ + diff --git a/lime.png b/lime.png index 4c5d9c59c..5afb8060b 100644 Binary files a/lime.png and b/lime.png differ diff --git a/lime/AudioHandler.hx b/lime/AudioHandler.hx index 90d833963..b89e2b956 100644 --- a/lime/AudioHandler.hx +++ b/lime/AudioHandler.hx @@ -3,7 +3,274 @@ package lime; import lime.utils.Libs; +#if (!audio_thread_disabled && lime_native) + #if neko + import neko.vm.Thread; + import neko.vm.Mutex; + #else + import cpp.vm.Thread; + import cpp.vm.Mutex; + #end +#end //audio_thread_disabled + + +class AudioHandler { + + public var lib : Lime; + public function new( _lib:Lime ) { lib = _lib; } + +#if (!audio_thread_disabled && lime_native) + + @:noCompletion public static var audio_state:AudioThreadState; + + @:noCompletion public static var audio_message_check_complete = 1; + @:noCompletion public static var audio_thread_is_idle:Bool = true; + @:noCompletion public static var audio_thread_running:Bool = false; + +#end + + public var sounds : Map; + public function startup() { + + sounds = new Map(); + + #if (!audio_thread_disabled && lime_native) + audio_state = new AudioThreadState (); + audio_thread_running = true; + audio_thread_is_idle = false; + audio_state.main_thread = Thread.current (); + audio_state.audio_thread = Thread.create( audio_thread_handler ); + #end //#(!audio_thread_disabled && lime_native) + + } //startup + + @:noCompletion public function update() { + for(sound in sounds) { + if(sound.ismusic) { + sound.check_complete(); + } + } + } + + public function create(_name:String, _file:String, ?_music:Bool = false ) { + + if(sounds.exists(_name)) { + throw ">>> Named sounds are not allowed to have duplicate names"; + } + + #if lime_native + + var _handle = lime_sound_from_file( lime.AssetData.path.get(_file), _music ); + var _sound = new Sound(_name, _handle, _music); + + sounds.set(_name, _sound); + + #end //lime_native + } + + public function get( _name:String ) : Sound { + return sounds.get(_name); + } + +#if (!audio_thread_disabled && lime_native) + + public function audio_thread_handler() { + + while (audio_thread_running) { + + var thread_message:Dynamic = Thread.readMessage (false); + + if (thread_message == audio_message_check_complete) { + audio_state.check(); + } + + if (!audio_thread_is_idle) { + audio_state.update(); + Sys.sleep (0.01); + } else { + Sys.sleep (0.2); + } + + } + + audio_thread_running = false; + audio_thread_is_idle = true; + + } + +#end //(!audio_thread_disabled && lime_native) + + +#if lime_native + private static var lime_sound_from_file = Libs.load("lime","lime_sound_from_file", 2); + private static var lime_sound_from_data = Libs.load("lime","lime_sound_from_data", 3); +#end //lime_native + +} //AudioHandler + + +class Sound { + + public var name : String; + public var handle : Dynamic; + public var channel : Dynamic; + public var ismusic : Bool = false; + + var on_complete_handler : Sound->Void; + + @:isVar public var volume(default, set) : Float = 1.0; + @:isVar public var pan(default, set) : Float = 0.0; + @:isVar public var position(get, set) : Float = 0.0; + +#if (!audio_thread_disabled && lime_native) + @:noCompletion private var added_to_thread:Bool; +#end + + private var _transform:SoundTransform; + + public function new(_name:String, _handle:Dynamic, ?_music:Bool = false, ?_sound:Dynamic = null) { + + name = _name; + handle = _handle; + channel = _sound; + ismusic = _music; + + //reuse. + _transform = new SoundTransform(volume,pan); + } + + public function play(?_loops:Int = 0, ?_start:Float = 0.0) { + + channel = null; + + #if lime_native + channel = lime_sound_channel_create(handle, _start, _loops, _transform); + #end //lime_native + } + + public function stop() { + + if(channel != null) { + + #if (!audio_thread_disabled && lime_native) + if( ismusic ) { + AudioHandler.audio_state.remove(this); + } + #end + + #if lime_native + lime_sound_channel_stop(channel); + #end //lime_native + + channel = null; + } + } + + @:noCompletion public function do_on_complete() { + if(on_complete_handler != null) { + on_complete_handler(this); + } + } + + public function on_complete(_function:Sound->Void) { + on_complete_handler = _function; + } + + + @:noCompletion public function do_check_complete ():Bool { + + #if lime_native + if( lime_sound_channel_is_complete(channel) ) { + handle = null; + channel = null; + return true; + } + #end + + return false; + + } //do_check_complete + + @:noCompletion public function check_complete() { + + #if (!audio_thread_disabled && lime_native) + + if (added_to_thread || (channel != null && ismusic)) { + + if (!added_to_thread) { + trace('adding to a thread ' + name); + AudioHandler.audio_state.add( this ); + added_to_thread = true; + } + + AudioHandler.audio_state.audio_thread.sendMessage( AudioHandler.audio_message_check_complete ); + + return false; + } + + #else + + if( do_check_complete() ) { + do_on_complete(); + return true; + } + + #end + + return false; + } + + function set_volume(_v:Float) : Float { + _transform.volume = _v; + + #if lime_native + lime_sound_channel_set_transform(channel,_transform); + #end //lime_native + + return volume = _v; + } + function set_pan(_p:Float) : Float { + _transform.pan = _p; + + #if lime_native + lime_sound_channel_set_transform(channel,_transform); + #end //lime_native + + return pan = _p; + } + + function set_position(_p:Float) : Float { + + #if lime_native + lime_sound_channel_set_position(channel, _p); + #end //lime_native + + return position = _p; + } + + function get_position() : Float { + + #if lime_native + position = lime_sound_channel_get_position(channel); + #end //lime_native + + return position; + } + +#if lime_native + private static var lime_sound_channel_is_complete = Libs.load ("lime", "lime_sound_channel_is_complete", 1); + private static var lime_sound_channel_create = Libs.load("lime","lime_sound_channel_create", 4); + private static var lime_sound_channel_stop = Libs.load("lime","lime_sound_channel_stop", 1); + private static var lime_sound_channel_set_transform = Libs.load("lime","lime_sound_channel_set_transform", 2); + private static var lime_sound_channel_get_position = Libs.load ("lime", "lime_sound_channel_get_position", 1); + private static var lime_sound_channel_set_position = Libs.load ("lime", "lime_sound_channel_set_position", 2); +#end //lime_native + +} + + class SoundTransform { + public var pan:Float; public var volume:Float; @@ -15,98 +282,83 @@ class SoundTransform { public function clone() { return new SoundTransform(volume, pan); } -} -class Sound { - public var handle : Dynamic; - public var sound : Dynamic; +} //SoundTransform - @:isVar public var volume(default, set) : Float = 1.0; - @:isVar public var pan(default, set) : Float = 0.0; - private var _transform:SoundTransform; - public function new(_handle:Dynamic, ?_sound:Dynamic = null){ - handle = _handle; - sound = _sound; - //reuse. - _transform = new SoundTransform(volume,pan); - } +#if (!audio_thread_disabled && lime_native) - public function play(?_loops:Int = 0, ?_start:Float = 0.0) { - sound = null; - - #if lime_native - sound = lime_sound_channel_create(handle, _start, _loops, _transform); - #end //lime_native - } +class AudioThreadState { + + public var audio_thread:Thread; + public var sound_list:Map ; + public var main_thread:Thread; + public var mutex:Mutex; + + public function new () { + mutex = new Mutex (); + sound_list = new Map (); + } + + public function add (sound:Sound):Void { + + mutex.acquire (); + + if (!sound_list.exists(sound)) { + sound_list.set (sound, false); + AudioHandler.audio_thread_is_idle = false; + } + + mutex.release (); + + } + + public function check() { + + for (sound in sound_list.keys()) { - public function stop() { - if(sound != null) { + var is_complete = sound_list.get(sound); + if (is_complete) { + sound.do_on_complete(); + + mutex.acquire (); + sound_list.remove( sound ); + mutex.release (); + + } //isComplete + } + + } + + public function remove( sound:Sound ):Void { + + mutex.acquire (); + + if( sound_list.exists(sound) ) { + sound_list.remove(sound); + if (Lambda.count (sound_list) == 0) { + AudioHandler.audio_thread_is_idle = true; + } + } + + mutex.release (); + + } + + public function update() { + + mutex.acquire (); + + for (sound in sound_list.keys()) { + var is_complete = sound.do_check_complete(); + sound_list.set( sound, is_complete ); + } + + mutex.release (); + + } + +} //AudioThreadState - #if lime_native - lime_sound_channel_stop(sound); - #end //lime_native - - sound = null; - } - } - - public function set_volume(_v:Float) : Float { - _transform.volume = _v; - - #if lime_native - lime_sound_channel_set_transform(sound,_transform); - #end //lime_native - - return volume = _v; - } - public function set_pan(_p:Float) : Float { - _transform.pan = _p; - - #if lime_native - lime_sound_channel_set_transform(sound,_transform); - #end //lime_native - - return pan = _p; - } - -#if lime_native - private static var lime_sound_channel_create = Libs.load("lime","lime_sound_channel_create", 4); - private static var lime_sound_channel_stop = Libs.load("lime","lime_sound_channel_stop", 1); - private static var lime_sound_channel_set_transform = Libs.load("lime","lime_sound_channel_set_transform", 2); -#end //lime_native - -} - -class AudioHandler { - - public var lib : LiME; - public function new( _lib:LiME ) { lib = _lib; } - - public var sounds : Map; - public function startup() { - //test audio junks - - sounds = new Map(); - } - - public function create_sound(_name:String, _file:String, ?_music:Bool = false ) { - - if(sounds.exists(_name)) { - throw ">>> Named sounds are not allowed to have duplicate names"; - } - - #if lime_native - var _handle = lime_sound_from_file( lime.AssetData.path.get(_file), _music); - var _sound = new Sound(_handle); - sounds.set(_name, _sound); - #end //lime_native - } - -#if lime_native - private static var lime_sound_from_file = Libs.load("lime","lime_sound_from_file", 2); - private static var lime_sound_from_data = Libs.load("lime","lime_sound_from_data", 3); -#end //lime_native - -} \ No newline at end of file +#end // (!audio_thread_disabled && lime_native) \ No newline at end of file diff --git a/lime/InputHandler.hx b/lime/InputHandler.hx index e524eb8e8..2190bbae9 100644 --- a/lime/InputHandler.hx +++ b/lime/InputHandler.hx @@ -1,13 +1,13 @@ package lime; -import lime.LiME; +import lime.Lime; import lime.RenderHandler; class InputHandler { - public var lib : LiME; - public function new( _lib:LiME ) { lib = _lib; } + public var lib : Lime; + public function new( _lib:Lime ) { lib = _lib; } public var touch_map : Map; public var down_keys : Map; @@ -46,7 +46,7 @@ class InputHandler { char : _event.char, value : _event.value, flags : _event.flags, - key : lime.helpers.Keys.toKeyValue(_event.value) + key : lime.helpers.Keys.toKeyValue(_event) }); } @@ -67,7 +67,7 @@ class InputHandler { char : _event.char, value : _event.value, flags : _event.flags, - key : lime.helpers.Keys.toKeyValue(_event.value), + key : lime.helpers.Keys.toKeyValue(_event), ctrl_down : (_event.flags & efCtrlDown > 0), alt_down : (_event.flags & efAltDown > 0), shift_down : (_event.flags & efShiftDown > 0), @@ -86,7 +86,7 @@ class InputHandler { char : _event.char, value : _event.value, flags : _event.flags, - key : lime.helpers.Keys.toKeyValue(_event.value), + key : lime.helpers.Keys.toKeyValue(_event), ctrl_down : (_event.flags & efCtrlDown > 0), alt_down : (_event.flags & efAltDown > 0), shift_down : (_event.flags & efShiftDown > 0), @@ -104,7 +104,7 @@ class InputHandler { char : _event.char, value : _event.value, flags : _event.flags, - key : lime.helpers.Keys.toKeyValue(_event.value), + key : lime.helpers.Keys.toKeyValue(_event), ctrl_down : (_event.flags & efCtrlDown > 0), alt_down : (_event.flags & efAltDown > 0), shift_down : (_event.flags & efShiftDown > 0), @@ -123,7 +123,7 @@ class InputHandler { char : _event.char, value : _event.value, flags : _event.flags, - key : lime.helpers.Keys.toKeyValue(_event.value), + key : lime.helpers.Keys.toKeyValue(_event), ctrl_down : (_event.flags & efCtrlDown > 0), alt_down : (_event.flags & efAltDown > 0), shift_down : (_event.flags & efShiftDown > 0), @@ -525,7 +525,7 @@ class InputHandler { js.Browser.document.addEventListener('keydown', function(e){ if (e.keyCode >= 65 && e.keyCode <= 122) { - e.value = e.which+32; + e.value = e.which; } else { e.value = e.which; } @@ -534,7 +534,7 @@ class InputHandler { }); js.Browser.document.addEventListener('keyup', function(e){ if (e.keyCode >= 65 && e.keyCode <= 122) { - e.value = e.which+32; + e.value = e.which; } else { e.value = e.which; } diff --git a/lime/LiME.hx b/lime/Lime.hx similarity index 98% rename from lime/LiME.hx rename to lime/Lime.hx index 72a96ccf1..79740cf59 100644 --- a/lime/LiME.hx +++ b/lime/Lime.hx @@ -10,7 +10,7 @@ import lime.WindowHandler; import haxe.Timer; -class LiME { +class Lime { //The host class of the application public var host : Dynamic; @@ -64,7 +64,7 @@ class LiME { config = _config; host = _main_; - _debug(':: lime :: initializing -'); + _debug(':: lime :: initializing - '); _debug(':: lime :: Creating window at ' + config.width + 'x' + config.height); //default to 60 fps @@ -307,9 +307,12 @@ class LiME { _debug('on_update ' + Timer.stamp(), true, false); #if lime_native - Timer.__checkTimers(); + Timer.__checkTimers(); #end + //process any audio + audio.update(); + if(!has_shutdown) { #if lime_native diff --git a/lime/RenderHandler.hx b/lime/RenderHandler.hx index 387c493a6..ed75d7269 100644 --- a/lime/RenderHandler.hx +++ b/lime/RenderHandler.hx @@ -1,6 +1,6 @@ package lime; -import lime.LiME; +import lime.Lime; import lime.utils.Libs; //Import GL @@ -35,8 +35,8 @@ enum BrowserLike { class RenderHandler { - public var lib : LiME; - public function new( _lib:LiME ) { lib = _lib; } + public var lib : Lime; + public function new( _lib:Lime ) { lib = _lib; } public var __handle : Dynamic; diff --git a/lime/WindowHandler.hx b/lime/WindowHandler.hx index 5b8ce4353..982ec1e5e 100644 --- a/lime/WindowHandler.hx +++ b/lime/WindowHandler.hx @@ -1,14 +1,14 @@ package lime; -import lime.LiME; +import lime.Lime; import lime.utils.Libs; import lime.Constants; class WindowHandler { - public var lib : LiME; - public function new( _lib:LiME ) { lib = _lib; } + public var lib : Lime; + public function new( _lib:Lime ) { lib = _lib; } //if the core is active public var active : Bool = false; @@ -38,14 +38,14 @@ class WindowHandler { //optional flags - ( lib.config.fullscreen ? Window.FULLSCREEN : 0) | - ( lib.config.borderless ? Window.BORDERLESS : 0) | - ( lib.config.resizable ? Window.RESIZABLE : 0) | - ( lib.config.AA ? Window.HW_AA : 0) | - ( lib.config.AA_HIRES ? Window.HW_AA_HIRES : 0) | - ( lib.config.depth_buffer ? Window.DEPTH_BUFFER : 0) | - ( lib.config.stencil_buffer ? Window.STENCIL_BUFFER : 0) | - ( lib.config.vsync ? Window.VSYNC : 0), + ( lib.config.fullscreen ? Window.FULLSCREEN : 0) | + ( lib.config.borderless ? Window.BORDERLESS : 0) | + ( lib.config.resizable ? Window.RESIZABLE : 0) | + ( lib.config.antialiasing == 2 ? Window.HW_AA : 0) | + ( lib.config.antialiasing == 4 ? Window.HW_AA_HIRES : 0) | + ( lib.config.depth_buffer ? Window.DEPTH_BUFFER : 0) | + ( lib.config.stencil_buffer ? Window.STENCIL_BUFFER : 0) | + ( lib.config.vsync ? Window.VSYNC : 0), lib.config.title, //title null //icon diff --git a/lime/helpers/Keys.hx b/lime/helpers/Keys.hx index 034eb04ee..0c9bda946 100644 --- a/lime/helpers/Keys.hx +++ b/lime/helpers/Keys.hx @@ -7,8 +7,8 @@ enum KeyValue { enter; meta; shift; - leftctrl; - leftalt; + ctrl; + alt; capslock; escape; space; @@ -59,6 +59,30 @@ enum KeyValue { equals; minus; tilde; + forward_slash; + back_slash; + semicolon; + single_quote; + comma; + period; + open_square_brace; + close_square_brace; + + f1; + f2; + f3; + f4; + f5; + f6; + f7; + f8; + f9; + f10; + f11; + f12; + f13; + f14; + f15; } class Keys { @@ -68,9 +92,9 @@ class Keys { static inline var _enter : Int = 13; static inline var _meta : Int = 15; static inline var _shift : Int = 16; - static inline var _leftctrl : Int = 17; - static inline var _leftalt : Int = 18; - static inline var _capslock : Int = 19; + static inline var _ctrl : Int = 17; + static inline var _alt : Int = 18; + static inline var _capslock : Int = 20; static inline var _escape : Int = 27; static inline var _space : Int = 32; @@ -90,43 +114,67 @@ class Keys { static inline var _key_8 : Int = 56; static inline var _key_9 : Int = 57; - static inline var _key_A : Int = 97; - static inline var _key_B : Int = 98; - static inline var _key_C : Int = 99; - static inline var _key_D : Int = 100; - static inline var _key_E : Int = 101; - static inline var _key_F : Int = 102; - static inline var _key_G : Int = 103; - static inline var _key_H : Int = 104; - static inline var _key_I : Int = 105; - static inline var _key_J : Int = 106; - static inline var _key_K : Int = 107; - static inline var _key_L : Int = 108; - static inline var _key_M : Int = 109; - static inline var _key_N : Int = 110; - static inline var _key_O : Int = 111; - static inline var _key_P : Int = 112; - static inline var _key_Q : Int = 113; - static inline var _key_R : Int = 114; - static inline var _key_S : Int = 115; - static inline var _key_T : Int = 116; - static inline var _key_U : Int = 117; - static inline var _key_V : Int = 118; - static inline var _key_W : Int = 119; - static inline var _key_X : Int = 120; - static inline var _key_Y : Int = 121; - static inline var _key_Z : Int = 122; + static inline var _key_A : Int = 65; + static inline var _key_B : Int = 66; + static inline var _key_C : Int = 67; + static inline var _key_D : Int = 68; + static inline var _key_E : Int = 69; + static inline var _key_F : Int = 70; + static inline var _key_G : Int = 71; + static inline var _key_H : Int = 72; + static inline var _key_I : Int = 73; + static inline var _key_J : Int = 74; + static inline var _key_K : Int = 75; + static inline var _key_L : Int = 76; + static inline var _key_M : Int = 77; + static inline var _key_N : Int = 78; + static inline var _key_O : Int = 79; + static inline var _key_P : Int = 80; + static inline var _key_Q : Int = 81; + static inline var _key_R : Int = 82; + static inline var _key_S : Int = 83; + static inline var _key_T : Int = 84; + static inline var _key_U : Int = 85; + static inline var _key_V : Int = 86; + static inline var _key_W : Int = 87; + static inline var _key_X : Int = 88; + static inline var _key_Y : Int = 89; + static inline var _key_Z : Int = 90; - static inline var _equals : Int = 187; - static inline var _minus : Int = 189; - static inline var _tilde : Int = 192; + static inline var _equals : Int = 187; + static inline var _minus : Int = 189; + static inline var _tilde : Int = 192; + static inline var _forward_slash : Int = 191; + static inline var _back_slash : Int = 220; + static inline var _semicolon : Int = 186; + static inline var _single_quote : Int = 222; + static inline var _comma : Int = 188; + static inline var _period : Int = 190; + static inline var _open_square_brace : Int = 219; + static inline var _close_square_brace : Int = 221; + + static inline var _f1 : Int = 112; + static inline var _f2 : Int = 113; + static inline var _f3 : Int = 114; + static inline var _f4 : Int = 115; + static inline var _f5 : Int = 116; + static inline var _f6 : Int = 117; + static inline var _f7 : Int = 118; + static inline var _f8 : Int = 119; + static inline var _f9 : Int = 120; + static inline var _f10 : Int = 121; + static inline var _f11 : Int = 122; + static inline var _f12 : Int = 123; + static inline var _f13 : Int = 124; + static inline var _f14 : Int = 125; + static inline var _f15 : Int = 126; public var tab : Int = _tab; public var enter : Int = _enter; public var meta : Int = _meta; public var shift : Int = _shift; - public var leftctrl : Int = _leftctrl; - public var leftalt : Int = _leftalt; + public var ctrl : Int = _ctrl; + public var alt : Int = _alt; public var capslock : Int = _capslock; public var escape : Int = _escape; public var space : Int = _space; @@ -174,12 +222,39 @@ class Keys { public var key_Y : Int = _key_Y; public var key_Z : Int = _key_Z; - public var equals : Int = _equals; - public var minus : Int = _minus; - public var tilde : Int = _tilde; + public var equals : Int = _equals; + public var minus : Int = _minus; + public var tilde : Int = _tilde; + public var forward_slash : Int = _forward_slash; + public var back_slash : Int = _back_slash; + public var semicolon : Int = _semicolon; + public var single_quote : Int = _single_quote; + public var comma : Int = _comma; + public var period : Int = _period; + public var open_square_brace : Int = _open_square_brace; + public var close_square_brace : Int = _close_square_brace; + + public var f1 : Int = _f1; + public var f2 : Int = _f2; + public var f3 : Int = _f3; + public var f4 : Int = _f4; + public var f5 : Int = _f5; + public var f6 : Int = _f6; + public var f7 : Int = _f7; + public var f8 : Int = _f8; + public var f9 : Int = _f9; + public var f10 : Int = _f10; + public var f11 : Int = _f11; + public var f12 : Int = _f12; + public var f13 : Int = _f13; + public var f14 : Int = _f14; + public var f15 : Int = _f15; public function new() {} - public static function toKeyValue(_value:Int) : KeyValue { + public static function toKeyValue(_event:Dynamic) : KeyValue { + + var _value = _event.value; + switch(_value) { case _backspace: return KeyValue.backspace; @@ -191,10 +266,10 @@ class Keys { return KeyValue.meta; case _shift: return KeyValue.shift; - case _leftctrl: - return KeyValue.leftctrl; - case _leftalt: - return KeyValue.leftalt; + case _ctrl: + return KeyValue.ctrl; + case _alt: + return KeyValue.alt; case _capslock: return KeyValue.capslock; case _escape: @@ -292,6 +367,54 @@ class Keys { case _tilde: return KeyValue.tilde; + case _forward_slash : + return KeyValue.forward_slash; + case _back_slash : + return KeyValue.back_slash; + case _semicolon : + return KeyValue.semicolon; + case _single_quote : + return KeyValue.single_quote; + case _comma : + return KeyValue.comma; + case _period : + return KeyValue.period; + case _open_square_brace : + return KeyValue.open_square_brace; + case _close_square_brace : + return KeyValue.close_square_brace; + + case _f1 : + return KeyValue.f1; + case _f2 : + return KeyValue.f2; + case _f3 : + return KeyValue.f3; + case _f4 : + return KeyValue.f4; + case _f5 : + return KeyValue.f5; + case _f6 : + return KeyValue.f6; + case _f7 : + return KeyValue.f7; + case _f8 : + return KeyValue.f8; + case _f9 : + return KeyValue.f9; + case _f10 : + return KeyValue.f10; + case _f11 : + return KeyValue.f11; + case _f12 : + return KeyValue.f12; + case _f13 : + return KeyValue.f13; + case _f14 : + return KeyValue.f14; + case _f15 : + return KeyValue.f15; + } //switch return KeyValue.unknown; diff --git a/lime/utils/ArrayBufferView.hx b/lime/utils/ArrayBufferView.hx index 2f8ce4c52..1e19bb835 100644 --- a/lime/utils/ArrayBufferView.hx +++ b/lime/utils/ArrayBufferView.hx @@ -56,9 +56,8 @@ package lime.utils; byteLength = buffer.length - byteOffset; } else { - + byteLength = length; - if (byteLength + byteOffset > buffer.length) { throw ("Invalid buffer length"); diff --git a/lime/utils/Float32Array.hx b/lime/utils/Float32Array.hx index dc8902c9d..2bf64abb3 100644 --- a/lime/utils/Float32Array.hx +++ b/lime/utils/Float32Array.hx @@ -19,14 +19,14 @@ package lime.utils; public function new (bufferOrArray:Dynamic, start:Int = 0, length:Null = null) { BYTES_PER_ELEMENT = 4; - + if (Std.is (bufferOrArray, Int)) { super (Std.int (bufferOrArray) * BYTES_PER_ELEMENT); this.length = bufferOrArray; } else if (Std.is (bufferOrArray, Array)) { - + var floats:Array = bufferOrArray; if (length != null) { @@ -56,8 +56,8 @@ package lime.utils; } } else { - - super (bufferOrArray, start, length); + + super (bufferOrArray, start, length << 2 ); if ((byteLength & 0x03) > 0) { diff --git a/project/Build.xml b/project/Build.xml index 0cefdbaf4..41d4a5f0a 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -537,8 +537,8 @@ - - + + diff --git a/project/src/common/Audio.cpp b/project/src/common/Audio.cpp index 4d64619fa..19faa1178 100644 --- a/project/src/common/Audio.cpp +++ b/project/src/common/Audio.cpp @@ -192,12 +192,17 @@ namespace lime bool loadOggSample(OggVorbis_File &oggFile, QuickVec &outBuffer, int *channels, int *bitsPerSample, int* outSampleRate) { // 0 for Little-Endian, 1 for Big-Endian - int endian = 0; + #ifdef HXCPP_BIG_ENDIAN + #define BUFFER_READ_TYPE 1 + #else + #define BUFFER_READ_TYPE 0 + #endif + int bitStream; long bytes = 1; + int totalBytes = 0; #define BUFFER_SIZE 32768 - char array[BUFFER_SIZE]; //Get the file information //vorbis data @@ -210,23 +215,31 @@ namespace lime } //The number of channels - *channels = pInfo->channels; + *channels = pInfo->channels; //default to 16? todo - *bitsPerSample = 16; + *bitsPerSample = 16; //Return the same rate as well *outSampleRate = pInfo->rate; + // Seem to need four times the read PCM total + outBuffer.resize(ov_pcm_total(&oggFile, -1)*4); + while (bytes > 0) { + if (outBuffer.size() < totalBytes + BUFFER_SIZE) + { + outBuffer.resize(totalBytes + BUFFER_SIZE); + } // Read up to a buffer's worth of decoded sound data - bytes = ov_read(&oggFile, array, BUFFER_SIZE, endian, 2, 1, &bitStream); - // Append to end of buffer - outBuffer.InsertAt(outBuffer.size(), (unsigned char*)array, bytes); + bytes = ov_read(&oggFile, (char*)outBuffer.begin() + totalBytes, BUFFER_SIZE, BUFFER_READ_TYPE, 2, 1, &bitStream); + totalBytes += bytes; } - ov_clear(&oggFile); + outBuffer.resize(totalBytes); + ov_clear(&oggFile); #undef BUFFER_SIZE + #undef BUFFER_READ_TYPE return true; } diff --git a/project/src/common/Utils.cpp b/project/src/common/Utils.cpp index 15f79840c..a5985a432 100644 --- a/project/src/common/Utils.cpp +++ b/project/src/common/Utils.cpp @@ -390,7 +390,7 @@ void GetSpecialDir(SpecialDir inDir,std::string &outDir) } else if (inDir == DIR_STORAGE) { - outDir = "../"; + outDir = "../data"; } else if (inDir == DIR_USER || inDir == DIR_DOCS || inDir == DIR_DESKTOP) { diff --git a/project/src/platform/blackberry/System.cpp b/project/src/platform/blackberry/System.cpp index 757d6bdc0..7713ea3f4 100644 --- a/project/src/platform/blackberry/System.cpp +++ b/project/src/platform/blackberry/System.cpp @@ -113,13 +113,13 @@ namespace lime { std::string FileDialogFolder( const std::string &title, const std::string &text ) { return ""; } - + std::string FileDialogOpen( const std::string &title, const std::string &text, const std::vector &fileTypes ) { return ""; } - + std::string FileDialogSave( const std::string &title, const std::string &text, const std::vector &fileTypes ) { return ""; - } + } } diff --git a/project/src/platform/emscripten/System.cpp b/project/src/platform/emscripten/System.cpp index 4a420bc41..a7f88f5a7 100644 --- a/project/src/platform/emscripten/System.cpp +++ b/project/src/platform/emscripten/System.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace lime { @@ -73,5 +74,18 @@ namespace lime { } + + std::string FileDialogFolder( const std::string &title, const std::string &text ) { + return ""; + } + + std::string FileDialogOpen( const std::string &title, const std::string &text, const std::vector &fileTypes ) { + return ""; + } + + std::string FileDialogSave( const std::string &title, const std::string &text, const std::vector &fileTypes ) { + return ""; + } + } \ No newline at end of file diff --git a/project/src/platform/tizen/TizenApplication.cpp b/project/src/platform/tizen/TizenApplication.cpp index d465d854b..39abd7d53 100644 --- a/project/src/platform/tizen/TizenApplication.cpp +++ b/project/src/platform/tizen/TizenApplication.cpp @@ -373,7 +373,7 @@ namespace lime { //outZ = mAccelZ; outX = 0; outY = 0; - outZ = 1; + outZ = -1; return true; //} diff --git a/project/src/renderer/opengl/OGLExport.cpp b/project/src/renderer/opengl/OGLExport.cpp index 85579acab..a81469d73 100644 --- a/project/src/renderer/opengl/OGLExport.cpp +++ b/project/src/renderer/opengl/OGLExport.cpp @@ -57,7 +57,9 @@ DEFINE_PRIM(lime_gl_version,0); value lime_gl_enable(value inCap) { + //#ifndef LIME_FORCE_GLES2 glEnable(val_int(inCap)); + //#endif return alloc_null(); } DEFINE_PRIM(lime_gl_enable,1); @@ -65,7 +67,9 @@ DEFINE_PRIM(lime_gl_enable,1); value lime_gl_disable(value inCap) { + //#ifndef LIME_FORCE_GLES2 glDisable(val_int(inCap)); + //#endif return alloc_null(); } DEFINE_PRIM(lime_gl_disable,1); diff --git a/project/src/renderer/opengl/OpenGLContext.cpp b/project/src/renderer/opengl/OpenGLContext.cpp index fc49bd9c2..58de233fe 100644 --- a/project/src/renderer/opengl/OpenGLContext.cpp +++ b/project/src/renderer/opengl/OpenGLContext.cpp @@ -92,7 +92,9 @@ namespace lime { mViewport.w = -1; SetViewport (inRect); + //#ifndef LIME_FORCE_GLES2 glEnable (GL_BLEND); + //#endif if (mAlphaMode == amPremultiplied) glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); @@ -238,10 +240,12 @@ namespace lime { void OpenGLContext::FinishBitmapRender () { + #ifndef LIME_FORCE_GLES2 glDisable (GL_TEXTURE_2D); #ifdef LIME_DITHER glEnable (GL_DITHER); #endif + #endif } @@ -325,7 +329,9 @@ namespace lime { void OpenGLContext::Render (const RenderState &inState, const HardwareCalls &inCalls) { + //#ifndef LIME_FORCE_GLES2 glEnable (GL_BLEND); + //#endif SetViewport (inState.mClipRect); if (mModelView != *inState.mTransform.mMatrix) { @@ -455,10 +461,12 @@ namespace lime { if (boundTexture) { boundTexture->BindFlags (draw.mBitmapRepeat, draw.mBitmapSmooth); + #ifndef LIME_FORCE_GLES2 #ifdef LIME_DITHER if (!inSmooth) glDisable (GL_DITHER); #endif + #endif } else { @@ -523,10 +531,12 @@ namespace lime { sgDrawCount++; glDrawArrays (sgOpenglType[draw.mPrimType], draw.mFirst, draw.mCount); + //#ifndef LIME_FORCE_GLES2 #ifdef LIME_DITHER if (boundTexture && !draw.mBitmapSmooth) glEnable (GL_DITHER); #endif + //#endif } diff --git a/run.n b/run.n index 99c454a66..30e184381 100644 Binary files a/run.n and b/run.n differ diff --git a/samples/HerokuShaders/Assets/4278.1.frag b/samples/HerokuShaders/Assets/4278.1.frag new file mode 100644 index 000000000..1dc0275bf --- /dev/null +++ b/samples/HerokuShaders/Assets/4278.1.frag @@ -0,0 +1,85 @@ +//http://glsl.heroku.com/e#4278.1 + + +uniform float time; +uniform vec2 resolution; +uniform vec2 mouse; + +mat3 genRotMat(float a0,float x,float y,float z){ +float a=a0*3.1415926535897932384626433832795/180.0; + return mat3( + 1.0+(1.0-cos(a))*(x*x-1.0), + -z*sin(a)+(1.0-cos(a))*x*y, + y*sin(a)+(1.0-cos(a))*x*z, + z*sin(a)+(1.0-cos(a))*x*y, + 1.0+(1.0-cos(a))*(y*y-1.0), + -x*sin(a)+(1.0-cos(a))*y*z, + -y*sin(a)+(1.0-cos(a))*x*z, + x*sin(a)+(1.0-cos(a))*y*z, + 1.0+(1.0-cos(a))*(z*z-1.0) + ); +} + +float cubeDist(vec3 p){ + return max(abs(p.x),max(abs(p.y),abs(p.z))); +} + +void main(){ + float spread=1.0; + float total=0.0; + float delta=0.01; + float cameraZ=-1.75; + float nearZ=-1.0; + float farZ=1.0; + float gs=0.0; + int iter=0; + vec3 col=vec3(0.0,0.0,0.0); + vec3 ray=vec3(0.0,0.0,0.0); + mat3 rot=genRotMat(sin(time/4.13)*360.0,1.0,0.0,0.0); + rot=rot*genRotMat(sin(time/4.64)*360.0,0.0,1.0,0.0); + rot=rot*genRotMat(sin(time/4.24)*360.0,0.0,0.0,1.0); + vec2 p=vec2(0.0,0.0); + p.x=gl_FragCoord.x/resolution.y-0.5*resolution.x/resolution.y; + p.y=gl_FragCoord.y/resolution.y-0.5; + ray.xy+=p.xy*spread*(nearZ-cameraZ); + vec3 rayDir=vec3(spread*p.xy*delta,delta); + vec3 tempDir=rayDir*rot; + vec3 norm; + ray.z=nearZ; + bool refracted=false; + for(int i=0;i<250;i++){ + vec3 temp; + vec3 tempc; + float val; + temp=ray.xyz*rot; + tempc=temp; + float thres=0.5; + if(tempc.x<0.0)tempc.x=abs(tempc.x); + if(tempc.x=farZ)break; + } + col.x=col.x/float(iter); + col.y=col.y/float(iter); + col.z=col.z/float(iter); + gl_FragColor=vec4(col,1.0); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/5359.8.frag b/samples/HerokuShaders/Assets/5359.8.frag new file mode 100644 index 000000000..fa4e4932b --- /dev/null +++ b/samples/HerokuShaders/Assets/5359.8.frag @@ -0,0 +1,133 @@ +//http://glsl.heroku.com/e#5359.8 + + +uniform float time; +uniform vec2 resolution; + + +// NEBULA - CoffeeBreakStudios.com (CBS) +// Work in progress.... +// +// 3148.26: Switched from classic to simplex noise +// 3148.27: Reduced number of stars +// 3249.0: Switched to fast computed 3D noise. Less quality but ~ 2x faster +// 3249.5: Removed use of random number generator to gain performance +// 3265.0: Added rotation: glsl.heroku.com/e#3005.1 +// 3265.6: Faster random number generator +// 5359.0: Added Barrel distortion and different starfield: http://glsl.heroku.com/e#5334.3 + +//Utility functions + +vec3 fade(vec3 t) { + return vec3(1.0,1.0,1.0); +} + +vec2 rotate(vec2 point, float rads) { + float cs = cos(rads); + float sn = sin(rads); + return point * mat2(cs, -sn, sn, cs); +} + +vec4 randomizer4(const vec4 x) +{ + vec4 z = mod(x, vec4(5612.0)); + z = mod(z, vec4(3.1415927 * 2.0)); + return(fract(cos(z) * vec4(56812.5453))); +} + +float rand(vec2 co){ + return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); +} + +// Fast computed noise +// http://www.gamedev.net/topic/502913-fast-computed-noise/ + +const float A = 1.0; +const float B = 57.0; +const float C = 113.0; +const vec3 ABC = vec3(A, B, C); +const vec4 A3 = vec4(0, B, C, C+B); +const vec4 A4 = vec4(A, A+B, C+A, C+A+B); + +float cnoise4(const in vec3 xx) +{ + vec3 x = mod(xx + 32768.0, 65536.0); + vec3 ix = floor(x); + vec3 fx = fract(x); + vec3 wx = fx*fx*(3.0-2.0*fx); + float nn = dot(ix, ABC); + + vec4 N1 = nn + A3; + vec4 N2 = nn + A4; + vec4 R1 = randomizer4(N1); + vec4 R2 = randomizer4(N2); + vec4 R = mix(R1, R2, wx.x); + float re = mix(mix(R.x, R.y, wx.y), mix(R.z, R.w, wx.y), wx.z); + + return 1.0 - 2.0 * re; +} +float surface3 ( vec3 coord, float frequency ) { + + float n = 0.0; + + n += 1.0 * abs( cnoise4( coord * frequency ) ); + n += 0.5 * abs( cnoise4( coord * frequency * 2.0 ) ); + n += 0.25 * abs( cnoise4( coord * frequency * 4.0 ) ); + n += 0.125 * abs( cnoise4( coord * frequency * 8.0 ) ); + n += 0.0625 * abs( cnoise4( coord * frequency * 16.0 ) ); + + return n; +} + +vec2 barrelDistortion(vec2 coord) { + vec2 cc = coord;// - 0.5; + float dist = dot(cc, cc); + return coord + cc * (dist * dist) * .4; +} + +void main( void ) { + float rads = radians(time*3.15); + //vec2 position = gl_FragCoord.xy / resolution.xy; + vec2 position=barrelDistortion(-1.0+2.0*((gl_FragCoord.xy)/resolution.xy)); + vec2 positionStars = ( gl_FragCoord.xy - resolution.xy*.5 ) / resolution.x; + position += rotate(position, rads); + float n = surface3(vec3(position*sin(time*0.1), time * 0.05)*mat3(1,sin(1.0),0,0,.8,.6,0,-.6,.8),0.9); + float n2 = surface3(vec3(position*cos(time*0.1), time * 0.04)*mat3(1,cos(1.0),0,0,.8,.6,0,-.6,.8),0.8); + float lum = length(n); + float lum2 = length(n2); + + vec3 tc = pow(vec3(1.0-lum),vec3(sin(position.x)+cos(time)+4.0,8.0+sin(time)+4.0,8.0)); + vec3 tc2 = pow(vec3(1.1-lum2),vec3(5.0,position.y+cos(time)+7.0,sin(position.x)+sin(time)+2.0)); + vec3 curr_color = (tc*0.8) + (tc2*0.5); + + + // 256 angle steps + float angle = atan(positionStars.y,positionStars.x)/(2.*3.14159265359); + angle += rads*0.5; + angle -= floor(angle); + + float rad = length(positionStars); + + float color = 0.0; + for (int i = 0; i < 10; i++) { + float angleFract = fract(angle*256.); + float angleRnd = floor(angle*256.)+1.; + float angleRnd1 = fract(angleRnd*fract(angleRnd*.7235)*45.1); + float angleRnd2 = fract(angleRnd*fract(angleRnd*.82657)*13.724); + float t = time+angleRnd1*10.; + float radDist = sqrt(angleRnd2+float(i)); + + float adist = radDist/rad*.1; + float dist = (t*.1+adist); + dist = abs(fract(dist)-.5); + color += max(0.,.5-dist*40./adist)*(.5-abs(angleFract-.5))*5./adist/radDist; + + angle = fract(angle+.61); + } + float color1 = color*rad; + + //curr_color += color/(n+n2); + + + gl_FragColor = vec4(curr_color, 1.0)+vec4( color1,color1,color,color1)/(n+n2); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/5398.8.frag b/samples/HerokuShaders/Assets/5398.8.frag new file mode 100644 index 000000000..1c8b4b73e --- /dev/null +++ b/samples/HerokuShaders/Assets/5398.8.frag @@ -0,0 +1,31 @@ +//http://glsl.heroku.com/e#5398.8 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + +void main( void ) { + + float scale = resolution.y / 100.0; + float ring = 50.0; + float radius = resolution.x*1.0; + float gap = scale*.5; + vec2 pos = gl_FragCoord.xy - resolution.xy*.5; + + float d = length(pos); + + // Create the wiggle + d += (sin(pos.y*0.25/scale+time)*sin(pos.x*0.25/scale+time*.5))*scale*2.0; + + // Compute the distance to the closest ring + float v = mod(d + radius/(ring*2.0), radius/ring); + v = abs(v - radius/(ring*2.0)); + + v = clamp(v-gap, 0.0, 1.0); + + d /= radius; + vec3 m = fract((d-1.0)*vec3(ring*-.5, -ring, ring*.25)*0.5); + + gl_FragColor = vec4( m*v, 1.0 ); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/5454.21.frag b/samples/HerokuShaders/Assets/5454.21.frag new file mode 100644 index 000000000..418e0284e --- /dev/null +++ b/samples/HerokuShaders/Assets/5454.21.frag @@ -0,0 +1,128 @@ +//http://glsl.heroku.com/e#5454.21 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + +// from http://glsl.heroku.com/e#5484.0 +vec3 asteroids( vec2 position ) { + + // 256 angle steps + float angle = atan(position.y,position.x)/(2.*3.14159265359); + angle -= floor(angle); + float rad = length(position); + + float color = 0.0; + for (int i = 0; i < 5; i++) { + float angleFract = fract(angle*256.); + float angleRnd = floor(angle*256.)+1.; + float angleRnd1 = fract(angleRnd*fract(angleRnd*.7235)*45.1); + float angleRnd2 = fract(angleRnd*fract(angleRnd*.82657)*13.724); + float t = -time+angleRnd1*10.; + float radDist = sqrt(angleRnd2+float(i)); + + float adist = radDist/rad*.1; + float dist = (t*.1+adist); + dist = abs(fract(dist)-.5); + color += max(0.,.5-dist*40./adist)*(.5-abs(angleFract-.5))*5./adist/radDist; + + angle = fract(angle+.61); + } + + return vec3( color )*.3; +} + +// from http://glsl.heroku.com/e#5248.0 +#define BIAS 0.1 +#define SHARPNESS 3.0 +vec3 star(vec2 position, float BLADES) { + float blade = clamp(pow(sin(atan(position.y,position.x )*BLADES)+BIAS, SHARPNESS), 0.0, 1.0); + vec3 color = mix(vec3(-0.34, -0.5, -1.0), vec3(0.0, -0.5, -1.0), (position.y + 1.0) * 0.25); + float d = 1.0/length(position) * 0.075; + color += vec3(0.95, 0.65, 0.30) * d; + color += vec3(0.95, 0.45, 0.30) * min(1.0, blade *0.7) * d; + return color; +} + +vec3 star2(vec2 position, float BLADES) { + float blade = clamp(pow(sin(atan(position.y,position.x )*BLADES + time*.5)+BIAS, 8.0), 0.0, 1.0); + vec3 color = mix(vec3(-0.34, -0.5, -0.0), vec3(0.0, -0.5, -0.0), (position.y + 1.0) * 0.25); + float d = 1.0/length(position) * 0.075; + color += vec3(0.95, 0.65, 0.30) * d; + color += vec3(0.95, 0.45, 0.30) * min(1.0, blade *0.7)*0.5; + return max(color.rgb, 0.0)*.5; +} + + +// Tweaked from http://glsl.heroku.com/e#4982.0 +float hash( float n ) { return fract(sin(n)*43758.5453); } + +float noise( in vec2 x ) +{ + vec2 p = floor(x); + vec2 f = fract(x); + f = f*f*(3.0-2.0*f); + float n = p.x + p.y*57.0; + float res = mix(mix(hash(n+0.0), hash(n+1.0),f.x), mix(hash(n+57.0), hash(n+58.0),f.x),f.y); + return res; +} + +vec3 cloud(vec2 p) { + vec3 f = vec3(0.0); + f += 0.5000*noise(p*10.0)*vec3(.45, .55, 1.0); + f += 0.2500*noise(p*20.0)*vec3(.85, .45, 1.0); + f += 0.1250*noise(p*40.0)*vec3(1.0, .00, 0.3); + f += 0.0625*noise(p*80.0)*vec3(1.0, 1.0, 1.0); + return f*.5; +} + +const float SPEED = 0.005; +const float SCALE = 80.0; +const float DENSITY = 1.5; +const float BRIGHTNESS = 10.0; +vec2 ORIGIN = resolution.xy*.5; + +float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } + +vec3 layer(float i, vec2 pos, float dist, vec2 coord) { + float a = pow((1.0-dist),20.0); + float t = i*10.0 - time*i*i; + float r = coord.x - (t*SPEED); + float c = fract(a+coord.y + i*.543); + vec2 p = vec2(r, c*.5)*SCALE*(4.0/(i*i)); + vec2 uv = fract(p)*2.0-1.0; + float m = clamp((rand(floor(p))-DENSITY/i)*BRIGHTNESS, 0.0, 1.0); + return clamp(star(uv*.5, 6.0)*m*dist, 0.0, 1.0); +} + +void main( void ) { + + vec2 pos = gl_FragCoord.xy - ORIGIN ; + float dist = length(pos) / resolution.y; + vec2 coord = vec2(pow(dist, 0.1), atan(pos.x, pos.y) / (3.1415926*2.0)); + + // Nebulous cloud + vec3 color = cloud(pos/resolution); + + // Background stars + float a = pow((1.0-dist),20.0); + float t = time*-.05; + float r = coord.x - (t*0.005); + float c = fract(a+coord.y + 0.0*.543); + vec2 p = vec2(r, c*.5)*4000.0; + vec2 uv = fract(p)*2.0-1.0; + float m = clamp((rand(floor(p))-.9)*10.0, 0.0, 1.0); + color += clamp((1.0-length(uv*2.0))*m*dist, 0.0, 1.0); + + color += asteroids(pos/resolution.x); + + // Flying stars into black hole + color += layer(2.0, pos, dist, coord); + color += layer(3.0, pos, dist, coord); + color += layer(4.0, pos, dist, coord); + + color += star2(pos/resolution, 2.0); + + gl_FragColor = vec4(color, 1.0); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/5492.frag b/samples/HerokuShaders/Assets/5492.frag new file mode 100644 index 000000000..fe81806a7 --- /dev/null +++ b/samples/HerokuShaders/Assets/5492.frag @@ -0,0 +1,127 @@ +//http://glsl.heroku.com/e#5492.0 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + + +// Helper constants +#define F2 0.366025403 +#define G2 0.211324865 +#define K 0.0243902439 // 1/41 + +// Permutation polynomial +float permute(float x) { + return mod((34.0 * x + 1.0)*x, 289.0); +} + +// Gradient mapping with an extra rotation. +vec2 grad2(vec2 p, float rot) { +#if 1 +// Map from a line to a diamond such that a shift maps to a rotation. + float u = permute(permute(p.x) + p.y) * K + rot; // Rotate by shift + u = 4.0 * fract(u) - 2.0; + return vec2(abs(u)-1.0, abs(abs(u+1.0)-2.0)-1.0); +#else +#define TWOPI 6.28318530718 +// For more isotropic gradients, sin/cos can be used instead. + float u = permute(permute(p.x) + p.y) * K + rot; // Rotate by shift + u = fract(u) * TWOPI; + return vec2(cos(u), sin(u)); +#endif +} + +float srdnoise(in vec2 P, in float rot, out vec2 grad) { + + // Transform input point to the skewed simplex grid + vec2 Ps = P + dot(P, vec2(F2)); + + // Round down to simplex origin + vec2 Pi = floor(Ps); + + // Transform simplex origin back to (x,y) system + vec2 P0 = Pi - dot(Pi, vec2(G2)); + + // Find (x,y) offsets from simplex origin to first corner + vec2 v0 = P - P0; + + // Pick (+x, +y) or (+y, +x) increment sequence + vec2 i1 = (v0.x > v0.y) ? vec2(1.0, 0.0) : vec2 (0.0, 1.0); + + // Determine the offsets for the other two corners + vec2 v1 = v0 - i1 + G2; + vec2 v2 = v0 - 1.0 + 2.0 * G2; + + // Wrap coordinates at 289 to avoid float precision problems + Pi = mod(Pi, 289.0); + + // Calculate the circularly symmetric part of each noise wiggle + vec3 t = max(0.5 - vec3(dot(v0,v0), dot(v1,v1), dot(v2,v2)), 0.0); + vec3 t2 = t*t; + vec3 t4 = t2*t2; + + // Calculate the gradients for the three corners + vec2 g0 = grad2(Pi, rot); + vec2 g1 = grad2(Pi + i1, rot); + vec2 g2 = grad2(Pi + 1.0, rot); + + // Compute noise contributions from each corner + vec3 gv = vec3(dot(g0,v0), dot(g1,v1), dot(g2,v2)); // ramp: g dot v + vec3 n = t4 * gv; // Circular kernel times linear ramp + + // Compute partial derivatives in x and y + vec3 temp = t2 * t * gv; + vec3 gradx = temp * vec3(v0.x, v1.x, v2.x); + vec3 grady = temp * vec3(v0.y, v1.y, v2.y); + grad.x = -8.0 * (gradx.x + gradx.y + gradx.z); + grad.y = -8.0 * (grady.x + grady.y + grady.z); + grad.x += dot(t4, vec3(g0.x, g1.x, g2.x)); + grad.y += dot(t4, vec3(g0.y, g1.y, g2.y)); + grad *= 40.0; + + // Add contributions from the three corners and return + return 40.0 * (n.x + n.y + n.z); +} + + +vec2 complex_mul(vec2 factorA, vec2 factorB){ + return vec2( factorA.x*factorB.x - factorA.y*factorB.y, factorA.x*factorB.y + factorA.y*factorB.x); +} + +vec2 torus_mirror(vec2 uv){ + return vec2(1.)-abs(fract(uv*.5)*2.-1.); +} + +float sigmoid(float x) { + return 2./(1. + exp2(-x)) - 1.; +} + +float smoothcircle(vec2 uv, float radius, float sharpness){ + return 0.5 - sigmoid( ( length( (uv - 0.5)) - radius) * sharpness) * 0.5; +} + + +void main() { + + vec2 posScale = vec2(2.0); + + vec2 aspect = vec2(1.,resolution.y/resolution.x); + vec2 uv = 0.5 + (gl_FragCoord.xy * vec2(1./resolution.x,1./resolution.y) - 0.5)*aspect; + float mouseW = atan((mouse.y - 0.5)*aspect.y, (mouse.x - 0.5)*aspect.x); + vec2 mousePolar = vec2(sin(mouseW), cos(mouseW)); + vec2 offset = (mouse - 0.5)*4.; + offset = - complex_mul(offset, mousePolar) +time*0.0; + vec2 uv_distorted = uv; + + float filter = smoothcircle( -mouse + 0.5 +uv_distorted, 0.15, 64.); + uv_distorted = complex_mul(((uv_distorted - 0.5)*mix(2., 12., filter)), mousePolar) + offset; + + vec2 p = uv_distorted; + vec2 g1, g2; + // vec2 p = ( gl_FragCoord.xy / resolution.xy ) * 6.0; + float n1 = srdnoise(p*0.5, 0.0*time, g1); + float n2 = srdnoise(p*2.0 + g1*0.5, 0.51*time, g2); + float n3 = srdnoise(p*4.0 + g1*0.5 + g2*0.25, 0.77*time, g2); + gl_FragColor = vec4(vec3(0.4, 0.5, 0.6) + vec3(n1+0.75*n2+0.5*n3), 1.0); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/5733.frag b/samples/HerokuShaders/Assets/5733.frag new file mode 100644 index 000000000..9c7ee275d --- /dev/null +++ b/samples/HerokuShaders/Assets/5733.frag @@ -0,0 +1,24 @@ +//http://glsl.heroku.com/e#5733.0 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; +varying vec2 surfacePosition; + + +void main( void ) { + vec2 p = surfacePosition; + float speed = 0.25; + vec3 color = vec3(0.5,0.2,0.1); + vec2 loc = vec2(cos(time/4.0*speed)/1.9-cos(time/2.0*speed)/3.8, + sin(time/4.0*speed)/1.9-sin(time/2.0*speed)/3.8 + ); + float depth; + for(int i = 0; i < 100; i+=1){ + p = vec2(p.x*p.x-p.y*p.y,2.0*p.y*p.x)+loc; + depth = float(i); + if((p.x*p.x-p.y*p.y) >= 25.0) break; + } + gl_FragColor = vec4(clamp(color*depth*0.9, 0.0, 2.0)*mod(gl_FragCoord.y, 2.0), 2.0 ); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/5805.18.frag b/samples/HerokuShaders/Assets/5805.18.frag new file mode 100644 index 000000000..7464351d2 --- /dev/null +++ b/samples/HerokuShaders/Assets/5805.18.frag @@ -0,0 +1,44 @@ +//http://glsl.heroku.com/e#5805.18 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + +float function_f (float x) { + return + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x+200.0)*0.1)) + - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x+100.0)*0.1)) + + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp(x*0.1)) + - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x-100.0)*0.1)) + + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x-200.0)*0.1)) + + sin(x*0.1 - time*10.0 + mouse.x * 10.0)*50.0; +} + +float function_g (float x) { + return - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x+200.0)*0.1)) + + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x+100.0)*0.1)) + - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp(x*0.1)) + + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x-100.0)*0.1)) + - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x-200.0)*0.1)) + + sin(x*0.1 + time*5.0 - mouse.x * 10.0)*50.0; +} + + +void main( void ) { + + vec3 color_1 = vec3(0.25, sin(time), cos(time)); + vec3 color_2 = vec3(0.5, 0.25, cos(time)); + + vec2 pos = gl_FragCoord.xy; + + pos.y -= resolution.y / 2.0; + pos.x -= resolution.x / 2.0; + + float intensity_f = 16.0 / abs(pos.y - function_f(pos.x)); + intensity_f = pow(intensity_f, 0.5); + + float intensity_g = 16.0 / abs(pos.y - function_g(pos.x)); + intensity_g += pow(intensity_g, 0.5); + + gl_FragColor = vec4((color_1 * intensity_f + color_2 * intensity_g)*mod(gl_FragCoord.y, 2.0), 1); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/5812.frag b/samples/HerokuShaders/Assets/5812.frag new file mode 100644 index 000000000..9d080d3bb --- /dev/null +++ b/samples/HerokuShaders/Assets/5812.frag @@ -0,0 +1,44 @@ +//http://glsl.heroku.com/e#5812 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + +float random(vec2 v) +{ +return fract(sin(dot(v ,vec2(13.9898,78.233))) * (10000.0+time*0.05)); +} + +void main( void ) +{ + const int numColors = 3; + vec3 colors[numColors]; + colors[0] = vec3( 0.3, 0.8, 0.8); + colors[1] = vec3( 0.8, 0.9, 0.4); + colors[2] = vec3( 0.4, 0.4, 0.5); + + vec2 screenPos = gl_FragCoord.xy; + vec2 screenPosNorm = gl_FragCoord.xy / resolution.xy; + vec2 position = screenPosNorm + mouse / 4.0; + + // calc block + vec2 screenBlock0 = floor(screenPos*0.16 + vec2(time,0) + mouse*3.0); + vec2 screenBlock1 = floor(screenPos*0.08 + vec2(time*1.5,0) + mouse*5.0); + vec2 screenBlock2 = floor(screenPos*0.02 + vec2(time*2.0,0)+mouse*10.0); + float rand0 = random(screenBlock0); + float rand1 = random(screenBlock1); + float rand2 = random(screenBlock2); + + float rand = rand1; + if ( rand2 < 0.05 ) { rand = rand2; } + + // block color + vec3 color = mix( colors[0], colors[1], pow(rand,5.0) ); + if ( rand < 0.05 ) { color=colors[2]; } + + float vignette = 1.6-length(screenPosNorm*2.0-1.0); + vec4 finalColor = vec4(color*vignette, 1.0); + + gl_FragColor = finalColor; +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/5891.5.frag b/samples/HerokuShaders/Assets/5891.5.frag new file mode 100644 index 000000000..88066932f --- /dev/null +++ b/samples/HerokuShaders/Assets/5891.5.frag @@ -0,0 +1,40 @@ +//http://glsl.heroku.com/e#5891.5 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + +const float Tau = 6.2832; +const float speed = .02; +const float density = .04; +const float shape = .04; + +float random( vec2 seed ) { + return fract(sin(seed.x+seed.y*1e3)*1e5); +} + +float Cell(vec2 coord) { + vec2 cell = fract(coord) * vec2(.5,2.) - vec2(.0,.5); + return (1.-length(cell*2.-1.))*step(random(floor(coord)),density)*2.; +} + +void main( void ) { + + vec2 p = gl_FragCoord.xy / resolution - mouse; + + float a = fract(atan(p.x, p.y) / Tau); + float d = length(p); + + vec2 coord = vec2(pow(d, shape), a)*256.; + vec2 delta = vec2(-time*speed*256., .5); + + float c = 0.; + for(int i=0; i<3; i++) { + coord += delta; + c = max(c, Cell(coord)); + } + + gl_FragColor = vec4(c * d); + +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/6022.frag b/samples/HerokuShaders/Assets/6022.frag new file mode 100644 index 000000000..8bc0ddc23 --- /dev/null +++ b/samples/HerokuShaders/Assets/6022.frag @@ -0,0 +1,84 @@ +//http://glsl.heroku.com/e#6022.0 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; +varying vec2 surfacePosition; + +float rand(vec2 co){ + return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43748.5453); +} +float cerp(float a, float b, float i) +{ + if(i<0.) + i += 1.; + i *= 3.14159265; + i = (1.-cos(i))/2.; + return a*(1.-i)+b*i; +} +float lerp(float a, float b, float i) +{ + if(i<0.) + i+=1.; + return a*(1.-i)+b*i; +} +vec3 lerp(vec3 a, vec3 b, float i) +{ + if(i<0.) + i+=1.; + return a*(1.-i)+b*i; +} +float posrand(vec2 pos, float width, float height) +{ + return rand(vec2(int(pos.x*width),int(pos.y*height))); +} +float tdposrand(vec2 pos, float width, float height) +{ + float n1, n2, n3, n4, n5, n6; + n1 = posrand(pos,width,height); + n2 = posrand(vec2(pos.x+1./width,pos.y),width,height); + n3 = posrand(vec2(pos.x,pos.y+1./height),width,height); + n4 = posrand(vec2(pos.x+1./width,pos.y+1./height),width,height); + n5 = cerp(n1,n2,pos.x*width-float(int(pos.x*width))); + n6 = cerp(n3,n4,pos.x*width-float(int(pos.x*width))); + return cerp(n5,n6,pos.y*height-float(int(pos.y*height))); +} + +vec3 readcolpath(vec3 one, vec3 two, vec3 thr, vec3 fou, float i) +{ + int num = int(i*3.); + if(num==0) + return lerp(one,two,i*3.-float(num)); + if(num==1) + return lerp(two,thr,i*3.-float(num)); + if(num==2) + return lerp(thr,fou,i*3.-float(num)); + return fou; +} +void main( void ) { + + vec2 position = surfacePosition+.5; + vec2 odd = vec2(0,time/5.); + vec3 col1 = vec3(1.,0.25,0.); + vec3 col2 = vec3(.45,0.2,0.); + vec3 col3 = vec3(0.2,.1,0.); + vec3 col4 = vec3(.4,.3,.25); + float color = 0.0; + position = position*(1.+1./12.)+vec2(length(vec2(tdposrand(position-odd,2.,2.),tdposrand(position*4.3-odd,2.,2.))))/12.; + if(position.y>0.) + { + //color += tdposrand(position-odd,1000.,1000.)/5.; + color += tdposrand(position-odd,50.,50.)/8.; + color += tdposrand(position-odd,20.,20.)/3.; + color += tdposrand(position-odd,10.,10.)/2.; + color += tdposrand(position-odd,5.,5.); + color /= position.y*1.; + } + else + { + color = 16.0; + } + gl_FragColor = vec4( vec3( color/2. )*readcolpath(col1,col2,col3,col4,color/16.), 1.0 ); + +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/6043.1.frag b/samples/HerokuShaders/Assets/6043.1.frag new file mode 100644 index 000000000..9d6f23863 --- /dev/null +++ b/samples/HerokuShaders/Assets/6043.1.frag @@ -0,0 +1,137 @@ +//http://glsl.heroku.com/e#6043.1 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + +//.h +vec3 sim(vec3 p,float s); +vec2 rot(vec2 p,float r); +vec2 rotsim(vec2 p,float s); + +//nice stuff :) +vec2 makeSymmetry(vec2 p){ + vec2 ret=p; + ret=rotsim(ret,5.08052); + ret.x=abs(ret.x); + return ret; +} + +float makePoint(float x,float y,float fx,float fy,float sx,float sy,float t){ + float xx=x+tan(t*fx)*sx; + float yy=y-tan(t*fy)*sy; + return 0.5/sqrt(abs(x*xx+yy*yy)); +} + + + +//util functions +const float PI=5.08052; + +vec3 sim(vec3 p,float s){ + vec3 ret=p; + ret=p+s/2.0; + ret=fract(ret/s)*s-s/2.0; + return ret; +} + +vec2 rot(vec2 p,float r){ + vec2 ret; + ret.x=p.x*cos(r)-p.y*sin(r); + ret.y=p.x*sin(r)+p.y*cos(r); + return ret; +} + +vec2 rotsim(vec2 p,float s){ + vec2 ret=p; + ret=rot(p,-PI/(s*2.0)); + ret=rot(p,floor(atan(ret.x,ret.y)/PI*s)*(PI/s)); + return ret; +} +//Util stuff end + + + +vec2 complex_mul(vec2 factorA, vec2 factorB){ + return vec2( factorA.x*factorB.x - factorA.y*factorB.y, factorA.x*factorB.y + factorA.y*factorB.x); +} + +vec2 torus_mirror(vec2 uv){ + return vec2(1.)-abs(fract(uv*.5)*2.-1.); +} + +float sigmoid(float x) { + return 2./(1. + exp2(-x)) - 1.; +} + +float smoothcircle(vec2 uv, float radius, float sharpness){ + return 0.5 - sigmoid( ( length( (uv - 0.5)) - radius) * sharpness) * 0.5; +} + + +void main() { + + vec2 posScale = vec2(2.0); + + vec2 aspect = vec2(1.,resolution.y/resolution.x); + vec2 uv = 0.5 + (gl_FragCoord.xy * vec2(1./resolution.x,1./resolution.y) - 0.5)*aspect; + float mouseW = atan((mouse.y - 0.5)*aspect.y, (mouse.x - 0.5)*aspect.x); + vec2 mousePolar = vec2(sin(mouseW), cos(mouseW)); + vec2 offset = (mouse - 0.5)*2.*aspect; + offset = - complex_mul(offset, mousePolar) +time*0.0; + vec2 uv_distorted = uv; + + float filter = smoothcircle( uv_distorted, 0.12, 100.); + uv_distorted = complex_mul(((uv_distorted - 0.5)*mix(2., 6., filter)), mousePolar) + offset; + + + vec2 p=(gl_FragCoord.xy/resolution.x)*2.0-vec2(1.0,resolution.y/resolution.x); + p = uv_distorted; +p.y=-p.y; + p=p*2.0; + + p=makeSymmetry(p); + + float x=p.x; + float y=p.y; + + float t=time*0.1618; + + float a= + makePoint(x,y,3.3,2.9,0.3,0.3,t); + a=a+makePoint(x,y,1.9,2.0,0.4,0.4,t); + a=a+makePoint(x,y,0.8,0.7,0.4,0.5,t); + a=a+makePoint(x,y,2.3,0.1,0.6,0.3,t); + a=a+makePoint(x,y,0.8,1.7,0.5,0.4,t); + a=a+makePoint(x,y,0.3,1.0,0.4,0.4,t); + a=a+makePoint(x,y,1.4,1.7,0.4,0.5,t); + a=a+makePoint(x,y,1.3,2.1,0.6,0.3,t); + a=a+makePoint(x,y,1.8,1.7,0.5,0.4,t); + + float b= + makePoint(x,y,1.2,1.9,0.3,0.3,t); + b=b+makePoint(x,y,0.7,2.7,0.4,0.4,t); + b=b+makePoint(x,y,1.4,0.6,0.4,0.5,t); + b=b+makePoint(x,y,2.6,0.4,0.6,0.3,t); + b=b+makePoint(x,y,0.7,1.4,0.5,0.4,t); + b=b+makePoint(x,y,0.7,1.7,0.4,0.4,t); + b=b+makePoint(x,y,0.8,0.5,0.4,0.5,t); + b=b+makePoint(x,y,1.4,0.9,0.6,0.3,t); + b=b+makePoint(x,y,0.7,1.3,0.5,0.4,t); + + float c= + makePoint(x,y,3.7,0.3,0.3,0.3,t); + c=c+makePoint(x,y,1.9,1.3,0.4,0.4,t); + c=c+makePoint(x,y,0.8,0.9,0.4,0.5,t); + c=c+makePoint(x,y,1.2,1.7,0.6,0.3,t); + c=c+makePoint(x,y,0.3,0.6,0.5,0.4,t); + c=c+makePoint(x,y,0.3,0.3,0.4,0.4,t); + c=c+makePoint(x,y,1.4,0.8,0.4,0.5,t); + c=c+makePoint(x,y,0.2,0.6,0.6,0.3,t); + c=c+makePoint(x,y,1.3,0.5,0.5,0.4,t); + + vec3 d=vec3(a+b,b+c,c)/32.0; + + gl_FragColor = vec4(d.x,d.y,d.z,1.0); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/6049.frag b/samples/HerokuShaders/Assets/6049.frag new file mode 100644 index 000000000..013c02fa8 --- /dev/null +++ b/samples/HerokuShaders/Assets/6049.frag @@ -0,0 +1,189 @@ +//http://glsl.heroku.com/e#6049.0 + + +uniform vec2 resolution; +uniform float time; +uniform vec2 mouse; + +//Util Start +float PI=3.14159265; + +vec2 ObjUnion( + in vec2 obj0, + in vec2 obj1) +{ + if (obj0.x0.0) fp.x=-fp.x; + if (fp.x>0.0) return vec3(0.0,0.0,0.0); + else return vec3(1.0,1.0,1.0); +} + +//Scene End + +float raymarching( + in vec3 prp, + in vec3 scp, + in int maxite, + in float precis, + in float startf, + in float maxd, + out float objid) +{ + const vec3 e=vec3(0.1,0,0.0); + vec2 s=vec2(startf,0.0); + vec3 c,p,n; + float f=startf; + for(int i=0;i<256;i++){ + if (abs(s.x)maxd||i>maxite) break; + f+=s.x; + p=prp+scp*f; + s=obj(p); + objid=s.y; + } + if (f>maxd) objid=-1.0; + return f; +} + + +vec3 camera( + in vec3 prp, + in vec3 vrp, + in vec3 vuv, + in float vpd) +{ + vec2 vPos=-1.0+2.0*gl_FragCoord.xy/resolution.xy; + vec3 vpn=normalize(vrp-prp); + vec3 u=normalize(cross(vuv,vpn)); + vec3 v=cross(vpn,u); + vec3 scrCoord=prp+vpn*vpd+vPos.x*u*resolution.x/resolution.y+vPos.y*v; + return normalize(scrCoord-prp); +} + +vec3 normal(in vec3 p) +{ + //tetrahedron normal + const float n_er=0.01; + float v1=obj(vec3(p.x+n_er,p.y-n_er,p.z-n_er)).x; + float v2=obj(vec3(p.x-n_er,p.y-n_er,p.z+n_er)).x; + float v3=obj(vec3(p.x-n_er,p.y+n_er,p.z-n_er)).x; + float v4=obj(vec3(p.x+n_er,p.y+n_er,p.z+n_er)).x; + return normalize(vec3(v4+v1-v3-v2,v3+v4-v1-v2,v2+v4-v3-v1)); +} + +vec3 render( + in vec3 prp, + in vec3 scp, + in int maxite, + in float precis, + in float startf, + in float maxd, + in vec3 background, + in vec3 light, + in float spec, + in vec3 ambLight, + out vec3 n, + out vec3 p, + out float f, + out float objid) +{ + objid=-1.0; + f=raymarching(prp,scp,maxite,precis,startf,maxd,objid); + if (objid>-0.5){ + p=prp+scp*f; + vec3 c=obj_c(p); + n=normal(p); + vec3 cf=phong(p,prp,n,light,c,spec,ambLight); + return vec3(cf); + } + f=maxd; + return vec3(background); //background color +} + +void main(void){ + + //Camera animation + vec3 vuv=vec3(0,1,0); + vec3 vrp=vec3(time*4.0,0.0,0.0); + float mx=mouse.x*PI*2.0; + float my=mouse.y*PI/2.01; + vec3 prp=vrp+vec3(cos(my)*cos(mx),sin(my),cos(my)*sin(mx))*12.0; //Trackball style camera pos + float vpd=1.5; + vec3 light=prp+vec3(5.0,0,5.0); + + vec3 scp=camera(prp,vrp,vuv,vpd); + vec3 n,p; + float f,o; + const float maxe=0.01; + const float startf=0.1; + const vec3 backc=vec3(0.0,0.0,0.0); + const float spec=8.0; + const vec3 ambi=vec3(0.1,0.1,0.1); + + vec3 c1=render(prp,scp,256,maxe,startf,60.0,backc,light,spec,ambi,n,p,f,o); + c1=c1*max(1.0-f*.015,0.0); + vec3 c2=backc; + if (o>0.5){ + scp=reflect(scp,n); + c2=render(p+scp*0.05,scp,32,maxe,startf,10.0,backc,light,spec,ambi,n,p,f,o); + } + c2=c2*max(1.0-f*.1,0.0); + gl_FragColor=vec4(c1.xyz*0.75+c2.xyz*0.25,1.0); + +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/6147.1.frag b/samples/HerokuShaders/Assets/6147.1.frag new file mode 100644 index 000000000..ee2fec8dd --- /dev/null +++ b/samples/HerokuShaders/Assets/6147.1.frag @@ -0,0 +1,59 @@ +//http://glsl.heroku.com/e#6147.1 + + +#define PI 3.14159265 +uniform float time; +uniform vec2 mouse, resolution; + +vec3 sim(vec3 p,float s); //.h +vec2 rot(vec2 p,float r); +vec2 rotsim(vec2 p,float s); + +vec2 makeSymmetry(vec2 p){ //nice stuff :) + vec2 ret=p; + ret=rotsim(p, 6.0); + ret.x=abs(ret.x); + return ret; +} + +float makePoint(float x,float y,float fx,float fy,float sx,float sy,float t){ + + float xx=x+tan(t * fx)*sy; + float yy=y-tan(t * fx)*sy; + return 0.8/sqrt(abs(x*xx+yy*yy)); +} + +vec2 sim(vec2 p,float s){ + vec2 ret=p; + ret=p+s/2.0; + ret=fract(ret/s)*s-s/2.0; + return ret; +} + +vec2 rot(vec2 p,float r){ + vec2 ret; + ret.x=p.x*cos(r)-p.y*sin(r); + ret.y=p.x*sin(r)+p.y*cos(r); + return ret; +} + +vec2 rotsim(vec2 p,float s){ + float k = atan(p.x, p.y); + vec2 ret=rot(p,floor((k + PI/(s*2.0)) / PI*s)*(PI/s)); + return ret; +} + +void main( void ) { + vec2 p=(gl_FragCoord.xy/resolution.x)*2.0-vec2(1.0,resolution.y/resolution.x); + p=makeSymmetry(p); + float x=p.x; + float y=p.y; + float t=time*0.2; + float a= makePoint(x,y,3.3,2.9,0.3,0.3,t); +// a=a+makePoint(x,y,1.8,1.7,0.5,0.4,t); + float b=makePoint(x,y,1.2,1.9,0.3,0.3,t); +// b=b+makePoint(x,y,0.7,2.7,0.4,0.4,t); + float c=makePoint(x,y,3.7,0.3,0.3,0.3,t); +// c=c+makePoint(x,y,0.8,0.9,0.4,0.5,t); + gl_FragColor = vec4(a/5.,b/5.,c/5.,1.0); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/6162.frag b/samples/HerokuShaders/Assets/6162.frag new file mode 100644 index 000000000..015ed2814 --- /dev/null +++ b/samples/HerokuShaders/Assets/6162.frag @@ -0,0 +1,92 @@ +//http://glsl.heroku.com/e#6162.0 + + +#define PI 3.141592653589793 + +#define ZOOM (4. - sin(time/2.)*3.) + +#define MAX_ITERATION 6 +#define ITERATION_BAIL sqrt(PI/2.) + +#define MAX_MARCH 50 +#define MAX_DISTANCE 2.3 + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + +float DE(vec3 p) +{ + vec3 w = p; + float dr = 1.; + float r = 0.; + for (int i=0; iITERATION_BAIL) break; + + dr*=pow(r, 7.)*8.+1.; + + float x = w.x; float x2 = x*x; float x4 = x2*x2; + float y = w.y; float y2 = y*y; float y4 = y2*y2; + float z = w.z; float z2 = z*z; float z4 = z2*z2; + + float k3 = x2 + z2; + float k2 = inversesqrt( pow(k3, 7.) ); + float k1 = x4 + y4 + z4 - 6.0*y2*z2 - 6.0*x2*y2 + 2.0*z2*x2; + float k4 = x2 - y2 + z2; + + w = vec3(64.0*x*y*z*(x2-z2)*k4*(x4-6.0*x2*z2+z4)*k1*k2, + -16.0*y2*k3*k4*k4 + k1*k1, + -8.0*y*k4*(x4*x4 - 28.0*x4*x2*z2 + 70.0*x4*z4 - 28.0*x2*z2*z4 + z4*z4)*k1*k2); + w+=p; + } + return .5*log(r)*r/dr; +} + +bool inCircle(vec3 p, vec3 d) +{ + float rdt = dot(p, d); + float rdr = dot(p, p) - 1.253314137315501; // sqrt(PI/2) + return (rdt*rdt)-rdr>0.; +} + + +void main( void ) +{ + vec2 pos = (gl_FragCoord.xy*2.0 - resolution.xy) / resolution.y; + + vec2 m = vec2(sin(time), cos(time))/ZOOM; + //m = ((.5-mouse)*PI*2.)/ZOOM; + m.y = clamp(m.y, -PI/2.+.01, PI/2.-.01); + + vec3 camOrigin = vec3(cos(m.x)*cos(m.y), sin(m.y), cos(m.y)*sin(m.x))*2.0; + vec3 camTarget = vec3(0.0, 0.0, 0.0); + vec3 camDir = normalize(camTarget - camOrigin); + vec3 camUp = normalize(vec3(0.0, 1.0, 0.0)); + vec3 camSide = normalize(cross(camDir, camUp)); + vec3 camCDS = cross(camDir, camSide); + + vec3 ray = normalize(camSide*pos.x + camCDS*pos.y + camDir*ZOOM); + + float col = 0., col2 = 0., col3 = 0.; + if (inCircle(camOrigin, ray)) + { + float m = 1.0, dist = 0.0, total_dist = 0.0; + + for(int i=0; iMAX_DISTANCE) break; + } + + col = m; + col2 = m*2.5-total_dist; + col3 = m*1.5-total_dist; + if (total_dist>MAX_DISTANCE) col = 0.; + } + + gl_FragColor = vec4(col, col2/2., col3*2., 1.0); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/6175.frag b/samples/HerokuShaders/Assets/6175.frag new file mode 100644 index 000000000..acc31e37e --- /dev/null +++ b/samples/HerokuShaders/Assets/6175.frag @@ -0,0 +1,225 @@ +//http://glsl.heroku.com/e#6175.0 + + +uniform float time; +uniform vec2 resolution; +uniform vec4 mouse; +uniform sampler2D tex0; +uniform sampler2D tex1; + +const float M_PI = 3.14159265358979323846; + +struct SphereIntersection +{ + // IN: + vec4 sphere; + vec3 ro; + vec3 rd; + // OUT: + float t; + vec3 pos; + vec3 normal; + float depth; +}; + +float saturate(float f) +{ + return clamp(f,0.0,1.0); +} + +vec3 saturate(vec3 v) +{ + return clamp(v,vec3(0,0,0),vec3(1,1,1)); +} + +// ... I went on the internet and I found THIS +float rand(vec2 co) +{ + return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); +} + +// Theta, Phi (r == 1) +vec2 normalToSpherical(vec3 normal) +{ + vec2 spherical; + // Flip ZY. + normal.yz = normal.zy; + spherical.x = atan(normal.y,normal.x); // Theta + spherical.y = acos(normal.z); // Phi + return spherical; +} + +// Input: Theta, Phi +vec3 sphericalToCartesian(vec2 s) +{ + vec3 cart; + cart.x = cos(s.x) * sin(s.y); + cart.y = sin(s.x) * sin(s.y); + cart.z = cos(s.y); + // Flip ZY + cart.yz = cart.zy; + return cart; +} + +// Ray origin, Ray direction, (Sphere center, Sphere radius) +void raySphere(inout SphereIntersection i) +{ + vec4 sphere = i.sphere; + vec3 ro = i.ro; + vec3 rd = i.rd; + vec3 sc = sphere.xyz; + float sr = sphere.w; + vec3 sd = ro-sc; + // a == 1 + float b = 2.0*dot(rd,sd); + float c = dot(sd,sd)-(sr*sr); + float disc = b*b - 4.0*c; + if(disc<0.0) + { + i.t = -1.0; + return; + } + float t = (-b-sqrt(disc))/2.0; + i.t = t; + i.pos = ro+rd*t; + i.normal = normalize(i.pos-sphere.xyz); + i.depth = 2.0*sr*dot(normalize(sd),i.normal); +} + +vec3 sphereNormal(vec4 sphere, vec3 point) +{ + return normalize(point-sphere.xyz); +} + +float sphereFunction(vec2 coord) +{ + coord.x -= time/4.0; + coord.y += sin(time/4.0); + float thetaCoeff = 24.0; + float phiCoeff = 16.0; + float height = 0.8; + height += (sin(3.0*coord.y)*sin(4.0*coord.x))/10.0; + height += (sin(16.0*coord.y)*sin(24.0*coord.x))/10.0; + return height; +} + +vec3 sphereFunctionNormal(vec2 coord, vec4 sphere) +{ + // Approximates the local slope of the heightfield function + float d = 0.01; + vec2 s0coord = coord; // Center + vec2 s1coord = coord+vec2(d,0); // +X = +Theta + vec2 s2coord = coord+vec2(0,-d); // +Y = -Phi + // Sample heightfield + float s0 = sphereFunction(s0coord) * sphere.w; + float s1 = sphereFunction(s1coord) * sphere.w; + float s2 = sphereFunction(s2coord) * sphere.w; + // Convert samples to cartesian + vec3 s0c = sphericalToCartesian(s0coord)*s0; + vec3 s1c = sphericalToCartesian(s1coord)*s1; + vec3 s2c = sphericalToCartesian(s2coord)*s2; + // Tangent space + vec3 x = s1c-s0c; + vec3 y = s2c-s0c; + vec3 normal = normalize(cross(y,x)); + return normal; +} + +void rayMarchSphere(inout SphereIntersection i) +{ + const float NUM_SAMPLES = 50.0; + vec3 pos = i.pos; + vec3 dir = i.rd; + float stepSize = i.depth/NUM_SAMPLES; + + // No hit + i.t = -1.0; + + for(float s = 0.0; s < NUM_SAMPLES; s++) + { + if(s == 0.0) + { + pos += dir*stepSize*rand(gl_FragCoord.xy); + } + vec3 v = pos-i.sphere.xyz; + float height = length(v); + vec3 n = v/height; + vec2 sCoord = normalToSpherical(n); + float testHeight = sphereFunction(sCoord)*i.sphere.w; + testHeight += 0.000001; // Prevent floating point error + if(height<=testHeight) + { + i.t = length(pos-i.ro); + i.pos = pos; + i.normal = n; + i.normal = sphereFunctionNormal(sCoord,i.sphere); + return; + } + pos += dir*stepSize; + } + return; +} + +vec3 lighting(vec3 point, vec3 N, vec3 light, vec3 color) +{ + vec3 toLight = light-point; + vec3 L = normalize(toLight); + return color*saturate(dot(N,L)); +} + +void rayMarchedSphereIntersection(inout SphereIntersection i) +{ + // First intersect the sphere + raySphere(i); + // Then raymarch the heightfield + if(i.t > 0.0) + { + rayMarchSphere(i); + } +} + +void main(void) +{ + vec2 screenPos = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy; + vec2 screenPosAR = vec2(screenPos.x*(resolution.x/resolution.y),screenPos.y); + + vec3 rayDir = normalize(vec3(screenPosAR.x,screenPosAR.y,1.0)); + vec3 light = vec3(sin(time/4.0)*3.0,cos(time/5.0)*3.0,-2.0); + vec4 sphere = vec4(0.0,0.0,3.0,2.2); + + SphereIntersection inter; + inter.ro = vec3(0,0,0); + inter.rd = rayDir; + inter.sphere = sphere; + rayMarchedSphereIntersection(inter); + //raySphere(inter); + + vec3 color; + if(inter.t > 0.0) + { + float shadowFactor = 1.0; + SphereIntersection shadowInter; + vec3 lightDir = normalize(light-inter.pos); + shadowInter.ro = inter.pos; + shadowInter.rd = lightDir; + shadowInter.pos = inter.pos+lightDir*0.1; + shadowInter.sphere = sphere; + shadowInter.depth = sphere.w; + rayMarchSphere(shadowInter); + if(shadowInter.t > 0.0) + { + //shadowFactor = 0.0; + } + // Some crazy colors + vec3 diffuse = normalize(normalize(inter.pos-sphere.xyz)+vec3(abs(sin(time/4.0)),abs(cos(time/5.0)),abs(sin(time/5.0)*2.0))); + color.xyz = lighting(inter.pos, inter.normal, light, diffuse) * shadowFactor; + color.xyz += saturate(inter.normal.zzz+0.50)*diffuse; // Some fake backlighting + } + else + { + color.xyz = vec3(0,0,0); + } + + gl_FragColor.xyz = color; + gl_FragColor.w = 1.0; +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/6223.2.frag b/samples/HerokuShaders/Assets/6223.2.frag new file mode 100644 index 000000000..d435c273f --- /dev/null +++ b/samples/HerokuShaders/Assets/6223.2.frag @@ -0,0 +1,37 @@ +//http://glsl.heroku.com/e#6223.2 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + +// a raymarching experiment by kabuto +//fork by tigrou ind (2013.01.22) +//optimized + +#define MAXITER 90 +#define MAXITER_SQR MAXITER*MAXITER + +vec3 field(vec3 p) { + p = abs(fract(p)-.5); + p *= p; + return sqrt(p+p.yzx*p.zzy)-.015; +} + +void main( void ) { + vec3 dir = normalize(vec3((gl_FragCoord.xy-resolution*.5)/resolution.x,1.)); + float a = time * 0.4; + vec3 pos = vec3(time*0.6 + sin(time)*0.2,sin(time)*0.25,-3.0); + + vec3 color = vec3(0); + for (int i = 0; i < MAXITER; i++) { + vec3 f2 = field(pos); + vec3 rep = vec3(1.0,0.7+sin(time)*0.7, 1.3); + float f = min(min(min(f2.x,f2.y),f2.z), length(mod(pos-vec3(0.1),rep)-0.5*rep)-0.10); + pos += dir*f; + color += float(MAXITER-i)/(f2+.01); + } + vec3 color3 = vec3(1.-1./(1.+color*(.09/float(MAXITER_SQR)))); + color3 *= color3; + gl_FragColor = vec4(vec3(color3.r+color3.g+color3.b),1.); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/6238.frag b/samples/HerokuShaders/Assets/6238.frag new file mode 100644 index 000000000..deee719e8 --- /dev/null +++ b/samples/HerokuShaders/Assets/6238.frag @@ -0,0 +1,28 @@ +//http://glsl.heroku.com/e#6238.0 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + +void main( void ) { + + vec3 color1 = vec3(1.7, 0.25, 0.5); + vec3 color2 = vec3(0.5, 0.7, 0.25); + vec3 color3 = vec3(0.25, 0.5, 0.7); + + vec2 point1 = resolution/2.0 + vec2(sin(time*2.0) * 10.0, cos(time*2.0) * 5.0); + vec2 point2 = resolution/2.0 + vec2(sin(time)*75.0, cos(time)*50.0); + vec2 point3 = resolution/2.0 + vec2(sin(time)*25.0, sin(time*2.0)*50.0)*2.0; + + vec2 dist1 = gl_FragCoord.xy - point1; + float intensity1 = pow(32.0/(0.01+length(dist1)), 2.0); + + vec2 dist2 = gl_FragCoord.xy - point2; + float intensity2 = pow(3.0/(0.01+length(dist2)), 2.0); + + vec2 dist3 = gl_FragCoord.xy - point3; + float intensity3 = pow(62.0/(0.01+length(dist3)), 1.0); + + gl_FragColor = vec4((color1*intensity1 + color2*intensity2 + color3*intensity3)*mod(gl_FragCoord.y, 2.0),1.0); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/6284.1.frag b/samples/HerokuShaders/Assets/6284.1.frag new file mode 100644 index 000000000..4d2b4cc31 --- /dev/null +++ b/samples/HerokuShaders/Assets/6284.1.frag @@ -0,0 +1,20 @@ +//http://glsl.heroku.com/e#6284.1 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + +void main( void ) { + + vec2 position = ( gl_FragCoord.xy / resolution.xy ) + mouse / 1.0; + + float color = 0.0; + color += sin( position.x * cos( time / 15.0 ) * 80.0 ) + cos( position.y * cos( time / 15.0 ) * 10.0 ); + color += sin( position.y * sin( time / 10.0 ) * 40.0 ) + cos( position.x * sin( time / 25.0 ) * 40.0 ); + color += sin( position.x * sin( time / 5.0 ) * 10.0 ) + sin( position.y * sin( time / 35.0 ) * 80.0 ); + color *= sin( time / 10.0 ) * 0.5; + + gl_FragColor = vec4( vec3( color, color * 0.1, sin( color + time / 9.0 ) * 0.75 ), 1.0 ); + +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/6286.frag b/samples/HerokuShaders/Assets/6286.frag new file mode 100644 index 000000000..290357977 --- /dev/null +++ b/samples/HerokuShaders/Assets/6286.frag @@ -0,0 +1,23 @@ +//http://glsl.heroku.com/e#6286.0 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; +varying vec2 surfacePosition; + +void main( void ) { + vec2 p = surfacePosition; + float speed = 0.45; + vec3 color = vec3(.4,.1,.8); + vec2 loc = vec2(cos(time/1.6*speed)/1.9-cos(time/.8*speed)/3.8, + sin(time/1.6*speed)/1.9-sin(time/.8*speed)/3.8 + ); + float depth; + for(int i = 0; i < 100; i+=1){ + p = vec2(p.x*p.x-p.y*p.y,2.0*p.x*p.y)+loc; + depth = float(i); + if((p.x*p.x+p.y*p.y) >= 4.0) break; + } + gl_FragColor = vec4(clamp(color*depth*0.05, 0.0, 10.0)*mod(gl_FragCoord.y, 2.0), 1.0 ); +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/6288.1.frag b/samples/HerokuShaders/Assets/6288.1.frag new file mode 100644 index 000000000..e769404a6 --- /dev/null +++ b/samples/HerokuShaders/Assets/6288.1.frag @@ -0,0 +1,32 @@ +//http://glsl.heroku.com/e#6288.1 + + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + + +void main( void ) +{ + + vec2 uPos = ( gl_FragCoord.xy / resolution.xy );//normalize wrt y axis + //suPos -= vec2((resolution.x/resolution.y)/2.0, 0.0);//shift origin to center + + uPos.x -= 1.0; + uPos.y -= 0.5; + + vec3 color = vec3(0.0); + float vertColor = 0.0; + for( float i = 0.0; i < 15.0; ++i ) + { + float t = time * (0.9); + + uPos.y += sin( uPos.x*i + t+i/2.0 ) * 0.1; + float fTemp = abs(1.0 / uPos.y / 100.0); + vertColor += fTemp; + color += vec3( fTemp*(10.0-i)/10.0, fTemp*i/10.0, pow(fTemp,1.5)*1.5 ); + } + + vec4 color_final = vec4(color, 1.0); + gl_FragColor = color_final; +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/heroku.vert b/samples/HerokuShaders/Assets/heroku.vert new file mode 100644 index 000000000..00e20fafa --- /dev/null +++ b/samples/HerokuShaders/Assets/heroku.vert @@ -0,0 +1,11 @@ + +attribute vec3 position; +attribute vec2 surfacePosAttrib; +varying vec2 surfacePosition; + +void main() { + + surfacePosition = surfacePosAttrib; + gl_Position = vec4( position, 1.0 ); + +} \ No newline at end of file diff --git a/samples/HerokuShaders/Assets/lime.svg b/samples/HerokuShaders/Assets/lime.svg new file mode 100644 index 000000000..0e20a1c77 --- /dev/null +++ b/samples/HerokuShaders/Assets/lime.svg @@ -0,0 +1,54 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/HerokuShaders/Assets/readme.txt b/samples/HerokuShaders/Assets/readme.txt new file mode 100644 index 000000000..6d008e674 --- /dev/null +++ b/samples/HerokuShaders/Assets/readme.txt @@ -0,0 +1 @@ +These shaders are taken from http://glsl.heroku.com \ No newline at end of file diff --git a/samples/HerokuShaders/HerokuShaders.hxproj b/samples/HerokuShaders/HerokuShaders.hxproj new file mode 100644 index 000000000..2000dc231 --- /dev/null +++ b/samples/HerokuShaders/HerokuShaders.hxproj @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/HerokuShaders/Source/Main.hx b/samples/HerokuShaders/Source/Main.hx new file mode 100644 index 000000000..85c6ae2e7 --- /dev/null +++ b/samples/HerokuShaders/Source/Main.hx @@ -0,0 +1,199 @@ +package; + + +import haxe.Timer; +import lime.gl.GL; +import lime.gl.GLBuffer; +import lime.gl.GLProgram; +import lime.gl.GLShader; +import lime.gl.GLUniformLocation; +import lime.geometry.Matrix3D; +import lime.utils.Float32Array; +import lime.utils.Assets; +import lime.Lime; + + +class Main { + + + private static var fragmentShaders = [ #if mobile "6284.1", "6238", "6147.1", "5891.5", "5805.18", "5492", "5398.8" #else "6286", "6288.1", "6284.1", "6238", "6223.2", "6175", "6162", "6147.1", "6049", "6043.1", "6022", "5891.5", "5805.18", "5812", "5733", "5454.21", "5492", "5359.8", "5398.8", "4278.1" #end ]; + private static var maxTime = 7; + + private var backbufferUniform:GLUniformLocation; + private var buffer:GLBuffer; + private var currentIndex:Int; + private var currentProgram:GLProgram; + private var currentTime:Float; + private var lime:Lime; + private var mouseUniform:GLUniformLocation; + private var positionAttribute:Int; + private var resolutionUniform:GLUniformLocation; + private var startTime:Float; + private var surfaceSizeUniform:GLUniformLocation; + private var timeUniform:GLUniformLocation; + private var vertexPosition:Int; + + + public function new () {} + + + private function compile ():Void { + + var program = GL.createProgram (); + var vertex = Assets.getText ("assets/heroku.vert"); + + #if desktop + var fragment = ""; + #else + var fragment = "precision mediump float;"; + #end + + fragment += Assets.getText ("assets/" + fragmentShaders[currentIndex] + ".frag"); + + var vs = createShader (vertex, GL.VERTEX_SHADER); + var fs = createShader (fragment, GL.FRAGMENT_SHADER); + + if (vs == null || fs == null) return; + + GL.attachShader (program, vs); + GL.attachShader (program, fs); + + GL.deleteShader (vs); + GL.deleteShader (fs); + + GL.linkProgram (program); + + if (GL.getProgramParameter (program, GL.LINK_STATUS) == 0) { + + trace (GL.getProgramInfoLog (program)); + trace ("VALIDATE_STATUS: " + GL.getProgramParameter (program, GL.VALIDATE_STATUS)); + trace ("ERROR: " + GL.getError ()); + return; + + } + + if (currentProgram != null) { + + GL.deleteProgram (currentProgram); + + } + + currentProgram = program; + + positionAttribute = GL.getAttribLocation (currentProgram, "surfacePosAttrib"); + GL.enableVertexAttribArray (positionAttribute); + + vertexPosition = GL.getAttribLocation (currentProgram, "position"); + GL.enableVertexAttribArray (vertexPosition); + + timeUniform = GL.getUniformLocation (program, "time"); + mouseUniform = GL.getUniformLocation (program, "mouse"); + resolutionUniform = GL.getUniformLocation (program, "resolution"); + backbufferUniform = GL.getUniformLocation (program, "backbuffer"); + surfaceSizeUniform = GL.getUniformLocation (program, "surfaceSize"); + + startTime = Timer.stamp (); + currentTime = startTime; + + } + + + private function createShader (source:String, type:Int):GLShader { + + var shader = GL.createShader (type); + GL.shaderSource (shader, source); + GL.compileShader (shader); + + if (GL.getShaderParameter (shader, GL.COMPILE_STATUS) == 0) { + + trace (GL.getShaderInfoLog (shader)); + return null; + + } + + return shader; + + } + + + private function randomizeArray (array:Array):Array { + + var arrayCopy = array.copy (); + var randomArray = new Array (); + + while (arrayCopy.length > 0) { + + var randomIndex = Math.round (Math.random () * (arrayCopy.length - 1)); + randomArray.push (arrayCopy.splice (randomIndex, 1)[0]); + + } + + return randomArray; + + } + + + public function ready (lime:Lime) { + + this.lime = lime; + + fragmentShaders = randomizeArray (fragmentShaders); + currentIndex = 0; + + buffer = GL.createBuffer (); + GL.bindBuffer (GL.ARRAY_BUFFER, buffer); + GL.bufferData (GL.ARRAY_BUFFER, new Float32Array ([ -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0 ]), GL.STATIC_DRAW); + GL.bindBuffer (GL.ARRAY_BUFFER, null); + + compile (); + + } + + + public function render ():Void { + + if (currentProgram == null) return; + + currentTime = Timer.stamp () - startTime; + + GL.viewport (0, 0, lime.config.width, lime.config.height); + GL.useProgram (currentProgram); + + GL.uniform1f (timeUniform, currentTime); + GL.uniform2f (mouseUniform, 0.1, 0.1); //GL.uniform2f (mouseUniform, (stage.mouseX / stage.stageWidth) * 2 - 1, (stage.mouseY / stage.stageHeight) * 2 - 1); + GL.uniform2f (resolutionUniform, lime.config.width, lime.config.height); + GL.uniform1i (backbufferUniform, 0 ); + GL.uniform2f (surfaceSizeUniform, lime.config.width, lime.config.height); + + GL.bindBuffer (GL.ARRAY_BUFFER, buffer); + GL.vertexAttribPointer (positionAttribute, 2, GL.FLOAT, false, 0, 0); + GL.vertexAttribPointer (vertexPosition, 2, GL.FLOAT, false, 0, 0); + + GL.clearColor (0, 0, 0, 1); + GL.clear (GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT ); + GL.drawArrays (GL.TRIANGLES, 0, 6); + GL.bindBuffer (GL.ARRAY_BUFFER, null); + + } + + + public function update ():Void { + + if (currentTime > maxTime && fragmentShaders.length > 1) { + + currentIndex++; + + if (currentIndex > fragmentShaders.length - 1) { + + currentIndex = 0; + + } + + compile (); + + } + + } + + +} \ No newline at end of file diff --git a/samples/HerokuShaders/project.lime b/samples/HerokuShaders/project.lime new file mode 100644 index 000000000..3d89f41cd --- /dev/null +++ b/samples/HerokuShaders/project.lime @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/examples/HerokuShaders/Assets/.keep b/samples/SimpleAudioExample/Assets/.keep similarity index 100% rename from examples/HerokuShaders/Assets/.keep rename to samples/SimpleAudioExample/Assets/.keep diff --git a/samples/SimpleAudioExample/Assets/ambience.ogg b/samples/SimpleAudioExample/Assets/ambience.ogg new file mode 100644 index 000000000..58b630a9f Binary files /dev/null and b/samples/SimpleAudioExample/Assets/ambience.ogg differ diff --git a/samples/SimpleAudioExample/Assets/sound.ogg b/samples/SimpleAudioExample/Assets/sound.ogg new file mode 100644 index 000000000..3aa2730c8 Binary files /dev/null and b/samples/SimpleAudioExample/Assets/sound.ogg differ diff --git a/samples/SimpleAudioExample/Assets/sound.wav b/samples/SimpleAudioExample/Assets/sound.wav new file mode 100644 index 000000000..2544fe226 Binary files /dev/null and b/samples/SimpleAudioExample/Assets/sound.wav differ diff --git a/samples/SimpleAudioExample/Assets/sound_licenses.txt b/samples/SimpleAudioExample/Assets/sound_licenses.txt new file mode 100644 index 000000000..0cb72a80b --- /dev/null +++ b/samples/SimpleAudioExample/Assets/sound_licenses.txt @@ -0,0 +1,13 @@ +sound.ogg / sound.wav + + http://www.freesound.org/people/FreqMan/sounds/42899/ + + The files are under the following license : + This work is licensed under the Attribution License. + + See the above link for more details. + + +ambience.ogg + + https://soundcloud.com/underscorediscovery/menuambience \ No newline at end of file diff --git a/examples/SimpleOpenGL/project.lime.xml b/samples/SimpleAudioExample/project.lime.xml similarity index 66% rename from examples/SimpleOpenGL/project.lime.xml rename to samples/SimpleAudioExample/project.lime.xml index ab5a31dfd..ec91cd58e 100644 --- a/examples/SimpleOpenGL/project.lime.xml +++ b/samples/SimpleAudioExample/project.lime.xml @@ -2,13 +2,13 @@ - + diff --git a/samples/SimpleAudioExample/src/Main.hx b/samples/SimpleAudioExample/src/Main.hx new file mode 100644 index 000000000..7e2fad197 --- /dev/null +++ b/samples/SimpleAudioExample/src/Main.hx @@ -0,0 +1,107 @@ + + //Ported and modified from OpenFL samples + //underscorediscovery + +import lime.AudioHandler.Sound; +import lime.utils.Assets; +import lime.Lime; + + //Import GL stuff from lime +import lime.gl.GL; + +//Press any key to reset the music +//Click to play a sound + +class Main { + + public var lib : Lime; + + //Some value to mess with the clear color + private var red_value : Float = 1.0; + private var red_direction : Int = 1; + private var dt : Float = 0.016; + private var end_dt : Float = 0; + + public function new() { } + + public function ready( _lime : Lime ) { + + //Store a reference + lib = _lime; + + // Init the shaders and view + init(); + + } //ready + + + public function init() { + + lib.audio.create('music', 'assets/ambience.ogg', true ); + lib.audio.create('sound', 'assets/sound.ogg', false); + lib.audio.create('sound_wav', 'assets/sound.wav', false); + + lib.audio.get('music').play(5); + lib.audio.get('music').on_complete(function(sound:Sound){ + trace("music complete!"); + }); + + } //init + + //Called each frame by lime for logic (called before render) + public function update() { + + dt = haxe.Timer.stamp() - end_dt; + end_dt = haxe.Timer.stamp(); + + //an awful magic number to change the value slowly + red_value += (red_direction * 0.3) * dt; + + if(red_value >= 1) { + red_value = 1; + red_direction = -red_direction; + } else if(red_value <= 0) { + red_value = 0; + red_direction = -red_direction; + } + + } //update + + //Called by lime + public function onmousemove(_event:Dynamic) { + } + //Called by lime + public function onmousedown(_event:Dynamic) { + lib.audio.get('sound').play(3,0); + } + //Called by lime + public function onmouseup(_event:Dynamic) { + } + //Called by lime + public function onkeydown(_event:Dynamic) { + lib.audio.get('music').position = 0.0; + } + //Called by lime + public function onkeyup(_event:Dynamic) { + } + + + //Called by lime + public function render() { + + //Set the viewport for GL + GL.viewport( 0, 0, lib.config.width, lib.config.height ); + + //Set the clear color to a weird color that bounces around + GL.clearColor( red_value, red_value*0.5, red_value*0.3, 1); + //Clear the buffers + GL.clear( GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT ); + + + + } //render + + +} //Main + + diff --git a/samples/SimpleOpenGL/Assets/lime.png b/samples/SimpleOpenGL/Assets/lime.png new file mode 100644 index 000000000..5afb8060b Binary files /dev/null and b/samples/SimpleOpenGL/Assets/lime.png differ diff --git a/samples/SimpleOpenGL/Assets/lime.svg b/samples/SimpleOpenGL/Assets/lime.svg new file mode 100644 index 000000000..0e20a1c77 --- /dev/null +++ b/samples/SimpleOpenGL/Assets/lime.svg @@ -0,0 +1,54 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/SimpleOpenGL/SimpleOpenGLView.hxproj b/samples/SimpleOpenGL/SimpleOpenGLView.hxproj new file mode 100644 index 000000000..789136620 --- /dev/null +++ b/samples/SimpleOpenGL/SimpleOpenGLView.hxproj @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/SimpleOpenGL/Source/Main.hx b/samples/SimpleOpenGL/Source/Main.hx new file mode 100644 index 000000000..8bdfccbaa --- /dev/null +++ b/samples/SimpleOpenGL/Source/Main.hx @@ -0,0 +1,215 @@ +package; + + +import format.png.Reader; +import format.png.Tools; +import haxe.io.BytesInput; +import lime.gl.GL; +import lime.gl.GLBuffer; +import lime.gl.GLProgram; +import lime.gl.GLTexture; +import lime.geometry.Matrix3D; +import lime.utils.Assets; +import lime.utils.Float32Array; +import lime.utils.UInt8Array; +import lime.Lime; + + +class Main { + + + private var imageData:UInt8Array; + private var imageHeight:Int; + private var imageWidth:Int; + private var imageUniform:Int; + private var lime:Lime; + private var modelViewMatrixUniform:Int; + private var projectionMatrixUniform:Int; + private var shaderProgram:GLProgram; + private var texCoordAttribute:Int; + private var texCoordBuffer:GLBuffer; + private var texture:GLTexture; + private var vertexAttribute:Int; + private var vertexBuffer:GLBuffer; + + + public function new () {} + + + private function createBuffers ():Void { + + var vertices = [ + + imageWidth, imageHeight, 0, + 0, imageHeight, 0, + imageWidth, 0, 0, + 0, 0, 0 + + ]; + + vertexBuffer = GL.createBuffer (); + GL.bindBuffer (GL.ARRAY_BUFFER, vertexBuffer); + GL.bufferData (GL.ARRAY_BUFFER, new Float32Array (cast vertices), GL.STATIC_DRAW); + GL.bindBuffer (GL.ARRAY_BUFFER, null); + + var texCoords = [ + + 1, 1, + 0, 1, + 1, 0, + 0, 0, + + ]; + + texCoordBuffer = GL.createBuffer (); + GL.bindBuffer (GL.ARRAY_BUFFER, texCoordBuffer); + GL.bufferData (GL.ARRAY_BUFFER, new Float32Array (cast texCoords), GL.STATIC_DRAW); + GL.bindBuffer (GL.ARRAY_BUFFER, null); + + } + + + private function createTexture ():Void { + + texture = GL.createTexture (); + GL.bindTexture (GL.TEXTURE_2D, texture); + GL.texImage2D (GL.TEXTURE_2D, 0, GL.RGBA, imageHeight, imageHeight, 0, GL.RGBA, GL.UNSIGNED_BYTE, imageData); + GL.texParameteri (GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.LINEAR); + GL.texParameteri (GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR); + GL.bindTexture (GL.TEXTURE_2D, null); + + } + + + private function initializeShaders ():Void { + + var vertexShaderSource = + + "attribute vec3 aVertexPosition; + attribute vec2 aTexCoord; + varying vec2 vTexCoord; + + uniform mat4 uModelViewMatrix; + uniform mat4 uProjectionMatrix; + + void main(void) { + vTexCoord = aTexCoord; + gl_Position = uProjectionMatrix * uModelViewMatrix * vec4 (aVertexPosition, 1.0); + }"; + + var vertexShader = GL.createShader (GL.VERTEX_SHADER); + GL.shaderSource (vertexShader, vertexShaderSource); + GL.compileShader (vertexShader); + + if (GL.getShaderParameter (vertexShader, GL.COMPILE_STATUS) == 0) { + + throw "Error compiling vertex shader"; + + } + + var fragmentShaderSource = + + "varying vec2 vTexCoord; + uniform sampler2D uImage0; + + void main(void) + { + gl_FragColor = texture2D (uImage0, vTexCoord).bgra; + }"; + + var fragmentShader = GL.createShader (GL.FRAGMENT_SHADER); + GL.shaderSource (fragmentShader, fragmentShaderSource); + GL.compileShader (fragmentShader); + + if (GL.getShaderParameter (fragmentShader, GL.COMPILE_STATUS) == 0) { + + throw "Error compiling fragment shader"; + + } + + shaderProgram = GL.createProgram (); + GL.attachShader (shaderProgram, vertexShader); + GL.attachShader (shaderProgram, fragmentShader); + GL.linkProgram (shaderProgram); + + if (GL.getProgramParameter (shaderProgram, GL.LINK_STATUS) == 0) { + + throw "Unable to initialize the shader program."; + + } + + vertexAttribute = GL.getAttribLocation (shaderProgram, "aVertexPosition"); + texCoordAttribute = GL.getAttribLocation (shaderProgram, "aTexCoord"); + projectionMatrixUniform = GL.getUniformLocation (shaderProgram, "uProjectionMatrix"); + modelViewMatrixUniform = GL.getUniformLocation (shaderProgram, "uModelViewMatrix"); + imageUniform = GL.getUniformLocation (shaderProgram, "uImage0"); + + } + + + public function ready (lime:Lime):Void { + + this.lime = lime; + + var bytes = Assets.getBytes ("assets/lime.png"); + var byteInput = new BytesInput (bytes, 0, bytes.length); + var png = new Reader (byteInput).read (); + var data = Tools.extract32 (png); + var header = Tools.getHeader (png); + + imageWidth = header.width; + imageHeight = header.height; + imageData = new UInt8Array (data.getData ()); + + initializeShaders (); + + createBuffers (); + createTexture (); + + } + + + private function render ():Void { + + GL.viewport (0, 0, lime.config.width, lime.config.height); + + GL.clearColor (1.0, 1.0, 1.0, 1.0); + GL.clear (GL.COLOR_BUFFER_BIT); + + var positionX = (lime.config.width - imageWidth) / 2; + var positionY = (lime.config.height - imageHeight) / 2; + + var projectionMatrix = Matrix3D.createOrtho (0, lime.config.width, lime.config.height, 0, 1000, -1000); + var modelViewMatrix = Matrix3D.create2D (positionX, positionY, 1, 0); + + GL.useProgram (shaderProgram); + GL.enableVertexAttribArray (vertexAttribute); + GL.enableVertexAttribArray (texCoordAttribute); + + GL.activeTexture (GL.TEXTURE0); + GL.bindTexture (GL.TEXTURE_2D, texture); + GL.enable (GL.TEXTURE_2D); + + GL.bindBuffer (GL.ARRAY_BUFFER, vertexBuffer); + GL.vertexAttribPointer (vertexAttribute, 3, GL.FLOAT, false, 0, 0); + GL.bindBuffer (GL.ARRAY_BUFFER, texCoordBuffer); + GL.vertexAttribPointer (texCoordAttribute, 2, GL.FLOAT, false, 0, 0); + + GL.uniformMatrix3D (projectionMatrixUniform, false, projectionMatrix); + GL.uniformMatrix3D (modelViewMatrixUniform, false, modelViewMatrix); + GL.uniform1i (imageUniform, 0); + + GL.drawArrays (GL.TRIANGLE_STRIP, 0, 4); + + GL.bindBuffer (GL.ARRAY_BUFFER, null); + GL.disable (GL.TEXTURE_2D); + GL.bindTexture (GL.TEXTURE_2D, null); + + GL.disableVertexAttribArray (vertexAttribute); + GL.disableVertexAttribArray (texCoordAttribute); + GL.useProgram (null); + + } + + +} \ No newline at end of file diff --git a/samples/SimpleOpenGL/project.lime b/samples/SimpleOpenGL/project.lime new file mode 100644 index 000000000..a39159343 --- /dev/null +++ b/samples/SimpleOpenGL/project.lime @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/script/src/RunScript.hx b/script/src/RunScript.hx index ef8e486d6..5c1158311 100644 --- a/script/src/RunScript.hx +++ b/script/src/RunScript.hx @@ -438,12 +438,14 @@ class RunScript { if (!flags.exists ("debug")) { runCommand (path, "haxelib", [ "run", "hxlibc", buildFile, "-Dtizen" ].concat (defines)); + runCommand (path, "haxelib", [ "run", "hxlibc", buildFile, "-Dtizen", "-Dsimulator" ].concat (defines)); } if (!flags.exists ("release")) { runCommand (path, "haxelib", [ "run", "hxlibc", buildFile, "-Dtizen", "-Dfulldebug" ].concat (defines)); + runCommand (path, "haxelib", [ "run", "hxlibc", buildFile, "-Dtizen", "-Dsimulator", "-Dfulldebug" ].concat (defines)); } diff --git a/templates/haxe/ApplicationMain.hx b/templates/haxe/ApplicationMain.hx index e67791b52..b062d1c46 100644 --- a/templates/haxe/ApplicationMain.hx +++ b/templates/haxe/ApplicationMain.hx @@ -1,15 +1,15 @@ import ::APP_MAIN::; -import lime.LiME; +import lime.Lime; class ApplicationMain { public static var _main_ : ::APP_MAIN::; - public static var _lime : LiME; + public static var _lime : Lime; public static function main () { //Create the runtime - _lime = new LiME(); + _lime = new Lime(); //Create the game class, give it the runtime _main_ = new ::APP_MAIN::(); @@ -17,7 +17,7 @@ class ApplicationMain { fullscreen : ::WIN_FULLSCREEN::, resizable : ::WIN_RESIZABLE::, borderless : ::WIN_BORDERLESS::, - aliasing : ::WIN_ANTIALIASING::, + antialiasing : ::WIN_ANTIALIASING::, stencil_buffer : ::WIN_STENCIL_BUFFER::, depth_buffer : ::WIN_DEPTH_BUFFER::, vsync : ::WIN_VSYNC::, diff --git a/templates/html5/haxe/ApplicationMain.hx b/templates/html5/haxe/ApplicationMain.hx index 232f2ec2e..8ac278a34 100755 --- a/templates/html5/haxe/ApplicationMain.hx +++ b/templates/html5/haxe/ApplicationMain.hx @@ -1,7 +1,7 @@ #if lime_html5 import ::APP_MAIN_PACKAGE::::APP_MAIN_CLASS::; - import lime.LiME; + import lime.Lime; class ApplicationMain { @@ -12,13 +12,20 @@ //Create the game class, give it the runtime var _main_ = Type.createInstance (::APP_MAIN::, []); //Create an instance of lime - var _lime = new LiME(); + var _lime = new Lime(); //Create the config from the project.nmml info var config = { - width : ::WIN_WIDTH::, - height : ::WIN_HEIGHT::, - title : "::APP_TITLE::" + fullscreen : ::WIN_FULLSCREEN::, + resizable : ::WIN_RESIZABLE::, + borderless : ::WIN_BORDERLESS::, + antialiasing : ::WIN_ANTIALIASING::, + stencil_buffer : ::WIN_STENCIL_BUFFER::, + depth_buffer : ::WIN_DEPTH_BUFFER::, + vsync : ::WIN_VSYNC::, + width : ::WIN_WIDTH::, + height : ::WIN_HEIGHT::, + title : "::APP_TITLE::" }; //Start up diff --git a/templates/neko/bin/neko-linux b/templates/neko/bin/neko-linux new file mode 100644 index 000000000..02039e1d2 Binary files /dev/null and b/templates/neko/bin/neko-linux differ diff --git a/templates/neko/bin/neko-linux64 b/templates/neko/bin/neko-linux64 new file mode 100644 index 000000000..042729a3c Binary files /dev/null and b/templates/neko/bin/neko-linux64 differ diff --git a/templates/neko/bin/neko-mac b/templates/neko/bin/neko-mac new file mode 100644 index 000000000..fff2acee5 Binary files /dev/null and b/templates/neko/bin/neko-mac differ diff --git a/templates/neko/bin/neko-mac64 b/templates/neko/bin/neko-mac64 new file mode 100755 index 000000000..5c316f09a Binary files /dev/null and b/templates/neko/bin/neko-mac64 differ diff --git a/templates/neko/bin/neko-windows b/templates/neko/bin/neko-windows new file mode 100644 index 000000000..2755e6557 Binary files /dev/null and b/templates/neko/bin/neko-windows differ