====== Shader on a Sprite Sheet ======
===== Assets =====
{{:examples:shaders:sprites.png|}} {{:examples:shaders:sprites.png?300|}}
===== Code =====
orxObject_CreateFromConfig("DemoObject");
===== Config =====
[DemoObject]
Graphic = DemoGraphic
ShaderList = Shader
Scale = 10
[DemoGraphic]
Texture = sprites.png
TextureOrigin = (0,8,0)
TextureSize = (8,8,0)
[Shader]
ParamList = texture
Code = "
void main() {
vec2 p = gl_TexCoord[0].xy;
vec4 textureCol = texture2D(texture, p);
vec2 textStartCoord = vec2(texture_left, texture_top);
vec2 textEndCoord = vec2(texture_right, texture_bottom);
vec2 cropWidth = textEndCoord - textStartCoord;
gl_FragColor = textureCol;
if (p.x >= textStartCoord.x && p.x <= textEndCoord.x && p.y >= textStartCoord.y && p.y <= textEndCoord.y){
vec2 outerCoord = -1.0 + 2.0 * (p-textStartCoord) / cropWidth;
gl_FragColor.a = 1.0-outerCoord.y;
}
}"
===== Result =====
{{:examples:shaders:alien-shaded.png?150|}}