-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Texture atlases can specify a shader by name now
Included a flipbook shader as an example of its use.
- Loading branch information
Showing
13 changed files
with
307 additions
and
171 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
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
Binary file not shown.
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,29 @@ | ||
#ifdef GL_ES | ||
precision mediump float; | ||
#endif | ||
|
||
uniform sampler2D u_texture; | ||
uniform vec4 u_FogColor; | ||
|
||
uniform float u_time; | ||
uniform float u_tex_width; | ||
uniform float u_tex_height; | ||
uniform int u_sprite_columns; | ||
uniform int u_sprite_rows; | ||
|
||
varying vec4 v_color; | ||
varying vec2 v_texCoords; | ||
varying float v_fogFactor; | ||
varying float v_eyeDistance; | ||
|
||
vec4 tex_Color; | ||
|
||
void main() { | ||
vec4 color; | ||
|
||
tex_Color = texture2D( u_texture, v_texCoords ); | ||
color = v_color * tex_Color; | ||
if(tex_Color.a < 0.01) discard; | ||
|
||
gl_FragColor = mix(u_FogColor, color, v_fogFactor); | ||
} |
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,67 @@ | ||
uniform mat4 u_projectionViewMatrix; | ||
uniform float u_fogStart; | ||
uniform float u_fogEnd; | ||
uniform float u_time; | ||
|
||
uniform vec4 u_AmbientColor; | ||
uniform vec4 u_FogColor; | ||
|
||
uniform float u_tex_width; | ||
uniform float u_tex_height; | ||
uniform int u_sprite_columns; | ||
uniform int u_sprite_rows; | ||
|
||
uniform vec4 u_LightColors[{{MAX_DYNAMIC_LIGHTS}}]; | ||
uniform vec3 u_LightPositions[{{MAX_DYNAMIC_LIGHTS}}]; | ||
uniform int u_UsedLights; | ||
|
||
attribute vec4 a_position; | ||
attribute vec4 a_color; | ||
attribute vec2 a_texCoord0; | ||
|
||
varying vec2 v_texCoords; | ||
varying vec4 v_color; | ||
|
||
varying float v_fogFactor; | ||
varying float v_eyeDistance; | ||
|
||
const float c_zerof = 0.0; | ||
const float c_onef = 1.0; | ||
const float c_animateSpeed = 8.0; | ||
|
||
vec4 vertexPositionInEye; | ||
|
||
float calcFogFactor(float distanceToEye); | ||
|
||
void main() { | ||
v_texCoords = a_texCoord0; | ||
gl_Position = u_projectionViewMatrix * a_position; | ||
v_color = a_color + u_AmbientColor; | ||
|
||
// Flip through the atlas on this row | ||
v_texCoords.x += float(int(u_time * c_animateSpeed) % u_sprite_columns) * u_tex_width; | ||
|
||
if(u_UsedLights != 0) { | ||
for(int i=0; i < {{MAX_DYNAMIC_LIGHTS}}; i++) | ||
{ | ||
if(u_LightColors[i].a != 0.0) | ||
{ | ||
float lightDistance = length(u_LightPositions[i] - gl_Position.xyz) / u_LightColors[i].a; | ||
float diffuse = (1.0 / (1.0 + (lightDistance * lightDistance))); | ||
v_color += (u_LightColors[i] * diffuse) * a_color.a; | ||
} | ||
} | ||
} | ||
|
||
v_color.a = 1.0; | ||
|
||
vertexPositionInEye = gl_Position; | ||
v_fogFactor = calcFogFactor(-vertexPositionInEye.z - u_fogEnd * (1.0 - a_color.a)); | ||
v_eyeDistance = -vertexPositionInEye.z; | ||
} | ||
|
||
float calcFogFactor(float distanceToEye) | ||
{ | ||
float f = (u_fogEnd - -distanceToEye) / (u_fogEnd - u_fogStart); | ||
return clamp(f, c_zerof, c_onef); | ||
} |
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
Oops, something went wrong.