I have two quick questions: 1· How can you change the color of the outline 2· How can yo change the alpha of the outline to make it more transparent Thanks
1. You fill the background of the sprite (and every sub image) with your desired outline color with alpha = 0. The default background is black with alpha = 0. 2. In the shader you can multiply the alpha variable with your desired alpha value. Example: "alpha += ceil( texture2D( gm_BaseTexture, v_vTexcoord + offset_x).a) * 0.75;" Here it will draw the shader at 0.75 alpha value. The ceil function takes the neighboring pixel's alpha value and rounds it up to the next integer. You can multiply this value, which is 1, with any alpha value you wish. Dividing would also work but multiplying is obviously better for clean code. I hope you find this useful!
@@aerobetamax6022 Hey! I realize I'm a little late to this party but could you help me understand what you mean by "the background" of the sprite with "alpha = 0"? I understand that the default background is black and that's why the outline is black, but where should I fill a different color, on the sprite sheet or on a different layer? How do I set the alpha to 0? Thanks in advance, -Russ
@@russellcastell2709 The background I refer to is simply the unpainted pixels of the sprite image. Default they are black, with alpha = 0 as to be transparent. You can change the alpha in the advanced color settings, one of the sliders changes the alpha value of the custom color you are customizing in the settings of the sprite editor.
@@russellcastell2709 try this, go to your object and open it as if you were going to draw on it, then choose the color you want and select the (cube) tool, then set the cube opacity to (0) and in color mode select replace then click sprite background and save everything, and when you run the game you will see the outline of the color you assigned to the sprite, this is a shape which changes the background color, it works for (Game Maker Studio) I don't know if it would work for (Game Maker Studio: 2. a little late but I hope I have helped you.
This is exactly the shader I needed to create aside from the outline color XD There's another I need to make and I think this video gave me the tools I need to write it, thanks! :D
I wouldn't actually recommend using this version of the code. The fact that you create the alpha float with the offset instantly to it means that if a pixel is alone (no surrounding pixel) it turns transparent but still gets the outline. Should be really simple to fix though
This is the only tutorial I could not get to work. The game could not start when I had this shader written at all, even if I did not call it with anything else. There were no missing semicolons in my code or anything, not sure what went wrong.
Is it possible to make this outline white instead of black? Would it be easy to do?
7 лет назад+5
I am not quite sure if I understand Shaun, but why adding the alpha value of the surrounding pixels of the current pixel is making an outline?? why the pixels inside the ghost are not being modified?? Can you help me understand this?
7 лет назад+8
ohhh, I understand now and that is why a transparent pixel remains transparent unless it is in contact with a non-transparent pixel. Because the alpha value of a transparent pixel is 0!!
Would it be possible to accomplish this without having the extra invisible pixel available around the sprite. I'm looking into a way to do 1 outline using multiple sprites, such as having character with different hair style and clothes and 1 outline around the overall character.. I can do that easily with surface but a shader for it would be better I think if even possible.
Compile error - fragment shader: at line x: ". comment lines out and it makes no difference. There's something bigger at play here, or something simple I've missed? All the code is entered correctly as far as I can see.
I got the same thing. I have no idea what went wrong and no idea how to fix it. So I'm basically going to give up on shaders for now and do some other workaround. If I can't make the most basic one work I certainly can't do anything more complex.
Help me understand, please. Since the alpha variable is the sum of the ceiled surrounding alpha, wouldn't alpha > 1 if more than one surrounding pixel has an alpha > 0?
@@sukedent1 This code, with the suggested modification just works fine, thanks :) I wonder how to make an outline which is always 1 pixel wide even when you start to scale the image... I will try to do that, but knowing my knowledge with shaders will fail soon, and I would use that for a gamejam. :D
Not works for me, why? T.T Error in compile : alpha += ceil( texture2D( gm_BaseTexture, v_vTexcoord - offsetx).a; (in Shader.fsh) 'String not found: na linha 1 : HLSL11 compiler failed with exit code -1' What can it be? I tried in the latest version and LTS.
Hey Shaun, QQ: If i'm using a single object to draw two different sprites on top of each other, is there any way to modify this shader to only draw an outline around their combined silhouette? For example, let's say your ghost was holding a sword that was drawn on top of him/her. I don't want the shader outlining the entire sword, but only the parts of the sword that protrude outside of the ghost's own outline. Thoughts? Thanks for all the help!
Great video! I am curious if you can use this methodology to draw vertexes that take up whole pixels in the game (8 bit game scaled 3x), rather than sub-pixel lines.
this still works on current GMS2?, it didn't for me! it seems that you need to initialize those vec2, since otherwise the other value can be random ie offsety.x can be anything (it can serve as a noise effect tho)
i'm testing your code on GMS 1.4x but the outline isn't showed.. why that happen? i see that we can change the thickness, but the color can be changed too?
First, thanks for another awesome video.. I'm curious how one would use this to outline text, or is it just easier/better to draw the text shadow, then redraw the text overtop of it? (thought maybe the shader would be better to use, and have multiple uses not limited to just the text)
this works really well and makes the enemys in my game look way cooler! only thing is with one of my enemys in particular, certain sprites of his freaks out a little and has like a really thick outline randomly. anybody have any idea why this could be?
2 years late, but yes. It's because your sprite is being atlas'd behind the scenes. The quickest way to fix this would be to go to Tools > Texture Groups and uncheck "Automatically Crop" for the Default group. You can play around with this by adding new groups to gain some optimization back from GM2's atlasing, but this should fix the outline issue described. Sorry again for being 2 years late, I was asleep.
The outline is drawn in whatever colour the transparent background of the sprite is. Even though zero opacity black and zero opacity white both just look like nothing, they are not the same. If you want a white outline for example, select the colour white in the sprite editor, and reduce the opacity to zero, then fill in the empty space around your sprite. Hope this helps.
I wanted to ask a question, but I don't want it to come across as sarcastic so this is a disclaimer XD QUESTION FOR CURIOSITY SAKE- Why would one create an outline in the shader this way as opposed to just doing it in the sprite index itself? Could you use this technique to draw the outline ONLY when, say, the sprite is behind an object (such as a tree or wall)? For example- say I wanted to have a yellow outline on my player object present itself only when there is something in the foreground so you can still determine where the player is on screen. Would this be a way you could do that?
I wanted to ask a question, but I don't want it to come across as sarcastic so this is a disclaimer XD QUESTION FOR CURIOSITY SAKE- Why do people make that face? The face on your pretty lil mug.
I would like to learn more about shaders. You can do so many cool effects with them, but I need to find the time to exercise and figure out and learn this shader language. For a start I would like to make a shader with which I could change the values of the color channels independently and maybe brightness and contrast.
First off, cheers for the tutorial! I'm getting ' Fragment Shader: sh_outline at line 19: " ' as a compile error, which doesn't explain much. The code I have is exactly the same as in the video. If I comment lines 18, 19 and 20 out it still gives the same error 'at line 19', even though there isn't anything there once commented out. I'm guessing this means the error is actually elsewhere but ... I can't find it! Any ideas?
Make sure you've closed out all your brackets correctly; I ran into this error and on double checking noticed that I was missing a closing ")" after the ".a" while adding the alpha values. It might not be the case for you but this was my problem at least :)
Love your tutorials. I just tried this and pretty sure I checked and tripple checked all the syntax, and still getting an error Fragment Shader: shOutline at line 15 : 'offsetx' gment Shader: shOutline at line 15 : 'x' FraFragment Shader: shOutline at line 17 : 'offsety' Fragment Shader: shOutline at line 17 : 'y' String not found: at line 1 : HLSL11 compiler failed with exit code -1
I'm new to programing I programmed some really basic shader but as far as I can tell shaders are completely absolute, drawing an outline or a different shade of red isn't hard! I don't understand why any body would spend hours making a shader when they can draw it by hand in 5 minutes its really, really not that hard
Variety. It's on the fly, so you could make cool effects such as change the lighting. If you had a red and blue light, do you want two separate sprite sets of slightly different colors, or one sprite and two shaders to change it endlessly? Also it gets more complex than this, there's lots of cool effects you'll NEED a shader to do such as wavy sprites.
The outline is drawn in whatever colour the transparent background of the sprite is. Even though zero opacity black and zero opacity white both just look like nothing, they are not the same. If you want a white outline for example, select the colour white in the sprite editor, and reduce the opacity to zero, then fill in the empty space around your sprite. Hope this helps.
I would subscribe if you promise to make a tutorial on how to make a shader that swaps colors! Like if I had a red sprite, how can I make it blue using a shader and ignoring image blend?
@@MrKingJavo I think at the time I was looking for a tutorial and the swapper you speak of doesn't teach me the code I was looking for. Thanks for the suggestion though!
make sure your sprite image has some spare room beside it, if the image is drawn up to the very edge of the sprite there is not empty squares to check against!
Why does mine not work? I tried to program it on my own then i failed then i tried it like you did and i failed. Then i literally copied someone else's in and still again... it didn't work. WTF? The problem is in the shader code according to gms2...
The outline is drawn in whatever colour the transparent background of the sprite is. Even though zero opacity black and zero opacity white both just look like nothing, they are not the same. If you want a white outline for example, select the colour white in the sprite editor, and reduce the opacity to zero, then fill in the empty space around your sprite. Hope this helps.
What do you need to do to make this work in Game Maker 1? I already know that in the shader fragment code, "ciel" needs to be "max" instead. Besides that, I have followed everything else in this vid, but I get an error message telling that object.pixelH "not set before reading it". I definitely have uniform float pixelH; written in the shader fragment code right underneath varying vec4 v_vColour; just like yours. EDIT: I forgot to put quotes around "pixelH" in the create event. But now I'm having another problem. I was trying to do this to text, but no outline is showing up around the text. I am using font_get_texture instead of sprite_get_texture of course. But I'm not sure what else needs to be done.
i love you so much the shader was only shading at the very top, bottom, left, and right of the sprite and this one works with also letting me use colour. also jinx pfp >o
I was wondering if i was making mistakes but after creating a blank project just to test it, and still not working i feel like this doesnt work anymore on recent Gamemaker studio 2 (free).
Hi there. We are currently developing a game, 'A Matter of Time', using Gamemaker. It would be awesome if you could check out the game's trailer on our channel, and even better if we could receive feedback on it! Thank you!
I have two quick questions:
1· How can you change the color of the outline
2· How can yo change the alpha of the outline to make it more transparent
Thanks
1. You fill the background of the sprite (and every sub image) with your desired outline color with alpha = 0. The default background is black with alpha = 0.
2. In the shader you can multiply the alpha variable with your desired alpha value.
Example: "alpha += ceil( texture2D( gm_BaseTexture, v_vTexcoord + offset_x).a) * 0.75;" Here it will draw the shader at 0.75 alpha value. The ceil function takes the neighboring pixel's alpha value and rounds it up to the next integer. You can multiply this value, which is 1, with any alpha value you wish. Dividing would also work but multiplying is obviously better for clean code.
I hope you find this useful!
@@aerobetamax6022 Hey! I realize I'm a little late to this party but could you help me understand what you mean by "the background" of the sprite with "alpha = 0"? I understand that the default background is black and that's why the outline is black, but where should I fill a different color, on the sprite sheet or on a different layer? How do I set the alpha to 0?
Thanks in advance,
-Russ
@@russellcastell2709 The background I refer to is simply the unpainted pixels of the sprite image. Default they are black, with alpha = 0 as to be transparent. You can change the alpha in the advanced color settings, one of the sliders changes the alpha value of the custom color you are customizing in the settings of the sprite editor.
@@russellcastell2709 try this, go to your object and open it as if you were going to draw on it, then choose the color you want and select the (cube) tool,
then set the cube opacity to (0) and in color mode select replace then click sprite background and save everything, and when you run the game you will see the outline of the color you assigned to the sprite, this is a shape which changes the background color, it works for (Game Maker Studio) I don't know if it would work for (Game Maker Studio: 2.
a little late but I hope I have helped you.
To change the color just write gl_FragColor.rgb=vec3(1,0,0); at the end of the shader, choose your desired values, this is for red
This is exactly the shader I needed to create aside from the outline color XD There's another I need to make and I think this video gave me the tools I need to write it, thanks! :D
I am excited to continue watching the plataformer serious :D
Code from this video (with a little different names and few optimizations):
I called my shader "shdr_outline"
shdr_outline.fsh code:
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord; // vec2( x, y )
varying vec4 v_vColour; // vec4( r, g, b, a )
// Custom parameters. We must pass them manualy!
uniform float pixelWidth;
uniform float pixelHeight;
void main()
{
gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
vec2 offsetX = vec2( pixelWidth, 0.0 );
vec2 offsetY = vec2( 0.0, pixelHeight );
float alpha = texture2D( gm_BaseTexture, v_vTexcoord - offsetX ).a;
alpha += texture2D( gm_BaseTexture, v_vTexcoord + offsetX ).a;
alpha += texture2D( gm_BaseTexture, v_vTexcoord - offsetY ).a;
alpha += texture2D( gm_BaseTexture, v_vTexcoord + offsetY ).a;
gl_FragColor.a = alpha;
}
"Create" event code:
// Find parameters in our shader
pixelWidth = shader_get_uniform(shdr_outline, "pixelWidth");
pixelHeight = shader_get_uniform(shdr_outline, "pixelHeight");
// Find pointer to our texture
texture_ptr = sprite_get_texture(sprite_index, 0);
// Get texel width and height
texelWidth = texture_get_texel_width(texture_ptr);
texelHeight = texture_get_texel_height(texture_ptr);
"Draw" event code:
// Set our shader instead of default one
shader_set(shdr_outline);
// Pass our custom float parameters "pixelWidth" and "pixelHeight";
shader_set_uniform_f(pixelWidth, texelWidth);
shader_set_uniform_f(pixelHeight, texelHeight);
// Draw sprite
draw_self();
// Set shader to default
shader_reset();
Wired. I followed tutornal but not workin but changed fsh code to ur code its working :Q
@@Coody0829 Glad that I could help :-)
Thank you
I wouldn't actually recommend using this version of the code. The fact that you create the alpha float with the offset instantly to it means that if a pixel is alone (no surrounding pixel) it turns transparent but still gets the outline. Should be really simple to fix though
This is the only tutorial I could not get to work. The game could not start when I had this shader written at all, even if I did not call it with anything else. There were no missing semicolons in my code or anything, not sure what went wrong.
awesome! are you planning to make more shader videos?
Even better than last tutorial!
Do we need to load that texture group or something? It's not working for me.
palette swap tut plz?
Is it possible to make this outline white instead of black? Would it be easy to do?
I am not quite sure if I understand Shaun, but why adding the alpha value of the surrounding pixels of the current pixel is making an outline?? why the pixels inside the ghost are not being modified?? Can you help me understand this?
ohhh, I understand now and that is why a transparent pixel remains transparent unless it is in contact with a non-transparent pixel. Because the alpha value of a transparent pixel is 0!!
Lol, nice one, Socrates.
Thanks for clarifying after you figured it out, was wondering this myself until I stumble upon your precious comment !
Would it be possible to accomplish this without having the extra invisible pixel available around the sprite. I'm looking into a way to do 1 outline using multiple sprites, such as having character with different hair style and clothes and 1 outline around the overall character.. I can do that easily with surface but a shader for it would be better I think if even possible.
Shader only draws outline above and below the sprite, not left and right! Help please?
This has probably already been asked, but how do I go about adding a second outline around the first? And maybe even a third around the second? Etc?
Compile error - fragment shader: at line x: ". comment lines out and it makes no difference. There's something bigger at play here, or something simple I've missed? All the code is entered correctly as far as I can see.
You are probably missing a *;*. it wont be in the line where it says 'at line x' but often a different line.
@@ronanvankessel6329 worst debug error ever
I got the same thing. I have no idea what went wrong and no idea how to fix it. So I'm basically going to give up on shaders for now and do some other workaround. If I can't make the most basic one work I certainly can't do anything more complex.
@@mulatdood Hey man, double check and triple check the variable names in your code. Was a really tiny thing I missed...
Help me understand, please. Since the alpha variable is the sum of the ceiled surrounding alpha, wouldn't alpha > 1 if more than one surrounding pixel has an alpha > 0?
Now I just need to figure out how to change the outline's color in code..
@Schlingelkron You madd n00b? git gud then
@@sukedent1 thanks!
@@sukedent1 This code, with the suggested modification just works fine, thanks :)
I wonder how to make an outline which is always 1 pixel wide even when you start to scale the image... I will try to do that, but knowing my knowledge with shaders will fail soon, and I would use that for a gamejam. :D
Not works for me, why? T.T
Error in compile : alpha += ceil( texture2D( gm_BaseTexture, v_vTexcoord - offsetx).a; (in Shader.fsh)
'String not found: na linha 1 : HLSL11 compiler failed with exit code -1'
What can it be? I tried in the latest version and LTS.
I got the same error. :( Did you ever find a solution?
Hey Shaun, QQ: If i'm using a single object to draw two different sprites on top of each other, is there any way to modify this shader to only draw an outline around their combined silhouette? For example, let's say your ghost was holding a sword that was drawn on top of him/her. I don't want the shader outlining the entire sword, but only the parts of the sword that protrude outside of the ghost's own outline. Thoughts? Thanks for all the help!
Great video. When is your next platformer video coming out? ;)
Great video! I am curious if you can use this methodology to draw vertexes that take up whole pixels in the game (8 bit game scaled 3x), rather than sub-pixel lines.
this still works on current GMS2?, it didn't for me! it seems that you need to initialize those vec2, since otherwise the other value can be random ie offsety.x can be anything (it can serve as a noise effect tho)
gamemaker refuses to let me disable automatic cropping. every time I run the game it automatically re-enables it.
we need to give this ghost a name...
2 years, still no name
@@embodyingocean189 yeah
@@embodyingocean189 there are 3, actually
@@AYMGaming 4*
i'm testing your code on GMS 1.4x but the outline isn't showed.. why that happen?
i see that we can change the thickness, but the color can be changed too?
First, thanks for another awesome video..
I'm curious how one would use this to outline text, or is it just easier/better to draw the text shadow, then redraw the text overtop of it? (thought maybe the shader would be better to use, and have multiple uses not limited to just the text)
this works really well and makes the enemys in my game look way cooler! only thing is with one of my enemys in particular, certain sprites of his freaks out a little and has like a really thick outline randomly. anybody have any idea why this could be?
2 years late, but yes. It's because your sprite is being atlas'd behind the scenes. The quickest way to fix this would be to go to Tools > Texture Groups and uncheck "Automatically Crop" for the Default group. You can play around with this by adding new groups to gain some optimization back from GM2's atlasing, but this should fix the outline issue described.
Sorry again for being 2 years late, I was asleep.
@@zheckman89 lmao thanks man im glad you had a goood nap
@@zheckman89 Bit of a necro, but this fixed the issue I was having with it not drawing on the sides of my sprites, thanks!
Been researching this all day, Thank you! Solved my issue @@zheckman89
I do not understand what I'm doing wrong.
Pixel strokes are not all drawn. ((((
great tutorial. how do I change the background color from black?
oops i meant the outline color. If I want a white outline instead of black.
The outline is drawn in whatever colour the transparent background of the sprite is. Even though zero opacity black and zero opacity white both just look like nothing, they are not the same. If you want a white outline for example, select the colour white in the sprite editor, and reduce the opacity to zero, then fill in the empty space around your sprite. Hope this helps.
@@jellroberts9249 There's gotta be a way to swap the color in the shader code rather than editing the hundreds of sprites in my game.
I wanted to ask a question, but I don't want it to come across as sarcastic so this is a disclaimer XD
QUESTION FOR CURIOSITY SAKE-
Why would one create an outline in the shader this way as opposed to just doing it in the sprite index itself? Could you use this technique to draw the outline ONLY when, say, the sprite is behind an object (such as a tree or wall)?
For example- say I wanted to have a yellow outline on my player object present itself only when there is something in the foreground so you can still determine where the player is on screen. Would this be a way you could do that?
Shaun Spalding thank you for taking the time to reply. I love your videos!
I wanted to ask a question, but I don't want it to come across as sarcastic so this is a disclaimer XD
QUESTION FOR CURIOSITY SAKE-
Why do people make that face? The face on your pretty lil mug.
I would like to learn more about shaders. You can do so many cool effects with them, but I need to find the time to exercise and figure out and learn this shader language.
For a start I would like to make a shader with which I could change the values of the color channels independently and maybe brightness and contrast.
I was waiting for more shader tutorials
First off, cheers for the tutorial! I'm getting ' Fragment Shader: sh_outline at line 19: " ' as a compile error, which doesn't explain much. The code I have is exactly the same as in the video. If I comment lines 18, 19 and 20 out it still gives the same error 'at line 19', even though there isn't anything there once commented out. I'm guessing this means the error is actually elsewhere but ... I can't find it! Any ideas?
Make sure you've closed out all your brackets correctly; I ran into this error and on double checking noticed that I was missing a closing ")" after the ".a" while adding the alpha values. It might not be the case for you but this was my problem at least :)
Shaun, can you please do a video on a Sinewave / vertical/horizontal oscillation shaders? because I want to make an earthbound like wavy background.
Was the wavy shader code ever posted, or tutorialized?
Love your tutorials. I just tried this and pretty sure I checked and tripple checked all the syntax, and still getting an error
Fragment Shader: shOutline at line 15 : 'offsetx'
gment Shader: shOutline at line 15 : 'x'
FraFragment Shader: shOutline at line 17 : 'offsety'
Fragment Shader: shOutline at line 17 : 'y'
String not found: at line 1 : HLSL11 compiler failed with exit code -1
DOh, never mind. had code error, variable had different capitalization from when being called
Uhh.. Texture Groups is greyed out for me. :(
Make sure you have one of your sprites in that window selected
TidyWire Your profile pic goes exactly with your comment xD
i can`t make work this shader for GMS 1.4. This must work or not?
Мамкин Анархист this is GMS2
I'm new to programing I programmed some really basic shader but as far as I can tell shaders are completely absolute, drawing an outline or a different shade of red isn't hard! I don't understand why any body would spend hours making a shader when they can draw it by hand in 5 minutes its really, really not that hard
Variety. It's on the fly, so you could make cool effects such as change the lighting. If you had a red and blue light, do you want two separate sprite sets of slightly different colors, or one sprite and two shaders to change it endlessly? Also it gets more complex than this, there's lots of cool effects you'll NEED a shader to do such as wavy sprites.
And also that helped me when I wanted to draw outlines on fonts!
can you plz make a power up tutorial and its collison
Can you make a tutorial on distortion shader tutorial?
Just a quick question, why does the outline on some of my sprites show as white instead of black?
The outline is drawn in whatever colour the transparent background of the sprite is. Even though zero opacity black and zero opacity white both just look like nothing, they are not the same. If you want a white outline for example, select the colour white in the sprite editor, and reduce the opacity to zero, then fill in the empty space around your sprite. Hope this helps.
@@jellroberts9249 I tried this and didn't help :(
How do you make the outline thicker?
He says, watch the video. 13:50
I would subscribe if you promise to make a tutorial on how to make a shader that swaps colors! Like if I had a red sprite, how can I make it blue using a shader and ignoring image blend?
Also, if the red object had green, the green will be completely unaffected by the shader due to the shader looking for only red to turn blue.
@@Freefork You need to lookup Pixelated Pope's Retro Palette Swapper
@@MrKingJavo I think at the time I was looking for a tutorial and the swapper you speak of doesn't teach me the code I was looking for.
Thanks for the suggestion though!
how do I make it colored?
there are two ways:
1/ detect the outline pixels when they are transitioning from 0 to 1;
```
void main() {
vec2 offsetX; offsetX.x = u_pixelW;
vec2 offsetY; offsetY.y = u_pixelH;
vec4 texColor = texture2D(gm_BaseTexture, v_vTexcoord);
float alpha = texColor.a;
float original_alpha = alpha;
alpha += ceil(texture2D(gm_BaseTexture, v_vTexcoord + offsetX).a);
alpha += ceil(texture2D(gm_BaseTexture, v_vTexcoord - offsetX).a);
alpha += ceil(texture2D(gm_BaseTexture, v_vTexcoord + offsetY).a);
alpha += ceil(texture2D(gm_BaseTexture, v_vTexcoord - offsetY).a);
if (alpha > 1.0) alpha = 1.0; // claim alpha
if (original_alpha != alpha) {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
else {
gl_FragColor = texColor;
}
gl_FragColor.a = alpha;
}
```
2/ transparent pixels have a color of (0,0,0,0); use that to detect transparent pixels;
```
void main() {
vec2 offsetX; offsetX.x = u_pixelW;
vec2 offsetY; offsetY.y = u_pixelH;
vec4 texColor = texture2D(gm_BaseTexture, v_vTexcoord);
float alpha = texColor.a;
alpha += ceil(texture2D(gm_BaseTexture, v_vTexcoord + offsetX).a);
alpha += ceil(texture2D(gm_BaseTexture, v_vTexcoord - offsetX).a);
alpha += ceil(texture2D(gm_BaseTexture, v_vTexcoord + offsetY).a);
alpha += ceil(texture2D(gm_BaseTexture, v_vTexcoord - offsetY).a);
if (texColor == vec4(0.0, 0.0, 0.0, 0.0)) {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
else {
gl_FragColor = texColor;
}
gl_FragColor.a = alpha;
}
```
replace `gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);` with your color of choice
Can you use DnD To use shaders
my outline gets cut out at straight edges :(
make sure your sprite image has some spare room beside it, if the image is drawn up to the very edge of the sprite there is not empty squares to check against!
Why does mine not work?
I tried to program it on my own then i failed then i tried it like you did and i failed. Then i literally copied someone else's in and still again... it didn't work.
WTF?
The problem is in the shader code according to gms2...
Very helpful
What about the outline colour or width?
The outline is drawn in whatever colour the transparent background of the sprite is. Even though zero opacity black and zero opacity white both just look like nothing, they are not the same. If you want a white outline for example, select the colour white in the sprite editor, and reduce the opacity to zero, then fill in the empty space around your sprite. Hope this helps.
Thank you! :D
What do you need to do to make this work in Game Maker 1? I already know that in the shader fragment code, "ciel" needs to be "max" instead. Besides that, I have followed everything else in this vid, but I get an error message telling that object.pixelH "not set before reading it". I definitely have uniform float pixelH; written in the shader fragment code right underneath varying vec4 v_vColour; just like yours.
EDIT: I forgot to put quotes around "pixelH" in the create event. But now I'm having another problem. I was trying to do this to text, but no outline is showing up around the text. I am using font_get_texture instead of sprite_get_texture of course. But I'm not sure what else needs to be done.
thank you for gamemaker video
What function opens the android keyboard without using dialog box?
I need that wavy sprite shader tutorial.
Thanks
awesome, thanks for the response!
This is my variant for color
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform float pixelH;
uniform float pixelW;
void main()
{
vec2 offsetX;
offsetX.x = pixelW;
vec2 offsetY;
offsetY.y = pixelH;
float alpha = texture2D(gm_BaseTexture,v_vTexcoord).a;
float is_empty = ceil(1.0 - alpha);
alpha += ceil(texture2D(gm_BaseTexture,v_vTexcoord + offsetX).a);
alpha += ceil(texture2D(gm_BaseTexture,v_vTexcoord - offsetX).a);
alpha += ceil(texture2D(gm_BaseTexture,v_vTexcoord + offsetY).a);
alpha += ceil(texture2D(gm_BaseTexture,v_vTexcoord - offsetY).a);
gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
vec4 outline_colour = vec4(0.2,0.4,0.8,alpha);
gl_FragColor = mix(gl_FragColor,outline_colour,is_empty);
Thank you!!! I was not looking forward to changing the background color on every sprite in my game to the desired outline color. Much appreciated!
i love you so much
the shader was only shading at the very top, bottom, left, and right of the sprite and this one works with also letting me use colour. also jinx pfp >o
@Olivia_meoww I'm very happy!!
Some update totally mangled this shader up
I was wondering if i was making mistakes but after creating a blank project just to test it, and still not working i feel like this doesnt work anymore on recent Gamemaker studio 2 (free).
não entendi
Thhhhhhxxxxxxxxx brooo
That's odd. I subbed to you, but i didn't get this in my sub box.
Can you make a sonic game tutorial
Like with boost and stuff
Do a normal platformer, then add a momentum effect, I'll reply again once I come up with something that should help.
shader_set_uniform_f_array() accept an array instead of scalar now:
```
shader_set_uniform_f_array(_upixelH, [_texelH]);
shader_set_uniform_f_array(_upixelW, [_texelW]);
```
Hi there. We are currently developing a game, 'A Matter of Time', using Gamemaker. It would be awesome if you could check out the game's trailer on our channel, and even better if we could receive feedback on it! Thank you!
first!