Evolunia
evolunia.net
- Joined
- Nov 6, 2017
- Messages
- 210
- Solutions
- 3
- Reaction score
- 187
Hello, I'm trying to make some shaders for otclient.
Currently I am trying to make an outline around my outfit, I've got it working nicely but some outfits are a bit buggy while walking and even some are bad stationary, but the majority seems to work flawlessy
I don't have any experience with shaders before, I played around with it now for a little bit and this is what I've made:
To detect where the outline should be drawn, it checks if the current color is a transparent color and if any of the neighbouring colors is a "real" colour.
Is there some better way to achieve this?
Here's some examples on how it looks like:
As you can see the gamemaster outfit is bugged with it, and there's two red lines where there shouldn't be any. Any tips on how to fix that? I've tried a lot of different things, but I can't seem to get a nice solution for it, so now I asking here
Currently I am trying to make an outline around my outfit, I've got it working nicely but some outfits are a bit buggy while walking and even some are bad stationary, but the majority seems to work flawlessy
I don't have any experience with shaders before, I played around with it now for a little bit and this is what I've made:
C++:
uniform mat4 u_Color;
varying vec2 v_TexCoord;
varying vec2 v_TexCoord2;
uniform sampler2D u_Tex0;
const float ALPHA_TOLERANCE = 0.01;
void main()
{
vec4 baseColor = texture2D(u_Tex0, v_TexCoord);
vec4 texcolor = texture2D(u_Tex0, v_TexCoord2);
if(texcolor.r > 0.9) {
baseColor *= texcolor.g > 0.9 ? u_Color[0] : u_Color[1];
} else if(texcolor.g > 0.9) {
baseColor *= u_Color[2];
} else if(texcolor.b > 0.9) {
baseColor *= u_Color[3];
}
vec4 pixel1 = texture2D(u_Tex0, vec2(v_TexCoord.x + 0.001, v_TexCoord.y));
vec4 pixel2 = texture2D(u_Tex0, vec2(v_TexCoord.x - 0.001, v_TexCoord.y));
vec4 pixel3 = texture2D(u_Tex0, vec2(v_TexCoord.x, v_TexCoord.y + 0.001));
vec4 pixel4 = texture2D(u_Tex0, vec2(v_TexCoord.x, v_TexCoord.y - 0.001));
bool neighbourColor = pixel4.a > ALPHA_TOLERANCE || pixel3.a > ALPHA_TOLERANCE || pixel2.a > ALPHA_TOLERANCE || pixel1.a > ALPHA_TOLERANCE;
if (baseColor.a < ALPHA_TOLERANCE && neighbourColor) {
baseColor.rgb = vec3(1.0, 0.0, 0.0);
baseColor.a = 0.7;
}
gl_FragColor = baseColor;
if(gl_FragColor.a < 0.01) discard;
}
Is there some better way to achieve this?
Here's some examples on how it looks like:
As you can see the gamemaster outfit is bugged with it, and there's two red lines where there shouldn't be any. Any tips on how to fix that? I've tried a lot of different things, but I can't seem to get a nice solution for it, so now I asking here