User Tools

Site Tools


en:examples:shaders:shader_on_a_spritesheet

Shader on a Sprite Sheet

Assets

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

en/examples/shaders/shader_on_a_spritesheet.txt · Last modified: 2018/02/14 04:47 (20 months ago) by iarwain