diff --git a/examples/shaders/go-jetpack-clouds/README.md b/examples/shaders/go-jetpack-clouds/README.md index 2f4eb31..ac7cdac 100644 --- a/examples/shaders/go-jetpack-clouds/README.md +++ b/examples/shaders/go-jetpack-clouds/README.md @@ -1,7 +1 @@ -# Go Jetpack -by [Branson Camp](https://github.com/bcamp1) using [Pixel](https://github.com/faiface/pixel) - -Welcome to Go-Jetpack, where you explore the skies using WASD or Arrow Keys. -This example showcases most of the fundamental pixel elements described in the [Pixel Wiki](https://github.com/faiface/pixel/wiki) - -![Screenshot](https://github.com/bcamp1/pixel/blob/master/examples/community/go-jetpack/screenshot.png) +Rolling cloud effect added to the Jetpack demo. \ No newline at end of file diff --git a/examples/shaders/go-jetpack-clouds/jetpack.go.asd b/examples/shaders/go-jetpack-clouds/jetpack.go.asd deleted file mode 100644 index 3dba98d..0000000 --- a/examples/shaders/go-jetpack-clouds/jetpack.go.asd +++ /dev/null @@ -1,320 +0,0 @@ -package main - -import ( - "fmt" - "image" - "io/ioutil" - "os" - - _ "image/png" - - "github.com/faiface/pixel" - "github.com/faiface/pixel/pixelgl" - "github.com/faiface/pixel/text" - "github.com/go-gl/mathgl/mgl32" - "github.com/golang/freetype/truetype" - "golang.org/x/image/colornames" -) - -var fragmentShader = `// afl_ext @ 2016 - -#ifdef GL_ES -precision highp float; -#endif - -#extension GL_OES_standard_derivatives : enable - -#define HOW_CLOUDY 0.4 -#define SHADOW_THRESHOLD 0.2 -#define SHADOW 0.2 -#define SUBSURFACE 1.0 -#define WIND_DIRECTION 5.0 -#define TIME_SCALE 1.7 -#define SCALE 0.3 -#define ENABLE_SHAFTS - -#define iGlobalTime time -#define iMouse (mouse.xy * resolution.xy) -#define iResolution resolution - -mat2 RM = mat2(cos(WIND_DIRECTION), -sin(WIND_DIRECTION), sin(WIND_DIRECTION), cos(WIND_DIRECTION)); -uniform float time; -uniform vec2 mouse; -uniform vec2 resolution; - -float hash( float n ) -{ - return fract(sin(n)*758.5453); -} - -float noise( in vec3 x ) -{ - vec3 p = floor(x); - vec3 f = fract(x); - float n = p.x + p.y*57.0 + p.z*800.0; - float res = mix(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), - mix(mix( hash(n+800.0), hash(n+801.0),f.x), mix( hash(n+857.0), hash(n+858.0),f.x),f.y),f.z); - return res; -} - -float fbm( vec3 p ) -{ - float f = 0.0; - f += 0.50000*noise( p ); p = p*2.02; - f -= 0.25000*noise( p ); p = p*2.03; - f += 0.12500*noise( p ); p = p*3.01; - f += 0.06250*noise( p ); p = p*3.04; - f += 0.03500*noise( p ); p = p*4.01; - f += 0.01250*noise( p ); p = p*4.04; - f -= 0.00125*noise( p ); - return f/0.984375; -} - -float cloud(vec3 p) -{ - p-=fbm(vec3(p.x,p.y,0.0)*0.5)*1.25; - float a = min((fbm(p*3.0)*2.2-1.1), 0.0); - return a*a; -} - -float shadow = 1.0; - - -float clouds(vec2 p){ - float ic = cloud(vec3(p * 2.0, iGlobalTime*0.01 * TIME_SCALE)) / HOW_CLOUDY; - float init = smoothstep(0.1, 1.0, ic) * 10.0; - shadow = smoothstep(0.0, SHADOW_THRESHOLD, ic) * SHADOW + (1.0 - SHADOW); - init = (init * cloud(vec3(p * (6.0), iGlobalTime*0.01 * TIME_SCALE)) * ic); - init = (init * (cloud(vec3(p * (11.0), iGlobalTime*0.01 * TIME_SCALE))*0.5 + 0.4) * init); - return min(1.0, init); -} -uniform sampler2D bb; -float cloudslowres(vec2 p){ - return 1.0 - (texture2D(bb, p).a - 0.9) * 10.0; -} - -vec2 ratio = vec2(1.0, 1.0); - -vec4 getresult(){ - vec2 surfacePosition = ((( gl_FragCoord.xy / iResolution.xy ) * vec2(iResolution.x / iResolution.y, 1.0)) * 2.0 - 1.0)*SCALE; - vec2 position = ( surfacePosition); - vec2 sun = ((iMouse.xy/ iResolution.xy)* vec2(iResolution.x / iResolution.y, 1.0)*2.0-1.0) * SCALE; - float dst = distance(sun * ratio, position * ratio); - float suni = pow(dst + 1.0, -10.0); - float shaft =0.0; - float st = 0.05; - float w = 1.0; - vec2 dir = sun - position; - float c = clouds(position); - #ifdef ENABLE_SHAFTS - for(int i=0;i<50;i++){ - float occl = cloudslowres(clamp((gl_FragCoord.xy / iResolution.xy) + dir * st, 0.0, 1.0)); - w *= 0.99; - st *= 1.05; - shaft += max(0.0, (1.0 - occl)) * w; - } - #endif - shadow = min(1.0, shadow + suni * suni * 0.2 * SUBSURFACE); - suni *= (shaft * 0.03); - return vec4(pow(mix(vec3(shadow), pow(vec3(0.23, 0.33, 0.48), vec3(2.2)) + suni, c), vec3(1.0/2.2)), c*0.1 + 0.9); -} - -void main( void ) { - gl_FragColor = getresult().rgba; -} -` - -func loadPicture(path string) (pixel.Picture, error) { - file, err := os.Open(path) - if err != nil { - return nil, err - } - defer file.Close() - img, _, err := image.Decode(file) - if err != nil { - return nil, err - } - return pixel.PictureDataFromImage(img), nil -} - -func loadSprite(path string) (pixel.Sprite, error) { - pic, err := loadPicture(path) - if err != nil { - return *pixel.NewSprite(pic, pic.Bounds()), err - } - sprite := pixel.NewSprite(pic, pic.Bounds()) - return *sprite, nil -} - -func loadTTF(path string, size float64, origin pixel.Vec) *text.Text { - file, err := os.Open(path) - if err != nil { - panic(err) - } - defer file.Close() - - bytes, err := ioutil.ReadAll(file) - if err != nil { - panic(err) - } - - font, err := truetype.Parse(bytes) - if err != nil { - panic(err) - } - - face := truetype.NewFace(font, &truetype.Options{ - Size: size, - GlyphCacheEntries: 1, - }) - - atlas := text.NewAtlas(face, text.ASCII) - - txt := text.New(origin, atlas) - - return txt - -} - -func run() { - // Set up window configs - - b := pixel.R(0, 0, 1024, 768) - - cfg := pixelgl.WindowConfig{ // Default: 1024 x 768 - Title: "Golang Jetpack!", - Bounds: b, - VSync: true, - } - win, err := pixelgl.NewWindow(cfg) - if err != nil { - panic(err) - } - - // Importantr variables - var jetX, jetY, velX, velY, radians float64 - flipped := 1.0 - jetpackOn := false - gravity := 0.6 // Default: 0.004 - jetAcc := 0.9 // Default: 0.008 - tilt := 0.01 // Default: 0.001 - whichOn := false - onNumber := 0 - jetpackName := "jetpack.png" - camVector := win.Bounds().Center() - - bg, _ := loadSprite("sky.png") - - c := pixelgl.NewCanvas(b) - - var mouse mgl32.Vec2 - var resolution mgl32.Vec2 - var t float32 - c.BindUniform("mouse", &mouse) - c.BindUniform("resolution", &resolution) - c.BindUniform("time", &t) - c.SetFragmentShader(fragmentShader) - c.UpdateShader() - - // Tutorial Text - txt := loadTTF("intuitive.ttf", 50, pixel.V(win.Bounds().Center().X-450, win.Bounds().Center().Y-200)) - fmt.Fprintf(txt, "Explore the Skies with WASD or Arrow Keys!") - - // Game Loop - for !win.Closed() { - win.Update() - win.Clear(colornames.Green) - - // Jetpack - Controls - jetpackOn = win.Pressed(pixelgl.KeyUp) || win.Pressed(pixelgl.KeyW) - - if win.Pressed(pixelgl.KeyRight) || win.Pressed(pixelgl.KeyD) { - jetpackOn = true - flipped = -1 - radians -= tilt - velX += tilt * 30 - } else if win.Pressed(pixelgl.KeyLeft) || win.Pressed(pixelgl.KeyA) { - jetpackOn = true - flipped = 1 - radians += tilt - velX -= tilt * 30 - } else { - if velX < 0 { - radians -= tilt / 3 - velX += tilt * 10 - } else if velX > 0 { - radians += tilt / 3 - velX -= tilt * 10 - } - } - if jetY < 0 { - jetY = 0 - velY = -0.3 * velY - } - - if jetpackOn { - velY += jetAcc - whichOn = !whichOn - onNumber += 1 - if onNumber == 5 { // every 5 frames, toggle anijetMation - onNumber = 0 - if whichOn { - jetpackName = "jetpack-on.png" - } else { - jetpackName = "jetpack-on2.png" - } - } - } else { - jetpackName = "jetpack.png" - velY -= gravity - } - - // Jetpack - Rendering - jetpack, err := loadSprite(jetpackName) - if err != nil { - panic(err) - } - - positionVector := pixel.V(win.Bounds().Center().X+jetX, win.Bounds().Center().Y+jetY-372) - jetMat := pixel.IM - jetMat = jetMat.Scaled(pixel.ZV, 4) - jetMat = jetMat.Moved(positionVector) - jetMat = jetMat.ScaledXY(positionVector, pixel.V(flipped, 1)) - jetMat = jetMat.Rotated(positionVector, radians) - - jetX += velX - jetY += velY - - // Camera - camVector.X += (positionVector.X - camVector.X) * 0.2 - camVector.Y += (positionVector.Y - camVector.Y) * 0.2 - - if camVector.X > 25085 { - camVector.X = 25085 - } else if camVector.X < -14843 { - camVector.X = -14843 - } - - if camVector.Y > 22500 { - camVector.Y = 22500 - } - - cam := pixel.IM.Moved(win.Bounds().Center().Sub(camVector)) - - win.SetMatrix(cam) - - // Drawing to the screen - win.SetSmooth(true) - bg.Draw(win, pixel.IM.Moved(pixel.V(win.Bounds().Center().X, win.Bounds().Center().Y+766)).Scaled(pixel.ZV, 10)) - txt.Draw(win, pixel.IM) - win.SetSmooth(false) - c.Draw(win, pixel.IM) - jetpack.Draw(win, jetMat) - - } - -} - -func main() { - pixelgl.Run(run) -} diff --git a/examples/shaders/go-jetpack-clouds/screenshot.png b/examples/shaders/go-jetpack-clouds/screenshot.png index a41e269..61ee5b0 100644 Binary files a/examples/shaders/go-jetpack-clouds/screenshot.png and b/examples/shaders/go-jetpack-clouds/screenshot.png differ diff --git a/examples/shaders/go-jetpack-clouds2/README.md b/examples/shaders/go-jetpack-clouds2/README.md deleted file mode 100644 index 2f4eb31..0000000 --- a/examples/shaders/go-jetpack-clouds2/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Go Jetpack -by [Branson Camp](https://github.com/bcamp1) using [Pixel](https://github.com/faiface/pixel) - -Welcome to Go-Jetpack, where you explore the skies using WASD or Arrow Keys. -This example showcases most of the fundamental pixel elements described in the [Pixel Wiki](https://github.com/faiface/pixel/wiki) - -![Screenshot](https://github.com/bcamp1/pixel/blob/master/examples/community/go-jetpack/screenshot.png) diff --git a/examples/shaders/go-jetpack-clouds2/intuitive.ttf b/examples/shaders/go-jetpack-clouds2/intuitive.ttf deleted file mode 100644 index 9039d7b..0000000 Binary files a/examples/shaders/go-jetpack-clouds2/intuitive.ttf and /dev/null differ diff --git a/examples/shaders/go-jetpack-clouds2/jetpack-on.png b/examples/shaders/go-jetpack-clouds2/jetpack-on.png deleted file mode 100644 index 2df103f..0000000 Binary files a/examples/shaders/go-jetpack-clouds2/jetpack-on.png and /dev/null differ diff --git a/examples/shaders/go-jetpack-clouds2/jetpack-on2.png b/examples/shaders/go-jetpack-clouds2/jetpack-on2.png deleted file mode 100644 index 2bfb514..0000000 Binary files a/examples/shaders/go-jetpack-clouds2/jetpack-on2.png and /dev/null differ diff --git a/examples/shaders/go-jetpack-clouds2/jetpack.go b/examples/shaders/go-jetpack-clouds2/jetpack.go deleted file mode 100644 index 74f6321..0000000 --- a/examples/shaders/go-jetpack-clouds2/jetpack.go +++ /dev/null @@ -1,391 +0,0 @@ -package main - -import ( - "fmt" - "image" - "io/ioutil" - "os" - "time" - - "github.com/go-gl/mathgl/mgl32" - - _ "image/png" - - "github.com/faiface/pixel" - "github.com/faiface/pixel/imdraw" - "github.com/faiface/pixel/pixelgl" - "github.com/faiface/pixel/text" - "github.com/golang/freetype/truetype" - "golang.org/x/image/colornames" -) - -// InstallShader ... -func InstallShader(c *pixelgl.Canvas, uTime *float32, uAmt *float32, uMouse, uGopherPos *mgl32.Vec2) { - c.BindUniform("u_time", uTime) - c.BindUniform("u_mouse", uMouse) - c.BindUniform("u_gopherpos", uGopherPos) - c.BindUniform("u_amount", uAmt) - c.SetFragmentShader(cloudsFragmentShader) - c.UpdateShader() -} - -func loadPicture(path string) (pixel.Picture, error) { - file, err := os.Open(path) - if err != nil { - return nil, err - } - defer file.Close() - img, _, err := image.Decode(file) - if err != nil { - return nil, err - } - return pixel.PictureDataFromImage(img), nil -} - -func loadSprite(path string) (pixel.Sprite, error) { - pic, err := loadPicture(path) - if err != nil { - return *pixel.NewSprite(pic, pic.Bounds()), err - } - sprite := pixel.NewSprite(pic, pic.Bounds()) - return *sprite, nil -} - -func loadTTF(path string, size float64, origin pixel.Vec) *text.Text { - file, err := os.Open(path) - if err != nil { - panic(err) - } - defer file.Close() - - bytes, err := ioutil.ReadAll(file) - if err != nil { - panic(err) - } - - font, err := truetype.Parse(bytes) - if err != nil { - panic(err) - } - - face := truetype.NewFace(font, &truetype.Options{ - Size: size, - GlyphCacheEntries: 1, - }) - - atlas := text.NewAtlas(face, text.ASCII) - - txt := text.New(origin, atlas) - - return txt - -} - -func run() { - // Set up window configs - cfg := pixelgl.WindowConfig{ // Default: 1024 x 768 - Title: "Golang Jetpack!", - Bounds: pixel.R(0, 0, 1024, 768), - VSync: true, - } - win, err := pixelgl.NewWindow(cfg) - if err != nil { - panic(err) - } - - // Importantr variables - var jetX, jetY, velX, velY, radians float64 - flipped := 1.0 - jetpackOn := false - gravity := 0.6 // Default: 0.004 - jetAcc := 0.9 // Default: 0.008 - tilt := 0.01 // Default: 0.001 - whichOn := false - onNumber := 0 - jetpackOffName := "jetpack.png" - jetpackOn1Name := "jetpack-on.png" - jetpackOn2Name := "jetpack-on2.png" - camVector := win.Bounds().Center() - - var uTime, uAmt float32 - var uMouse, uGopherPos mgl32.Vec2 - - uAmt = 100 - imd := imdraw.New(nil) - imd.Color = colornames.Green - - bounds := win.Bounds() - bounds.Max = bounds.Max.ScaledXY(pixel.V(1.0, 1.0)) - - canvas := pixelgl.NewCanvas(bounds) - - InstallShader(canvas, &uTime, &uAmt, &uMouse, &uGopherPos) - - bg, _ := loadSprite("sky.png") - bg.Draw(canvas, pixel.IM) - - // Jetpack - Rendering - jetpackOff, err := loadSprite(jetpackOffName) - if err != nil { - panic(err) - } - jetpackOn1, err := loadSprite(jetpackOn1Name) - if err != nil { - panic(err) - } - jetpackOn2, err := loadSprite(jetpackOn2Name) - if err != nil { - panic(err) - } - - // Tutorial Text - txt := loadTTF("intuitive.ttf", 50, pixel.V(win.Bounds().Center().X-450, win.Bounds().Center().Y-200)) - txt.Color = colornames.Black - fmt.Fprintf(txt, "Explore the Skies with WASD or Arrow Keys!") - - currentSprite := jetpackOff - start := time.Now() - b := win.Bounds().Moved(pixel.V(0, -760)) - min := b.Min - max := b.Max - - // Game Loop - for !win.Closed() { - uTime = float32(time.Since(start).Seconds()) - mpos := win.MousePosition() - uMouse[0] = float32(mpos.X) - uMouse[1] = float32(mpos.Y) - - win.SetTitle(fmt.Sprint(uGopherPos)) - - win.Clear(colornames.Green) - - // Jetpack - Controls - jetpackOn = win.Pressed(pixelgl.KeyUp) || win.Pressed(pixelgl.KeyW) - - if win.Pressed(pixelgl.KeyRight) || win.Pressed(pixelgl.KeyD) { - jetpackOn = true - flipped = -1 - radians -= tilt - velX += tilt * 30 - } else if win.Pressed(pixelgl.KeyLeft) || win.Pressed(pixelgl.KeyA) { - jetpackOn = true - flipped = 1 - radians += tilt - velX -= tilt * 30 - } else { - if velX < 0 { - radians -= tilt / 3 - velX += tilt * 10 - } else if velX > 0 { - radians += tilt / 3 - velX -= tilt * 10 - } - } - if jetY < 0 { - jetY = 0 - velY = -0.3 * velY - } - - if jetpackOn { - velY += jetAcc - whichOn = !whichOn - onNumber++ - if onNumber == 5 { // every 5 frames, toggle anijetMation - onNumber = 0 - if whichOn { - currentSprite = jetpackOn1 - } else { - currentSprite = jetpackOn2 - } - } - } else { - currentSprite = jetpackOff - velY -= gravity - } - - if win.Pressed(pixelgl.KeyEqual) { - uAmt++ - } - if win.Pressed(pixelgl.KeyMinus) { - uAmt-- - } - - positionVector := pixel.V(win.Bounds().Center().X+jetX, win.Bounds().Center().Y+jetY-372) - jetMat := pixel.IM - jetMat = jetMat.Scaled(pixel.ZV, 4) - jetMat = jetMat.Moved(positionVector) - jetMat = jetMat.ScaledXY(positionVector, pixel.V(flipped, 1)) - jetMat = jetMat.Rotated(positionVector, radians) - - jetX += velX - jetY += velY - uGopherPos[0] = float32(jetX*0.00001 + 1.0) - uGopherPos[1] = float32(jetY*0.00001 + 1.0) - // Camera - camVector.X += (positionVector.X - camVector.X) * 0.2 - camVector.Y += (positionVector.Y - camVector.Y) * 0.2 - - if camVector.X > 25085 { - camVector.X = 25085 - } else if camVector.X < -14843 { - camVector.X = -14843 - } - - if camVector.Y > 22500 { - camVector.Y = 22500 - } - - cam := pixel.IM.Moved(win.Bounds().Center().Sub(camVector)) - - win.SetMatrix(cam) - - // Drawing to the screen - win.SetSmooth(true) - - //bg.Draw(canvas, pixel.IM.Moved(pixel.V(win.Bounds().Center().X, win.Bounds().Center().Y+766))) - bg.Draw(canvas, pixel.IM) - - canvas.Draw(win, pixel.IM.Moved(camVector)) - imd.Clear() - imd.Push( - min.Sub(pixel.V(camVector.X, 0)), - max.Add(pixel.V(camVector.X, 0)), - ) - imd.Rectangle(0) - imd.Draw(win) - txt.Draw(win, pixel.IM) - win.SetSmooth(false) - currentSprite.Draw(win, jetMat) - - win.Update() - } - -} - -func main() { - pixelgl.Run(run) -} - -var cloudsFragmentShader = ` -#version 330 core - -#ifdef GL_ES -precision highp float; -#endif - -#define HOW_CLOUDY 0.2 -#define SHADOW_THRESHOLD 0.4 -#define SHADOW 0.3 -#define SUBSURFACE 1.0 -#define WIND_DIRECTION 0.3 -#define TIME_SCALE 0.6 -#define SCALE 0.1 -//#define ENABLE_SHAFTS -in vec2 texcoords; -out vec4 fragColor; -mat2 RM = mat2(cos(WIND_DIRECTION), -sin(WIND_DIRECTION), sin(WIND_DIRECTION), cos(WIND_DIRECTION)); -uniform float u_time; -uniform vec2 u_mouse; -//uniform vec2 u_resolution; -uniform vec4 u_texbounds; -uniform sampler2D u_texture; -uniform vec2 u_gopherpos; -uniform float u_amount; - -float hash( float n ) -{ - return fract(sin(n)*758.5453); -} - -float noise( in vec3 x ) -{ - vec3 p = floor(x); - vec3 f = fract(x); - float n = p.x + p.y*57.0 + p.z*800.0; - float res = mix(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), - mix(mix( hash(n+800.0), hash(n+801.0),f.x), mix( hash(n+857.0), hash(n+858.0),f.x),f.y),f.z); - return res; -} - -float fbm( vec3 p ) -{ - float f = 0.0; - f += 0.50000*noise( p ); p = p*2.02; - f -= 0.25000*noise( p ); p = p*2.03; - f += 0.12500*noise( p ); p = p*3.01; - f += 0.06250*noise( p ); p = p*3.04; - f += 0.03500*noise( p ); p = p*4.01; - f += 0.01250*noise( p ); p = p*4.04; - f -= 0.00125*noise( p ); - return f/0.784375; -} - -float cloud(vec3 p) -{ - p-=fbm(vec3(p.x,p.y,0.0)*0.5)*1.25; - float a = min((fbm(p*3.0)*2.2-1.1), 0.0); - return a*a; -} - -float shadow = 1.0; - - -float clouds(vec2 p){ - float ic = cloud(vec3(p * 2.0, u_time*0.01 * TIME_SCALE)) / HOW_CLOUDY; - float init = smoothstep(0.1, 1.0, ic) * 5.0; - shadow = smoothstep(0.0, SHADOW_THRESHOLD, ic) * SHADOW + (1.0 - SHADOW); - init = (init * cloud(vec3(p * (6.0), u_time*0.01 * TIME_SCALE)) * ic); - init = (init * (cloud(vec3(p * (11.0), u_time*0.01 * TIME_SCALE))*0.5 + 0.4) * init); - return min(1.0, init); -} -//uniform sampler2D bb; -float cloudslowres(vec2 p){ - return 1.0 - (texture(u_texture, p).a - 0.9) * 10.0; -} - -vec2 ratio = vec2(1.0, 1.0); - -vec4 getresult(){ - vec2 uvmouse = (u_mouse/(texcoords - u_texbounds.xy)); - vec2 t = (texcoords - u_texbounds.xy) / u_texbounds.zw; - //vec2 surfacePosition = ((( t ) * vec2(u_gopherpos.x , u_gopherpos.y)) * 2.0 - 1.0)*SCALE; - vec2 surfacePosition = t+u_gopherpos*10.0; - vec2 position = ( surfacePosition * SCALE); - vec2 sun = (uvmouse.xy * vec2(texcoords.x / texcoords.y, 1.0)*2.0-1.0) * SCALE; - - float dst = distance(sun * ratio, position * ratio); - float suni = pow(dst + 1.0, -10.0); - float shaft =0.0; - float st = 0.05; - float w = 1.0; - vec2 dir = sun - position; - float c = clouds(position); - #ifdef ENABLE_SHAFTS - for(int i=0;i<50;i++){ - float occl = cloudslowres(clamp((t) + dir * st, 0.0, 1.0)); - w *= 0.99; - st *= 1.05; - shaft += max(0.0, (1.0 - occl)) * w; - } - #endif - shadow = min(1.0, shadow + suni * suni * 0.2 * SUBSURFACE); - suni *= (shaft * 0.03); - return vec4(pow(mix(vec3(shadow), pow(vec3(0.23, 0.33, 0.48), vec3(2.2)) + suni, c), vec3(1.0/2.2)), c*0.1 + 0.9); -} -uniform sampler2D backbuffer; -void main( void ) { - - fragColor = getresult().rgba; - - vec2 t = (texcoords - u_texbounds.xy) / u_texbounds.zw; - float d = 1.0 / u_amount; - float ar = (t.y / t.x) * (u_gopherpos.y * 10); - float u = floor( t.x / d ) * d; - d = ar / u_amount; - float v = floor( t.y / d ) * d; - fragColor *= texture( backbuffer, vec2(u,v) ); - - -} -` diff --git a/examples/shaders/go-jetpack-clouds2/jetpack.go.asd b/examples/shaders/go-jetpack-clouds2/jetpack.go.asd deleted file mode 100644 index 3dba98d..0000000 --- a/examples/shaders/go-jetpack-clouds2/jetpack.go.asd +++ /dev/null @@ -1,320 +0,0 @@ -package main - -import ( - "fmt" - "image" - "io/ioutil" - "os" - - _ "image/png" - - "github.com/faiface/pixel" - "github.com/faiface/pixel/pixelgl" - "github.com/faiface/pixel/text" - "github.com/go-gl/mathgl/mgl32" - "github.com/golang/freetype/truetype" - "golang.org/x/image/colornames" -) - -var fragmentShader = `// afl_ext @ 2016 - -#ifdef GL_ES -precision highp float; -#endif - -#extension GL_OES_standard_derivatives : enable - -#define HOW_CLOUDY 0.4 -#define SHADOW_THRESHOLD 0.2 -#define SHADOW 0.2 -#define SUBSURFACE 1.0 -#define WIND_DIRECTION 5.0 -#define TIME_SCALE 1.7 -#define SCALE 0.3 -#define ENABLE_SHAFTS - -#define iGlobalTime time -#define iMouse (mouse.xy * resolution.xy) -#define iResolution resolution - -mat2 RM = mat2(cos(WIND_DIRECTION), -sin(WIND_DIRECTION), sin(WIND_DIRECTION), cos(WIND_DIRECTION)); -uniform float time; -uniform vec2 mouse; -uniform vec2 resolution; - -float hash( float n ) -{ - return fract(sin(n)*758.5453); -} - -float noise( in vec3 x ) -{ - vec3 p = floor(x); - vec3 f = fract(x); - float n = p.x + p.y*57.0 + p.z*800.0; - float res = mix(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), - mix(mix( hash(n+800.0), hash(n+801.0),f.x), mix( hash(n+857.0), hash(n+858.0),f.x),f.y),f.z); - return res; -} - -float fbm( vec3 p ) -{ - float f = 0.0; - f += 0.50000*noise( p ); p = p*2.02; - f -= 0.25000*noise( p ); p = p*2.03; - f += 0.12500*noise( p ); p = p*3.01; - f += 0.06250*noise( p ); p = p*3.04; - f += 0.03500*noise( p ); p = p*4.01; - f += 0.01250*noise( p ); p = p*4.04; - f -= 0.00125*noise( p ); - return f/0.984375; -} - -float cloud(vec3 p) -{ - p-=fbm(vec3(p.x,p.y,0.0)*0.5)*1.25; - float a = min((fbm(p*3.0)*2.2-1.1), 0.0); - return a*a; -} - -float shadow = 1.0; - - -float clouds(vec2 p){ - float ic = cloud(vec3(p * 2.0, iGlobalTime*0.01 * TIME_SCALE)) / HOW_CLOUDY; - float init = smoothstep(0.1, 1.0, ic) * 10.0; - shadow = smoothstep(0.0, SHADOW_THRESHOLD, ic) * SHADOW + (1.0 - SHADOW); - init = (init * cloud(vec3(p * (6.0), iGlobalTime*0.01 * TIME_SCALE)) * ic); - init = (init * (cloud(vec3(p * (11.0), iGlobalTime*0.01 * TIME_SCALE))*0.5 + 0.4) * init); - return min(1.0, init); -} -uniform sampler2D bb; -float cloudslowres(vec2 p){ - return 1.0 - (texture2D(bb, p).a - 0.9) * 10.0; -} - -vec2 ratio = vec2(1.0, 1.0); - -vec4 getresult(){ - vec2 surfacePosition = ((( gl_FragCoord.xy / iResolution.xy ) * vec2(iResolution.x / iResolution.y, 1.0)) * 2.0 - 1.0)*SCALE; - vec2 position = ( surfacePosition); - vec2 sun = ((iMouse.xy/ iResolution.xy)* vec2(iResolution.x / iResolution.y, 1.0)*2.0-1.0) * SCALE; - float dst = distance(sun * ratio, position * ratio); - float suni = pow(dst + 1.0, -10.0); - float shaft =0.0; - float st = 0.05; - float w = 1.0; - vec2 dir = sun - position; - float c = clouds(position); - #ifdef ENABLE_SHAFTS - for(int i=0;i<50;i++){ - float occl = cloudslowres(clamp((gl_FragCoord.xy / iResolution.xy) + dir * st, 0.0, 1.0)); - w *= 0.99; - st *= 1.05; - shaft += max(0.0, (1.0 - occl)) * w; - } - #endif - shadow = min(1.0, shadow + suni * suni * 0.2 * SUBSURFACE); - suni *= (shaft * 0.03); - return vec4(pow(mix(vec3(shadow), pow(vec3(0.23, 0.33, 0.48), vec3(2.2)) + suni, c), vec3(1.0/2.2)), c*0.1 + 0.9); -} - -void main( void ) { - gl_FragColor = getresult().rgba; -} -` - -func loadPicture(path string) (pixel.Picture, error) { - file, err := os.Open(path) - if err != nil { - return nil, err - } - defer file.Close() - img, _, err := image.Decode(file) - if err != nil { - return nil, err - } - return pixel.PictureDataFromImage(img), nil -} - -func loadSprite(path string) (pixel.Sprite, error) { - pic, err := loadPicture(path) - if err != nil { - return *pixel.NewSprite(pic, pic.Bounds()), err - } - sprite := pixel.NewSprite(pic, pic.Bounds()) - return *sprite, nil -} - -func loadTTF(path string, size float64, origin pixel.Vec) *text.Text { - file, err := os.Open(path) - if err != nil { - panic(err) - } - defer file.Close() - - bytes, err := ioutil.ReadAll(file) - if err != nil { - panic(err) - } - - font, err := truetype.Parse(bytes) - if err != nil { - panic(err) - } - - face := truetype.NewFace(font, &truetype.Options{ - Size: size, - GlyphCacheEntries: 1, - }) - - atlas := text.NewAtlas(face, text.ASCII) - - txt := text.New(origin, atlas) - - return txt - -} - -func run() { - // Set up window configs - - b := pixel.R(0, 0, 1024, 768) - - cfg := pixelgl.WindowConfig{ // Default: 1024 x 768 - Title: "Golang Jetpack!", - Bounds: b, - VSync: true, - } - win, err := pixelgl.NewWindow(cfg) - if err != nil { - panic(err) - } - - // Importantr variables - var jetX, jetY, velX, velY, radians float64 - flipped := 1.0 - jetpackOn := false - gravity := 0.6 // Default: 0.004 - jetAcc := 0.9 // Default: 0.008 - tilt := 0.01 // Default: 0.001 - whichOn := false - onNumber := 0 - jetpackName := "jetpack.png" - camVector := win.Bounds().Center() - - bg, _ := loadSprite("sky.png") - - c := pixelgl.NewCanvas(b) - - var mouse mgl32.Vec2 - var resolution mgl32.Vec2 - var t float32 - c.BindUniform("mouse", &mouse) - c.BindUniform("resolution", &resolution) - c.BindUniform("time", &t) - c.SetFragmentShader(fragmentShader) - c.UpdateShader() - - // Tutorial Text - txt := loadTTF("intuitive.ttf", 50, pixel.V(win.Bounds().Center().X-450, win.Bounds().Center().Y-200)) - fmt.Fprintf(txt, "Explore the Skies with WASD or Arrow Keys!") - - // Game Loop - for !win.Closed() { - win.Update() - win.Clear(colornames.Green) - - // Jetpack - Controls - jetpackOn = win.Pressed(pixelgl.KeyUp) || win.Pressed(pixelgl.KeyW) - - if win.Pressed(pixelgl.KeyRight) || win.Pressed(pixelgl.KeyD) { - jetpackOn = true - flipped = -1 - radians -= tilt - velX += tilt * 30 - } else if win.Pressed(pixelgl.KeyLeft) || win.Pressed(pixelgl.KeyA) { - jetpackOn = true - flipped = 1 - radians += tilt - velX -= tilt * 30 - } else { - if velX < 0 { - radians -= tilt / 3 - velX += tilt * 10 - } else if velX > 0 { - radians += tilt / 3 - velX -= tilt * 10 - } - } - if jetY < 0 { - jetY = 0 - velY = -0.3 * velY - } - - if jetpackOn { - velY += jetAcc - whichOn = !whichOn - onNumber += 1 - if onNumber == 5 { // every 5 frames, toggle anijetMation - onNumber = 0 - if whichOn { - jetpackName = "jetpack-on.png" - } else { - jetpackName = "jetpack-on2.png" - } - } - } else { - jetpackName = "jetpack.png" - velY -= gravity - } - - // Jetpack - Rendering - jetpack, err := loadSprite(jetpackName) - if err != nil { - panic(err) - } - - positionVector := pixel.V(win.Bounds().Center().X+jetX, win.Bounds().Center().Y+jetY-372) - jetMat := pixel.IM - jetMat = jetMat.Scaled(pixel.ZV, 4) - jetMat = jetMat.Moved(positionVector) - jetMat = jetMat.ScaledXY(positionVector, pixel.V(flipped, 1)) - jetMat = jetMat.Rotated(positionVector, radians) - - jetX += velX - jetY += velY - - // Camera - camVector.X += (positionVector.X - camVector.X) * 0.2 - camVector.Y += (positionVector.Y - camVector.Y) * 0.2 - - if camVector.X > 25085 { - camVector.X = 25085 - } else if camVector.X < -14843 { - camVector.X = -14843 - } - - if camVector.Y > 22500 { - camVector.Y = 22500 - } - - cam := pixel.IM.Moved(win.Bounds().Center().Sub(camVector)) - - win.SetMatrix(cam) - - // Drawing to the screen - win.SetSmooth(true) - bg.Draw(win, pixel.IM.Moved(pixel.V(win.Bounds().Center().X, win.Bounds().Center().Y+766)).Scaled(pixel.ZV, 10)) - txt.Draw(win, pixel.IM) - win.SetSmooth(false) - c.Draw(win, pixel.IM) - jetpack.Draw(win, jetMat) - - } - -} - -func main() { - pixelgl.Run(run) -} diff --git a/examples/shaders/go-jetpack-clouds2/jetpack.png b/examples/shaders/go-jetpack-clouds2/jetpack.png deleted file mode 100644 index 4ea39e0..0000000 Binary files a/examples/shaders/go-jetpack-clouds2/jetpack.png and /dev/null differ diff --git a/examples/shaders/go-jetpack-clouds2/screenshot.png b/examples/shaders/go-jetpack-clouds2/screenshot.png deleted file mode 100644 index a41e269..0000000 Binary files a/examples/shaders/go-jetpack-clouds2/screenshot.png and /dev/null differ diff --git a/examples/shaders/go-jetpack-clouds2/sky.png b/examples/shaders/go-jetpack-clouds2/sky.png deleted file mode 100644 index ab5fa36..0000000 Binary files a/examples/shaders/go-jetpack-clouds2/sky.png and /dev/null differ diff --git a/examples/shaders/go-jetpack-pixelate/README.md b/examples/shaders/go-jetpack-pixelate/README.md index 2f4eb31..a6df6a5 100644 --- a/examples/shaders/go-jetpack-pixelate/README.md +++ b/examples/shaders/go-jetpack-pixelate/README.md @@ -1,7 +1 @@ -# Go Jetpack -by [Branson Camp](https://github.com/bcamp1) using [Pixel](https://github.com/faiface/pixel) - -Welcome to Go-Jetpack, where you explore the skies using WASD or Arrow Keys. -This example showcases most of the fundamental pixel elements described in the [Pixel Wiki](https://github.com/faiface/pixel/wiki) - -![Screenshot](https://github.com/bcamp1/pixel/blob/master/examples/community/go-jetpack/screenshot.png) +A pixelating shader on top of the Jetpack demo. Use the -/+ keys to change the strength! \ No newline at end of file diff --git a/examples/shaders/go-jetpack-pixelate/jetpack.go b/examples/shaders/go-jetpack-pixelate/jetpack.go index 2b15c40..180562c 100644 --- a/examples/shaders/go-jetpack-pixelate/jetpack.go +++ b/examples/shaders/go-jetpack-pixelate/jetpack.go @@ -6,6 +6,8 @@ import ( "io/ioutil" "os" + "github.com/go-gl/mathgl/mgl32" + _ "image/png" "github.com/faiface/pixel" @@ -16,8 +18,11 @@ import ( ) // InstallShader ... -func InstallShader(w *pixelgl.Window) { +func InstallShader(w *pixelgl.Window, uAmount *float32, uResolution, uMouse *mgl32.Vec2) { wc := w.GetCanvas() + wc.BindUniform("u_resolution", uResolution) + wc.BindUniform("u_mouse", uMouse) + wc.BindUniform("u_amount", uAmount) wc.SetFragmentShader(pixelateFragShader) wc.UpdateShader() } @@ -100,7 +105,10 @@ func run() { jetpackOn2Name := "jetpack-on2.png" camVector := win.Bounds().Center() - InstallShader(win) + var uAmount float32 + var uMouse, uResolution mgl32.Vec2 + + InstallShader(win, &uAmount, &uResolution, &uMouse) bg, _ := loadSprite("sky.png") @@ -124,10 +132,19 @@ func run() { currentSprite := jetpackOff + canvas := pixelgl.NewCanvas(win.Bounds()) + uResolution[0] = float32(win.Bounds().W()) + uResolution[1] = float32(win.Bounds().H()) + uAmount = 300.0 // Game Loop for !win.Closed() { - win.Update() - win.Clear(colornames.Green) + + mpos := win.MousePosition() + uMouse[0] = float32(mpos.X) + uMouse[1] = float32(mpos.Y) + win.SetTitle(fmt.Sprint(uAmount)) + win.Clear(colornames.Blue) + canvas.Clear(colornames.Green) // Jetpack - Controls jetpackOn = win.Pressed(pixelgl.KeyUp) || win.Pressed(pixelgl.KeyW) @@ -173,6 +190,13 @@ func run() { velY -= gravity } + if win.Pressed(pixelgl.KeyEqual) { + uAmount += 10 + } + if win.Pressed(pixelgl.KeyMinus) { + uAmount -= 10 + } + positionVector := pixel.V(win.Bounds().Center().X+jetX, win.Bounds().Center().Y+jetY-372) jetMat := pixel.IM jetMat = jetMat.Scaled(pixel.ZV, 4) @@ -199,15 +223,16 @@ func run() { cam := pixel.IM.Moved(win.Bounds().Center().Sub(camVector)) - win.SetMatrix(cam) + canvas.SetMatrix(cam) // Drawing to the screen win.SetSmooth(true) - bg.Draw(win, pixel.IM.Moved(pixel.V(win.Bounds().Center().X, win.Bounds().Center().Y+766)).Scaled(pixel.ZV, 10)) - txt.Draw(win, pixel.IM) + bg.Draw(canvas, pixel.IM.Moved(pixel.V(win.Bounds().Center().X, win.Bounds().Center().Y+766)).Scaled(pixel.ZV, 10)) + txt.Draw(canvas, pixel.IM) win.SetSmooth(false) - currentSprite.Draw(win, jetMat) - + currentSprite.Draw(canvas, jetMat) + canvas.Draw(win, pixel.IM.Moved(win.Bounds().Center())) + win.Update() } } @@ -222,28 +247,60 @@ var pixelateFragShader = ` precision mediump float; precision mediump int; #endif + in vec4 Color; in vec2 texcoords; -in float Intensity; +in vec2 glpos; + out vec4 fragColor; + uniform vec4 u_colormask; uniform vec4 u_texbounds; uniform sampler2D u_texture; -// varying vec4 vertTexCoord; -// uniform sampler2D texture; -// uniform vec2 pixels; +uniform float u_amount; +uniform vec2 u_mouse; +uniform vec2 u_resolution; + void main(void) { - fragColor = vec4(0, 0, 0, 0); - fragColor += (1 - Intensity) * Color; vec2 t = (texcoords - u_texbounds.xy) / u_texbounds.zw; - fragColor += Intensity * Color * texture(u_texture, t); - fragColor *= u_colormask; - vec2 p = t.st; - p.x -= mod(texcoords.x, 1.0 / gl_FragCoord.x); - p.y -= mod(texcoords.y, 1.0 / gl_FragCoord.y); - - fragColor = texture(u_texture, p).rgba; + float d = 1.0 / u_amount; + float ar = u_resolution.x / u_resolution.y; + float u = floor( t.x / d ) * d; + d = ar / u_amount; + float v = floor( t.y / d ) * d; + fragColor = texture( u_texture, vec2( u, v ) ); } ` + +/* + //fragColor = vec4(1.0,0.0,0.0,1.0); + // float d = 1.0 / u_amount; + // float ar = u_resolution.x / u_resolution.y; + // float u = floor( texcoords.x / d ) * d; + // d = ar / u_amount; + // float v = floor( texcoords.y / d ) * d; + // fragColor = texture( u_texture, vec2( u, v ) ); + + // vec2 p = t.st; + // p.x -= mod(t.x / glpos.x, t.x / glpos.x + 0.1); + // p.y -= mod(t.y / glpos.y, t.y / glpos.y + 0.1); + + // fragColor = texture(u_texture, p).rgba; +*/ +// varying vec2 vUv; +// uniform sampler2D tInput; +// uniform vec2 resolution; +// uniform float amount; + +// void main() { + +// float d = 1.0 / amount; +// float ar = resolution.x / resolution.y; +// float u = floor( vUv.x / d ) * d; +// d = ar / amount; +// float v = floor( vUv.y / d ) * d; +// gl_FragColor = texture2D( tInput, vec2( u, v ) ); + +// } diff --git a/examples/shaders/go-jetpack-pixelate/screenshot.png b/examples/shaders/go-jetpack-pixelate/screenshot.png index a41e269..e33912c 100644 Binary files a/examples/shaders/go-jetpack-pixelate/screenshot.png and b/examples/shaders/go-jetpack-pixelate/screenshot.png differ diff --git a/examples/shaders/go-jetpack-pixelate2/README.md b/examples/shaders/go-jetpack-pixelate2/README.md deleted file mode 100644 index 2f4eb31..0000000 --- a/examples/shaders/go-jetpack-pixelate2/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Go Jetpack -by [Branson Camp](https://github.com/bcamp1) using [Pixel](https://github.com/faiface/pixel) - -Welcome to Go-Jetpack, where you explore the skies using WASD or Arrow Keys. -This example showcases most of the fundamental pixel elements described in the [Pixel Wiki](https://github.com/faiface/pixel/wiki) - -![Screenshot](https://github.com/bcamp1/pixel/blob/master/examples/community/go-jetpack/screenshot.png) diff --git a/examples/shaders/go-jetpack-pixelate2/intuitive.ttf b/examples/shaders/go-jetpack-pixelate2/intuitive.ttf deleted file mode 100644 index 9039d7b..0000000 Binary files a/examples/shaders/go-jetpack-pixelate2/intuitive.ttf and /dev/null differ diff --git a/examples/shaders/go-jetpack-pixelate2/jetpack-on.png b/examples/shaders/go-jetpack-pixelate2/jetpack-on.png deleted file mode 100644 index 2df103f..0000000 Binary files a/examples/shaders/go-jetpack-pixelate2/jetpack-on.png and /dev/null differ diff --git a/examples/shaders/go-jetpack-pixelate2/jetpack-on2.png b/examples/shaders/go-jetpack-pixelate2/jetpack-on2.png deleted file mode 100644 index 2bfb514..0000000 Binary files a/examples/shaders/go-jetpack-pixelate2/jetpack-on2.png and /dev/null differ diff --git a/examples/shaders/go-jetpack-pixelate2/jetpack.go b/examples/shaders/go-jetpack-pixelate2/jetpack.go deleted file mode 100644 index 180562c..0000000 --- a/examples/shaders/go-jetpack-pixelate2/jetpack.go +++ /dev/null @@ -1,306 +0,0 @@ -package main - -import ( - "fmt" - "image" - "io/ioutil" - "os" - - "github.com/go-gl/mathgl/mgl32" - - _ "image/png" - - "github.com/faiface/pixel" - "github.com/faiface/pixel/pixelgl" - "github.com/faiface/pixel/text" - "github.com/golang/freetype/truetype" - "golang.org/x/image/colornames" -) - -// InstallShader ... -func InstallShader(w *pixelgl.Window, uAmount *float32, uResolution, uMouse *mgl32.Vec2) { - wc := w.GetCanvas() - wc.BindUniform("u_resolution", uResolution) - wc.BindUniform("u_mouse", uMouse) - wc.BindUniform("u_amount", uAmount) - wc.SetFragmentShader(pixelateFragShader) - wc.UpdateShader() -} - -func loadPicture(path string) (pixel.Picture, error) { - file, err := os.Open(path) - if err != nil { - return nil, err - } - defer file.Close() - img, _, err := image.Decode(file) - if err != nil { - return nil, err - } - return pixel.PictureDataFromImage(img), nil -} - -func loadSprite(path string) (pixel.Sprite, error) { - pic, err := loadPicture(path) - if err != nil { - return *pixel.NewSprite(pic, pic.Bounds()), err - } - sprite := pixel.NewSprite(pic, pic.Bounds()) - return *sprite, nil -} - -func loadTTF(path string, size float64, origin pixel.Vec) *text.Text { - file, err := os.Open(path) - if err != nil { - panic(err) - } - defer file.Close() - - bytes, err := ioutil.ReadAll(file) - if err != nil { - panic(err) - } - - font, err := truetype.Parse(bytes) - if err != nil { - panic(err) - } - - face := truetype.NewFace(font, &truetype.Options{ - Size: size, - GlyphCacheEntries: 1, - }) - - atlas := text.NewAtlas(face, text.ASCII) - - txt := text.New(origin, atlas) - - return txt - -} - -func run() { - // Set up window configs - cfg := pixelgl.WindowConfig{ // Default: 1024 x 768 - Title: "Golang Jetpack!", - Bounds: pixel.R(0, 0, 1024, 768), - VSync: true, - } - win, err := pixelgl.NewWindow(cfg) - if err != nil { - panic(err) - } - - // Importantr variables - var jetX, jetY, velX, velY, radians float64 - flipped := 1.0 - jetpackOn := false - gravity := 0.6 // Default: 0.004 - jetAcc := 0.9 // Default: 0.008 - tilt := 0.01 // Default: 0.001 - whichOn := false - onNumber := 0 - jetpackOffName := "jetpack.png" - jetpackOn1Name := "jetpack-on.png" - jetpackOn2Name := "jetpack-on2.png" - camVector := win.Bounds().Center() - - var uAmount float32 - var uMouse, uResolution mgl32.Vec2 - - InstallShader(win, &uAmount, &uResolution, &uMouse) - - bg, _ := loadSprite("sky.png") - - // Jetpack - Rendering - jetpackOff, err := loadSprite(jetpackOffName) - if err != nil { - panic(err) - } - jetpackOn1, err := loadSprite(jetpackOn1Name) - if err != nil { - panic(err) - } - jetpackOn2, err := loadSprite(jetpackOn2Name) - if err != nil { - panic(err) - } - - // Tutorial Text - txt := loadTTF("intuitive.ttf", 50, pixel.V(win.Bounds().Center().X-450, win.Bounds().Center().Y-200)) - fmt.Fprintf(txt, "Explore the Skies with WASD or Arrow Keys!") - - currentSprite := jetpackOff - - canvas := pixelgl.NewCanvas(win.Bounds()) - uResolution[0] = float32(win.Bounds().W()) - uResolution[1] = float32(win.Bounds().H()) - uAmount = 300.0 - // Game Loop - for !win.Closed() { - - mpos := win.MousePosition() - uMouse[0] = float32(mpos.X) - uMouse[1] = float32(mpos.Y) - win.SetTitle(fmt.Sprint(uAmount)) - win.Clear(colornames.Blue) - canvas.Clear(colornames.Green) - - // Jetpack - Controls - jetpackOn = win.Pressed(pixelgl.KeyUp) || win.Pressed(pixelgl.KeyW) - - if win.Pressed(pixelgl.KeyRight) || win.Pressed(pixelgl.KeyD) { - jetpackOn = true - flipped = -1 - radians -= tilt - velX += tilt * 30 - } else if win.Pressed(pixelgl.KeyLeft) || win.Pressed(pixelgl.KeyA) { - jetpackOn = true - flipped = 1 - radians += tilt - velX -= tilt * 30 - } else { - if velX < 0 { - radians -= tilt / 3 - velX += tilt * 10 - } else if velX > 0 { - radians += tilt / 3 - velX -= tilt * 10 - } - } - if jetY < 0 { - jetY = 0 - velY = -0.3 * velY - } - - if jetpackOn { - velY += jetAcc - whichOn = !whichOn - onNumber++ - if onNumber == 5 { // every 5 frames, toggle anijetMation - onNumber = 0 - if whichOn { - currentSprite = jetpackOn1 - } else { - currentSprite = jetpackOn2 - } - } - } else { - currentSprite = jetpackOff - velY -= gravity - } - - if win.Pressed(pixelgl.KeyEqual) { - uAmount += 10 - } - if win.Pressed(pixelgl.KeyMinus) { - uAmount -= 10 - } - - positionVector := pixel.V(win.Bounds().Center().X+jetX, win.Bounds().Center().Y+jetY-372) - jetMat := pixel.IM - jetMat = jetMat.Scaled(pixel.ZV, 4) - jetMat = jetMat.Moved(positionVector) - jetMat = jetMat.ScaledXY(positionVector, pixel.V(flipped, 1)) - jetMat = jetMat.Rotated(positionVector, radians) - - jetX += velX - jetY += velY - - // Camera - camVector.X += (positionVector.X - camVector.X) * 0.2 - camVector.Y += (positionVector.Y - camVector.Y) * 0.2 - - if camVector.X > 25085 { - camVector.X = 25085 - } else if camVector.X < -14843 { - camVector.X = -14843 - } - - if camVector.Y > 22500 { - camVector.Y = 22500 - } - - cam := pixel.IM.Moved(win.Bounds().Center().Sub(camVector)) - - canvas.SetMatrix(cam) - - // Drawing to the screen - win.SetSmooth(true) - bg.Draw(canvas, pixel.IM.Moved(pixel.V(win.Bounds().Center().X, win.Bounds().Center().Y+766)).Scaled(pixel.ZV, 10)) - txt.Draw(canvas, pixel.IM) - win.SetSmooth(false) - currentSprite.Draw(canvas, jetMat) - canvas.Draw(win, pixel.IM.Moved(win.Bounds().Center())) - win.Update() - } - -} - -func main() { - pixelgl.Run(run) -} - -var pixelateFragShader = ` -#version 330 core -#ifdef GL_ES -precision mediump float; -precision mediump int; -#endif - -in vec4 Color; -in vec2 texcoords; -in vec2 glpos; - -out vec4 fragColor; - -uniform vec4 u_colormask; -uniform vec4 u_texbounds; -uniform sampler2D u_texture; -uniform float u_amount; -uniform vec2 u_mouse; -uniform vec2 u_resolution; - -void main(void) -{ - vec2 t = (texcoords - u_texbounds.xy) / u_texbounds.zw; - - float d = 1.0 / u_amount; - float ar = u_resolution.x / u_resolution.y; - float u = floor( t.x / d ) * d; - d = ar / u_amount; - float v = floor( t.y / d ) * d; - fragColor = texture( u_texture, vec2( u, v ) ); -} -` - -/* - //fragColor = vec4(1.0,0.0,0.0,1.0); - // float d = 1.0 / u_amount; - // float ar = u_resolution.x / u_resolution.y; - // float u = floor( texcoords.x / d ) * d; - // d = ar / u_amount; - // float v = floor( texcoords.y / d ) * d; - // fragColor = texture( u_texture, vec2( u, v ) ); - - // vec2 p = t.st; - // p.x -= mod(t.x / glpos.x, t.x / glpos.x + 0.1); - // p.y -= mod(t.y / glpos.y, t.y / glpos.y + 0.1); - - // fragColor = texture(u_texture, p).rgba; -*/ -// varying vec2 vUv; -// uniform sampler2D tInput; -// uniform vec2 resolution; -// uniform float amount; - -// void main() { - -// float d = 1.0 / amount; -// float ar = resolution.x / resolution.y; -// float u = floor( vUv.x / d ) * d; -// d = ar / amount; -// float v = floor( vUv.y / d ) * d; -// gl_FragColor = texture2D( tInput, vec2( u, v ) ); - -// } diff --git a/examples/shaders/go-jetpack-pixelate2/jetpack.png b/examples/shaders/go-jetpack-pixelate2/jetpack.png deleted file mode 100644 index 4ea39e0..0000000 Binary files a/examples/shaders/go-jetpack-pixelate2/jetpack.png and /dev/null differ diff --git a/examples/shaders/go-jetpack-pixelate2/screenshot.png b/examples/shaders/go-jetpack-pixelate2/screenshot.png deleted file mode 100644 index a41e269..0000000 Binary files a/examples/shaders/go-jetpack-pixelate2/screenshot.png and /dev/null differ diff --git a/examples/shaders/go-jetpack-pixelate2/sky.png b/examples/shaders/go-jetpack-pixelate2/sky.png deleted file mode 100644 index ab5fa36..0000000 Binary files a/examples/shaders/go-jetpack-pixelate2/sky.png and /dev/null differ diff --git a/examples/shaders/go-jetpack-toon/README.md b/examples/shaders/go-jetpack-toon/README.md index 2f4eb31..9421a16 100644 --- a/examples/shaders/go-jetpack-toon/README.md +++ b/examples/shaders/go-jetpack-toon/README.md @@ -1,7 +1 @@ -# Go Jetpack -by [Branson Camp](https://github.com/bcamp1) using [Pixel](https://github.com/faiface/pixel) - -Welcome to Go-Jetpack, where you explore the skies using WASD or Arrow Keys. -This example showcases most of the fundamental pixel elements described in the [Pixel Wiki](https://github.com/faiface/pixel/wiki) - -![Screenshot](https://github.com/bcamp1/pixel/blob/master/examples/community/go-jetpack/screenshot.png) +A cartoon-izing shader added to the Jetpack demo! \ No newline at end of file diff --git a/examples/shaders/go-jetpack-toon/screenshot.png b/examples/shaders/go-jetpack-toon/screenshot.png index a41e269..d7ab21e 100644 Binary files a/examples/shaders/go-jetpack-toon/screenshot.png and b/examples/shaders/go-jetpack-toon/screenshot.png differ diff --git a/examples/shaders/isometric-basics-emboss/README.md b/examples/shaders/isometric-basics-emboss/README.md index 035ef05..b494e86 100644 --- a/examples/shaders/isometric-basics-emboss/README.md +++ b/examples/shaders/isometric-basics-emboss/README.md @@ -1,13 +1 @@ -# Isometric view basics - -Created by [Sergio Vera](https://github.com/svera). - -Isometric view is a display method used to create an illusion of 3D for an otherwise 2D game - sometimes referred to as pseudo 3D or 2.5D. - -Implementing an isometric view can be done in many ways, but for the sake of simplicity we'll implement a tile-based approach, which is the most efficient and widely used method. - -In the tile-based approach, each visual element is broken down into smaller pieces, called tiles, of a standard size. These tiles will be arranged to form the game world according to pre-determined level data - usually a 2D array. - -For a detailed explanation about the maths behind this, read [http://clintbellanger.net/articles/isometric_math/](http://clintbellanger.net/articles/isometric_math/). - -![Result](result.png) +A realtime embossing shader on the isometric demo! \ No newline at end of file diff --git a/examples/shaders/isometric-basics-emboss/screenshot.png b/examples/shaders/isometric-basics-emboss/screenshot.png new file mode 100644 index 0000000..5685d81 Binary files /dev/null and b/examples/shaders/isometric-basics-emboss/screenshot.png differ diff --git a/examples/shaders/parallax-edge-detection/README.md b/examples/shaders/parallax-edge-detection/README.md index ceda9ed..0148d29 100644 --- a/examples/shaders/parallax-edge-detection/README.md +++ b/examples/shaders/parallax-edge-detection/README.md @@ -1,9 +1 @@ -# Parallax scrolling demo - -Created by [Sergio Vera](https://github.com/svera) - -This example shows how to implement an infinite side scrolling background with a depth effect, using [parallax scrolling](https://en.wikipedia.org/wiki/Parallax_scrolling). Code is based in the [infinite scrolling background](https://github.com/faiface/pixel/tree/master/examples/community/scrolling-background) demo. - -Credits to [Peter Hellberg](https://github.com/peterhellberg) for the improved background images. - -![Parallax scrolling background](result.png) +A terrible "edge-detecting" shader on top of the parallax demo. Adjust with the -/+ keys. \ No newline at end of file diff --git a/examples/shaders/parallax-edge-detection/screenshot.png b/examples/shaders/parallax-edge-detection/screenshot.png new file mode 100644 index 0000000..37cedd2 Binary files /dev/null and b/examples/shaders/parallax-edge-detection/screenshot.png differ diff --git a/examples/shaders/raycaster/README.md b/examples/shaders/raycaster/README.md index 56eba27..86c7ba7 100644 --- a/examples/shaders/raycaster/README.md +++ b/examples/shaders/raycaster/README.md @@ -1,22 +1 @@ -# raycaster - -A raycaster made by [Peter Hellberg](https://github.com/peterhellberg/) as part of his [pixel-experiments](https://github.com/peterhellberg/pixel-experiments). - -Based on Lode’s article on [raycasting](http://lodev.org/cgtutor/raycasting.html). - -## Controls - -WASD for strafing and arrow keys for rotation. - -Place blocks using the number keys. - -## Screenshots - -![raycaster animation](https://user-images.githubusercontent.com/565124/31828029-798e6620-b5b9-11e7-96b7-fda540755745.gif) - -![raycaster screenshot](screenshot.png) - -## Links - - - https://github.com/peterhellberg/pixel-experiments/tree/master/raycaster - - https://gist.github.com/peterhellberg/835eccabf95800555120cc8f0c9e16c2 +FXAA emulating shader on top of the raycaster demo! Use the -/+ key to enable and disable. \ No newline at end of file diff --git a/examples/shaders/raycaster/screenshot.png b/examples/shaders/raycaster/screenshot.png index fd18e89..c2ee1e3 100644 Binary files a/examples/shaders/raycaster/screenshot.png and b/examples/shaders/raycaster/screenshot.png differ