Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
112 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Image Wrapping</title> | ||
</head> | ||
<body> | ||
<canvas id="game"></canvas> | ||
<script src="../../lib/excalibur.js"></script> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/// <reference path="../../lib/excalibur.d.ts" /> | ||
|
||
// identity tagged template literal lights up glsl-literal vscode plugin | ||
var glsl = x => x[0]; | ||
var game = new ex.Engine({ | ||
canvasElementId: 'game', | ||
width: 800, | ||
height: 800 | ||
}); | ||
|
||
var fireShader = glsl`#version 300 es | ||
precision mediump float; | ||
uniform float animation_speed; | ||
uniform float offset; | ||
uniform float u_time_ms; | ||
uniform sampler2D u_graphic; | ||
uniform sampler2D noise; | ||
in vec2 v_uv; | ||
out vec4 fragColor; | ||
void main() { | ||
vec2 animatedUV = vec2(v_uv.x, v_uv.y + (u_time_ms / 1000.) * 0.5); | ||
vec4 color = texture(noise, animatedUV); | ||
color.rgb += (v_uv.y - 0.5); | ||
color.rgb = step(color.rgb, vec3(0.5)); | ||
color.rgb = vec3(1.0) - color.rgb; | ||
fragColor.rgb = mix(vec3(1.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0), v_uv.y); | ||
fragColor.a = color.r; | ||
fragColor.rgb = fragColor.rgb * fragColor.a; | ||
} | ||
` | ||
|
||
var noiseImage = new ex.ImageSource('./noise.png', { | ||
filtering: ex.ImageFiltering.Blended, | ||
wrapping: ex.ImageWrapping.Repeat | ||
}); | ||
|
||
var material = game.graphicsContext.createMaterial({ | ||
name: 'fire', | ||
fragmentSource: fireShader, | ||
images: { | ||
'noise': noiseImage | ||
} | ||
}) | ||
|
||
var actor = new ex.Actor({ | ||
pos: ex.vec(0, 200), | ||
anchor: ex.vec(0, 0), | ||
width: 800, | ||
height: 600, | ||
color: ex.Color.Red | ||
}); | ||
actor.graphics.material = material; | ||
game.add(actor); | ||
|
||
var loader = new ex.Loader([noiseImage]); | ||
|
||
game.start(loader); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters