Shaders GMS2 shader not working. Please help.

C

cammodore64

Guest
I just started playing with shaders and even though my code is exactly like the simple tutorials I'm following, nothing seems to change when I run the program. I have no idea what I'm doing wrong. Any advice would be a great help.

Here's the fragment shader's code:

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

void main() {

vec4 base_col = v_vColor * texture2D(gm_BaseTexture, v_vTexcoord);

gl_FragColor = vec4(base_col.rgb, base_col.a * 0.5);
}

And here's the test object's draw event code:

shader_set(shader0);
draw_self();
shader_reset();

Again, very simple stuff and yet nothing seems to change when ran. The object sprite's "separate texture page" box is checked and color interpolation between pixels has been disabled.
 

NightFrost

Member
That should be drawing the sprite at 0.5 alpha, so something is off. Have you perhaps turned off alpha blending?
 
It's not necessary to use seperate texture page in this case. Although this is not the cause of your problem.

There's not enough information here to explain why you wouldn't see any difference between using the shader and not using the shader. I would suggest that, first, you double check that there really isn't any visible difference. Then, check if there is anything else going on in your project that might be interfering with the expected function of this shader. Possible culprits might be certain blending modes, or perhaps drawing multiple instances overlapping in the same spot.
 
C

cammodore64

Guest
It's not necessary to use seperate texture page in this case. Although this is not the cause of your problem.

There's not enough information here to explain why you wouldn't see any difference between using the shader and not using the shader. I would suggest that, first, you double check that there really isn't any visible difference. Then, check if there is anything else going on in your project that might be interfering with the expected function of this shader. Possible culprits might be certain blending modes, or perhaps drawing multiple instances overlapping in the same spot.
What I posted is the entirety of the project’s code (I threw this together in a new program purely to test/get an understanding of shaders). I’ve also checked the screen output several times and the results really don’t seem to show any visible difference. Is there anything that maybe I’m not including in the code? I seriously feel like such a dope. I’ve never hit a wall like this with GMS.
 
If you don't compare side-by-side the difference between using and not using the shader, it might be difficult to visually detect any difference. Either set up a toggle button, or take a screenshot of each and compare in an image editor.
 
C

cammodore64

Guest
Try changing something more obvious, such as the color (eg. making it red). See if that even works.
I changed the shader code to the following:

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

void main() {
// vec4 base_col = v_vColor * texture2D(gm_BaseTexture, v_vTexcoord);

gl_FragColor = vec4.rgba(1.0, 0.0, 0.0, 0.0);
}

I figure the result should have been a solid red box, but again, the sprite just appears unchanged.
 
C

cammodore64

Guest
If you don't compare side-by-side the difference between using and not using the shader, it might be difficult to visually detect any difference. Either set up a toggle button, or take a screenshot of each and compare in an image editor.
I changed the draw event to draw the sprite both with and without the shader and changed the shader to draw every pixel pure red (the original sprite is a grayscale npc figure so the difference should be quite clear) there’s sadly just no change...I really appreciate your help. I’m trying everything I can over here.
 

Posh Indie

That Guy
I changed the shader code to the following:

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

void main() {
// vec4 base_col = v_vColor * texture2D(gm_BaseTexture, v_vTexcoord);

gl_FragColor = vec4.rgba(1.0, 0.0, 0.0, 0.0);
}

I figure the result should have been a solid red box, but again, the sprite just appears unchanged.
Actually, that would be invisible entirely. But regardless, that is not how it should have behaved, haha.
 

Bart

WiseBart
v_vColour and v_vColor are two different variables ;)

Code:
gl_FragColor = vec4.rgba(1.0, 0.0, 0.0, 0.0);
This one is a syntax issue. First construct the vec4, then access its components, like this:
Code:
gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0).rgba;
Although you can just assign the newly created vec4 directly since gl_FragColor is also a vec4:
Code:
gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);
 
C

cammodore64

Guest
Okay, so I made all the little corrections and now I have this:
Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColor;

void main() {
    vec4 color = v_vColor * texture2D(gm_BaseTexture, v_vTexcoord);

    color.r = 1.0;
    color.a = 0.5;
   
    gl_FragColor = color;
}
Still nothing. I feel like I'm going crazy at this point. The vector section of the shader is empty. Am I supposed to include something there? The sprite being tested has it's own texture page. Are there any other checkboxes floating around that I need to check off? Does it matter that I'm using a Mac? I'm completely out of ideas.
 

Bart

WiseBart
That code looks okay, assuming that you use v_vColor in the vertex shader as well (instead of v_vColour).
What code do you have in the vertex shader? (is this what you mean by the vector section of the shader)
 
C

cammodore64

Guest
Yes, I meant vertex shader. Sorry about that. Like I said, there's no code in there since I figured it would only need to use the fragment shader stuff for 2D purposes.
 
Top