• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Black/White Alpha/Clipping Masks to COMBINE Surfaces??

A

Anomaly

Guest
Hi
I've been researching alot about using black and white images as alphas to designate which areas of an entire surface that's drawn, is to be shown, AND the EXACT OPPOSITE for another surface to be drawn.

meaning...
my current example:
for one scene,
I am using a gaussian blur shader to blur the entire screen of the game... but the goal is not to blur the entire screen...

I have a black and white image (PNG) of a fuzzy edged circle like a vignette..

i'd like the white center of the "alpha mask" black and white vignette.. to ALLOW the original NON-BLURRED application screen through..
...yet have the BLACK outer areas be where the gaussian shader is allowed to be drawn.


i have every other type of mask available with transparent center.. transparent outer rim.. white inner.. black inner etc.. that i can use if need be.

i've been reading alot on the forum as much as i can about it..

someone (forgot whom..)
said to :
Create the surface
Clear it with 0,0
disable alpha channel
Draw the sprite
disable RGB colour channels
draw the alpha colour mask
re-enable all colour channels.
i was doing that doing this....
Code:
//***Do horizontal blur first
surface_set_target(final_surface);//    1
if shader_enabled shader_set(shd_gaussian_horizontal);
    shader_set_uniform_f(uni_resolution_hoz, var_resolution_x, var_resolution_y);
    shader_set_uniform_f(uni_blur_amount_hoz, var_blur_amount);
    
draw_clear_alpha(c_black,0);//    2
gpu_set_colorwriteenable(true,true,true,false);//    3
draw_set_alpha(0);

draw_surface(surf,0,0);//              4
gpu_set_blendenable(false)
gpu_set_colorwriteenable(false,false,false,true); // 5

draw_set_alpha(1);

gpu_set_blendenable(true);
draw_sprite(spr_Blur_Vignette1_Inverse,0,0,0);// 6


gpu_set_colorwriteenable(true,true,true,true);//    3

shader_reset();
surface_reset_target();
then there's this... which i think is exactly what i want but don't know how to implement it...
"gpu_set_blendmode_ext_sepalpha"

DukeSoft here... got it right...
https://forum.yoyogames.com/index.php?threads/drawing-alpha-blended-sprites-on-surface.11442/
but didn't go into depth as to what he had set up originally..

i am thinking there's a simpler method to achieve these results like Mike does here....
https://www.yoyogames.com/blog/430/dynamic-rendering-masks


also if i am successful with this.. should i see the application screen show underneath it automatically or do i have to do a reverse version of this achieve that?
 
A

Anomaly

Guest
ok HERE is exactly what I mean....
I have the regular output of the game... that's in focus..


then i have another potential output that's affected by a gaussian blur shader on a surface in a GUI draw event of an invisible object...
like this..


by using a black and white OR transparent - to- black, or transparent -to - white.. faded "FEATHERED" image..like this...


i would like to get THIS type of result ...


this shouldn't be super difficult right?

i've tried for over 24 hours trying all sorts of different methods people have shared over the years...
nothing is working..
i'm still learning surfaces.. so 'm pretty sure i'm missing some things...
i need to know how to do exactly this...

does the alpha clip mask HAVE to be a sprite? or can it be drawn?


THANKS!!
 
Send me the vertex & fragment shader code and I'll try to get that vignette into there instead of using a surface. No promise I can do it though - still learning :)
 
A

Anomaly

Guest
I
Send me the vertex & fragment shader code and I'll try to get that vignette into there instead of using a surface. No promise I can do it though - still learning :)
Hi, thanks for replying.
I'm using the gausian blur object in this pack...
https://marketplace.yoyogames.com/assets/261/free-shaders
i've been messing with the GUI draw event.. splitting it up into scripts and trying to somehow have the "focused" version come through the middle.. or any other type of alpha mask i choose..
thanks for any effort!
 

Bingdom

Googledom
Shader challenge... Challenge accepted!

----

It was easier than I thought. There is a limitation though, you must check use for 3D in order for this shader to work.upload_2017-10-9_14-1-54.png

Create a new object. Inside this object, put:
Create event:
Code:
vigHor = shader_get_sampler_index(shd_gaussian_horizontal,"vignette");
vigVer = shader_get_sampler_index(shd_gaussian_vertical,"vignette");

vigTex = sprite_get_texture(s_vignette,0);

uni_resolution_hoz = shader_get_uniform(shd_gaussian_horizontal,"resolution");
uni_resolution_vert = shader_get_uniform(shd_gaussian_vertical,"resolution");
var_resolution_x = view_wview;
var_resolution_y = view_hview;

uni_blur_amount_hoz = shader_get_uniform(shd_gaussian_vertical,"blur_amount");
uni_blur_amount_vert = shader_get_uniform(shd_gaussian_horizontal,"blur_amount");
var_blur_amount = 4.0;

surf = surface_create(sprite_get_width(s_flower),sprite_get_height(s_flower)); //Must be a power of 2
The main change I did with the create event from the shader marketplace asset is the surface size, getting sampler uniform handle indexes and getting the texture index for s_vignette.

Draw event:
Code:
//Do horizontal blur first
surface_set_target(surf);
shader_set(shd_gaussian_horizontal);
    shader_set_uniform_f(uni_resolution_hoz, var_resolution_x, var_resolution_y);
    shader_set_uniform_f(uni_blur_amount_hoz, var_blur_amount);
    texture_set_stage(vigHor, vigTex);
    draw_sprite(s_flower,0,0,0);
shader_reset();
surface_reset_target();

//Do vertical blur last
shader_set(shd_gaussian_vertical);
    shader_set_uniform_f(uni_resolution_vert, var_resolution_x, var_resolution_y);
    shader_set_uniform_f(uni_blur_amount_vert, var_blur_amount);
    texture_set_stage(vigVer, vigTex);
    draw_surface(surf,0,0);
shader_reset();
With the draw event, I removed the second surface and passed in the s_vignette texture to the shader.

Then for the 2 shaders add this on the top of both of them
Code:
//Get the vignette
uniform sampler2D vignette;
This allows me to pass in a texture to the shader

Then this line for both of them, replace this line
Code:
gl_FragColor = sum;
To this line
Code:
vec4 base = texture2D(vignette, v_texcoord);
float value = (base.r + base.g + base.b) / 3.0; //If the colour is white, then apply the shader
gl_FragColor = mix(sum,texture2D(gm_BaseTexture,v_texcoord),value);
Basically, if there is a white pixel located on the vignette, the shader will be applied to the base texture.

Result:
upload_2017-10-9_14-25-11.png
 
Last edited:
A

Anomaly

Guest
Shader challenge... Challenge accepted!

----

It was easier than I thought. There is a limitation though, you must check use for 3D in order for this shader to work.View attachment 13357

Create a new object. Inside this object, put:
Create event:
Code:
vigHor = shader_get_sampler_index(shd_gaussian_horizontal,"vignette");
vigVer = shader_get_sampler_index(shd_gaussian_vertical,"vignette");

vigTex = sprite_get_texture(s_vignette,0);

uni_resolution_hoz = shader_get_uniform(shd_gaussian_horizontal,"resolution");
uni_resolution_vert = shader_get_uniform(shd_gaussian_vertical,"resolution");
var_resolution_x = view_wview;
var_resolution_y = view_hview;

uni_blur_amount_hoz = shader_get_uniform(shd_gaussian_vertical,"blur_amount");
uni_blur_amount_vert = shader_get_uniform(shd_gaussian_horizontal,"blur_amount");
var_blur_amount = 4.0;

surf = surface_create(sprite_get_width(s_flower),sprite_get_height(s_flower)); //Must be a power of 2
The main change I did with the create event from the shader marketplace asset is the surface size, getting sampler uniform handle indexes and getting the texture index for s_vignette.

Draw event:
Code:
//Do horizontal blur first
surface_set_target(surf);
shader_set(shd_gaussian_horizontal);
    shader_set_uniform_f(uni_resolution_hoz, var_resolution_x, var_resolution_y);
    shader_set_uniform_f(uni_blur_amount_hoz, var_blur_amount);
    texture_set_stage(vigHor, vigTex);
    draw_sprite(s_flower,0,0,0);
shader_reset();
surface_reset_target();

//Do vertical blur last
shader_set(shd_gaussian_vertical);
    shader_set_uniform_f(uni_resolution_vert, var_resolution_x, var_resolution_y);
    shader_set_uniform_f(uni_blur_amount_vert, var_blur_amount);
    texture_set_stage(vigVer, vigTex);
    draw_surface(surf,0,0);
shader_reset();
With the draw event, I removed the second surface and passed in the s_vignette texture to the shader.

Then for the 2 shaders add this on the top of both of them
Code:
//Get the vignette
uniform sampler2D vignette;
This allows me to pass in a texture to the shader

Then this line for both of them, replace this line
Code:
gl_FragColor = sum;
To this line
Code:
vec4 base = texture2D(vignette, v_texcoord);
float value = (base.r + base.g + base.b) / 3.0; //If the colour is white, then apply the shader
gl_FragColor = mix(sum,texture2D(gm_BaseTexture,v_texcoord),value);
Basically, if there is a white pixel located on the vignette, the shader will be applied to the base texture.

Result:
View attachment 13358
NOW THAT'S WHAT IM TALKIN' uhBOUTst!!
awesome. I shall implement it immediately Good Sir.
Thank you very much.
I'll post some results.

I'll get into learning the high degrees of shader code some day!

...P.S. .. have you ever gotten the"shockwave" item in that pack to work?
 
Last edited by a moderator:
A

Anomaly

Guest
I had a quick play around beforehand. You're meant to click on the screen.
Yeah I think I have some unintended mouse offsetting going on because I only see the waves coming in from a distance after awhile from outside the screen.
I'll just have to test it in a fresh project.

...Are there any "live hangouts" with GM? I used to use IRC back in the day...
 

Bingdom

Googledom
Squarebit is hosting a large discord server that's designed mainly for socializing. It's a bit strict to join, just make sure you read all the rules. I will be back on that server once I've finished my final exams.
Link to topic
 
A

Anomaly

Guest
cool.
exactly where are the dual: ( gl_FragColor = sum;" )'s ?
 

Bingdom

Googledom
There's only one of them in each shader, but there's two shaders which do a very similar thing which you need to adjust.

gl_FragColor = sum; should be located near the bottom of the shader.
 
T

Tristan

Guest
can someone tell me how to make a new forum post? I've been searching everywhere
 
A

Anomaly

Guest
There's only one of them in each shader, but there's two shaders which do a very similar thing which you need to adjust.

gl_FragColor = sum; should be located near the bottom of the shader.
Hah! Wooops! ACTUALLY in the file in internet explorer...I was looking in the resource tree of GMS..
 
Since Bingdom covered a version with a mask I thought I'll cover a version without and use corner id and vignette code instead (mainly as an excerise for myself since I think the problem is solved already). Not really happy about performance, but it's advantage is it's flexibilty.

vignetteblur.jpg

Here's a link to a demo:
https://www.dropbox.com/s/2dagw6np6abqy8f/VignetteBlur.exe?dl=0

And here the project file:
https://www.dropbox.com/s/rbidhv55ea4h7k4/VignetteBlur.gmz?dl=0

If you're using this in GMS2 and the vignette isn't working, change this line:
cornerCoord.y = corner_red - 0.5;

to this:
cornerCoord.y = corner_blue - 0.5;

in BOTH vertex shaders.

edit: btw: the corner id is only in there in case this is used on a sprite. The surface wouldn't need it since its coordinates go from 0 to 1 anyways. I re-uploaded the project file and marked everything that can be removed with *** if you're using this shader on surfaces only. Except one commented-out line in both fragment shaders. That one needs to be active then.
 
Last edited:
A

Anomaly

Guest
Since Bingdom covered a version with a mask I thought I'll cover a version without and use corner id and vignette code instead (mainly as an excerise for myself since I think the problem is solved already). Not really happy about performance, but it's advantage is it's flexibilty.

View attachment 13377

Here's a link to a demo:
https://www.dropbox.com/s/2dagw6np6abqy8f/VignetteBlur.exe?dl=0

And here the project file:
https://www.dropbox.com/s/rbidhv55ea4h7k4/VignetteBlur.gmz?dl=0

If you're using this in GMS2 and the vignette isn't working, change this line:
cornerCoord.y = corner_red - 0.5;

to this:
cornerCoord.y = corner_blue - 0.5;

in BOTH vertex shaders.
:cool: i find the lack of a "WOW!" emoji disturbing.
super cool!

my first project i have been working on is cartoonish side-scroller platformer puzzle/action game but my background is in cg animation and visual effects so i love things like this that open up the potential of GMS to new levels of possibility for later projects!
 
A

Anomaly

Guest
Shader challenge... Challenge accepted!

----

It was easier than I thought. There is a limitation though, you must check use for 3D in order for this shader to work.View attachment 13357

Create a new object. Inside this object, put:
Create event:
Code:
vigHor = shader_get_sampler_index(shd_gaussian_horizontal,"vignette");
vigVer = shader_get_sampler_index(shd_gaussian_vertical,"vignette");

vigTex = sprite_get_texture(s_vignette,0);

uni_resolution_hoz = shader_get_uniform(shd_gaussian_horizontal,"resolution");
uni_resolution_vert = shader_get_uniform(shd_gaussian_vertical,"resolution");
var_resolution_x = view_wview;
var_resolution_y = view_hview;

uni_blur_amount_hoz = shader_get_uniform(shd_gaussian_vertical,"blur_amount");
uni_blur_amount_vert = shader_get_uniform(shd_gaussian_horizontal,"blur_amount");
var_blur_amount = 4.0;

surf = surface_create(sprite_get_width(s_flower),sprite_get_height(s_flower)); //Must be a power of 2
The main change I did with the create event from the shader marketplace asset is the surface size, getting sampler uniform handle indexes and getting the texture index for s_vignette.

Draw event:
Code:
//Do horizontal blur first
surface_set_target(surf);
shader_set(shd_gaussian_horizontal);
    shader_set_uniform_f(uni_resolution_hoz, var_resolution_x, var_resolution_y);
    shader_set_uniform_f(uni_blur_amount_hoz, var_blur_amount);
    texture_set_stage(vigHor, vigTex);
    draw_sprite(s_flower,0,0,0);
shader_reset();
surface_reset_target();

//Do vertical blur last
shader_set(shd_gaussian_vertical);
    shader_set_uniform_f(uni_resolution_vert, var_resolution_x, var_resolution_y);
    shader_set_uniform_f(uni_blur_amount_vert, var_blur_amount);
    texture_set_stage(vigVer, vigTex);
    draw_surface(surf,0,0);
shader_reset();
With the draw event, I removed the second surface and passed in the s_vignette texture to the shader.

Then for the 2 shaders add this on the top of both of them
Code:
//Get the vignette
uniform sampler2D vignette;
This allows me to pass in a texture to the shader

Then this line for both of them, replace this line
Code:
gl_FragColor = sum;
To this line
Code:
vec4 base = texture2D(vignette, v_texcoord);
float value = (base.r + base.g + base.b) / 3.0; //If the colour is white, then apply the shader
gl_FragColor = mix(sum,texture2D(gm_BaseTexture,v_texcoord),value);
Basically, if there is a white pixel located on the vignette, the shader will be applied to the base texture.

Result:
View attachment 13358

hey so i'm finally getting some time to try to get this to work...
i did everything, and i'm getting the error messages:
Fragment Shader: shd_gaussian_vertical at line 27 : 'value'
Vertex Shader: shd_gaussian_horizontal at line 15 : ''
here's my shd_gaussian_vertical.fsh file contents
(which i opened, changed and saved in window's Notepad):
Code:
//Get the vignette
uniform sampler2D vignette;

varying vec2 v_texcoord;

uniform float time;
uniform vec2 mouse_pos;
uniform vec2 resolution;
uniform float blur_amount;

void main()
{
float blurSize = 1.0/resolution.y * blur_amount;

   vec4 sum = vec4(0.0);
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y- 4.0*blurSize)) * 0.05;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y- 3.0*blurSize)) * 0.09;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y - 2.0*blurSize)) * 0.12;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y - blurSize)) * 0.15;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y)) * 0.16;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y + blurSize)) * 0.15;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y + 2.0*blurSize)) * 0.12;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y + 3.0*blurSize)) * 0.09;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y + 4.0*blurSize)) * 0.05;
   gl_FragColor = mix(sum,texture2D(gm_BaseTexture,v_texcoord),value);

//gl_FragColor = sum;
}

and the horizontal:
Code:
//Get the vignette
uniform sampler2D vignette;
varying vec2 v_texcoord;

uniform float time;
uniform vec2 mouse_pos;
uniform vec2 resolution;
uniform float blur_amount;

void main()
{
float blurSize = 1.0/resolution.x * blur_amount;

   vec4 sum = vec4(0.0);
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x - 4.0*blurSize, v_texcoord.y)) * 0.05;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x - 3.0*blurSize, v_texcoord.y)) * 0.09;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x - 2.0*blurSize, v_texcoord.y)) * 0.12;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x - blurSize, v_texcoord.y)) * 0.15;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x, v_texcoord.y)) * 0.16;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x + blurSize, v_texcoord.y)) * 0.15;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x + 2.0*blurSize, v_texcoord.y)) * 0.12;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x + 3.0*blurSize, v_texcoord.y)) * 0.09;
   sum += texture2D(gm_BaseTexture, vec2(v_texcoord.x + 4.0*blurSize, v_texcoord.y)) * 0.05;
   vec4 base = texture2D(vignette, v_texcoord); float value = (base.r + base.g + base.b) / 3.0;
   //If the colour is white, then apply the shader
   gl_FragColor = mix(sum,texture2D(gm_BaseTexture,v_texcoord),value);

//gl_FragColor = sum;
}

i do not have a "used for 3d" checkbox (to my knowledge) on anything... I'm using GMS2.

also... in the code you've supplied for the Create Event of the object I make...
Code:
surf = surface_create
(sprite_get_width(s_flower),sprite_get_height(s_flower)); //Must be a power of 2
if i don't want just the picture of flowers from my post to be used..
and instead actually have it use gameplay..
would the original code that came with the pack work?... (this requires their scripts that came with them to be used...
"
Code:
surf = surface_create(__view_get( e__VW.WView, 0 ), __view_get( e__VW.HView, 0 ));
__view_set( e__VW.SurfaceID, 0, surf );
or i should use something else.. like just use "camera_get_view_width()" etc to set up the variables of a surface made from gameplay? ..if i dont' want to have to include the scripts from the pack?

trying to get this baby to function!
 
A

Anomaly

Guest
Since Bingdom covered a version with a mask I thought I'll cover a version without and use corner id and vignette code instead (mainly as an excerise for myself since I think the problem is solved already). Not really happy about performance, but it's advantage is it's flexibilty.

View attachment 13377

Here's a link to a demo:
https://www.dropbox.com/s/2dagw6np6abqy8f/VignetteBlur.exe?dl=0

And here the project file:
https://www.dropbox.com/s/rbidhv55ea4h7k4/VignetteBlur.gmz?dl=0

If you're using this in GMS2 and the vignette isn't working, change this line:
cornerCoord.y = corner_red - 0.5;

to this:
cornerCoord.y = corner_blue - 0.5;

in BOTH vertex shaders.

edit: btw: the corner id is only in there in case this is used on a sprite. The surface wouldn't need it since its coordinates go from 0 to 1 anyways. I re-uploaded the project file and marked everything that can be removed with *** if you're using this shader on surfaces only. Except one commented-out line in both fragment shaders. That one needs to be active then.

that is pretty impressive.!
cool to see the flexibility of the changeable controls.
is this only used for the vignette function( ie: outer square to inner circle) or could it effect any other types of shapes of affected area?


also is the number in the top left frames per second? the first two digits being the amount per second?
 
Last edited by a moderator:

Bingdom

Googledom
At the end of the sum+= column, you should have
Code:
vec4 base = texture2D(vignette, v_texcoord);
float value = (base.r + base.g + base.b) / 3.0; //If the colour is white, then apply the shader
gl_FragColor = mix(sum,texture2D(gm_BaseTexture,v_texcoord),value);
That^
It looks you only put in 1/3 and 2/3 of the lines

would the original code that came with the pack work?... (this requires their scripts that came with them to be used...
It will, you just have to add a few more things.

The things that I changed (that I mentioned earlier) is what you should put in the current scripts.

For the create event:
Code:
vigHor = shader_get_sampler_index(shd_gaussian_horizontal,"vignette");
vigVer = shader_get_sampler_index(shd_gaussian_vertical,"vignette");
vigTex = sprite_get_texture(s_vignette,0);
For the horizontal drawing and
Code:
texture_set_stage(vigHor, vigTex);
this is for the vertical drawing
Code:
texture_set_stage(vigVer, vigTex);
They should be placed with all the shader_set_uniform() functions, inbetween shader_set() and draw_surface().
 
Last edited:
is this only used for the vignette function( ie: outer square to inner circle) or could it effect any other types of shapes of affected area?
The code will only calculate a smooth oval in the same ratio as the sprite or surface is. That's where your first idea and Bingdoms version using a mask have an advantage: You can just draw a different mask however you want. But implementing masks that keep their ratio and can used on any sprite size on any texture page ration (they're not always square) is tricky.

In my tutorial series on shaders (just started the series yesterday, link in the signature) I'll eventually get to that topic. It will be covered in the tutorial on Luma Masks. But that's still several weeks in the future and I haven't even completely finished the code to work with any sprite/surface ratio and any mask ratio. If you're interested, just follow the link, subscribe to the channel and activate notifications to get informed whenever I upload a new tutorial.
 
A

Anomaly

Guest
something real strange is going on wqith my notepad saving of the fsh file i thinki.. .

keep getting an error...
Vertex Shader: shd_gaussian_horizontal at line 15 : but with a strange circle.. that won't come up in this text here..
edit: i replaced the file and it was fixed...
it was the " shd_gaussian_horizontal.vsh " file that i had opened and closed in notepad unaltered.. somehow some weird invisible character was saved in there or maybe it didn't like UNICODE or ANSI or something...

anyway...
 
Last edited by a moderator:
A

Anomaly

Guest
At the end of the sum+= column, you should have
Code:
vec4 base = texture2D(vignette, v_texcoord);
float value = (base.r + base.g + base.b) / 3.0; //If the colour is white, then apply the shader
gl_FragColor = mix(sum,texture2D(gm_BaseTexture,v_texcoord),value);
That^
It looks you only put in 1/3 and 2/3 of the lines


It will, you just have to add a few more things.

The things that I changed (that I mentioned earlier) is what you should put in the current scripts.

For the create event:
Code:
vigHor = shader_get_sampler_index(shd_gaussian_horizontal,"vignette");
vigVer = shader_get_sampler_index(shd_gaussian_vertical,"vignette");
vigTex = sprite_get_texture(s_vignette,0);
For the drawing, just put
Code:
texture_set_stage(vigHor, vigTex);
with all the shader_set_uniform() functions, inbetween shader_set() and draw_surface().

yep made all those changes... errrors are gone..but i'm just wondering how we do this to the actual gameplay.. and not a picture of flowers...(they were just examples not the intended result)...

i have this line in the horizontal blurring part of the draw event...
Code:
draw_sprite(s_flower,0,0,0);

and haven't the slightest idea as to what should go there...

so as to get gameplay... as the half/ blurred result... not.. flowers..
 

Bingdom

Googledom
I made a mistake on my other post. See edit.

Do this:
  1. Implement marketplace assets to your current project, then edit it to your needs.
  2. Then apply the changes I've mentioned earlier. (Think of it as an update)
 
Last edited:
A

Anomaly

Guest
I made a mistake on my other post. See edit.

Do this:
  1. Implement marketplace assets to your current project, then edit it to your needs.
  2. Then apply the changes I've mentioned earlier. (Think of it as an update)
so after doing that... GM will still be asking for an "s_flower" sprite that doesn't exist right?
 
A

Anomaly

Guest
No. It would be asking for a s_vignette sprite if you haven't named it like that. Just follow post #21
So in your changes, find where you put the terms "s_vignette" AND "s_flower" ...and change them BOTH to the name of the vignette sprite I am using (same as one I posted above) correct?

(I call it "spr_Blur_Vignette_Black_to_White" since I have other vignette graphics for completely different things than this.)
 

Bingdom

Googledom
So in your changes, find where you put the terms "s_vignette" AND "s_flower" ...and change them BOTH to the name of the vignette sprite I am using (same as one I posted above) correct?

(I call it "spr_Blur_Vignette_Black_to_White" since I have other vignette graphics for completely different things than this.)
No. There should be no s_flower anywhere. Doesn't the default script draw to a surface which covers the whole screen?
 
A

Anomaly

Guest
ok so the only changes for the Create and GUI draw events on the original pack's code should be...
For the create event:
Code:
vigHor = shader_get_sampler_index(shd_gaussian_horizontal,"vignette");
vigVer = shader_get_sampler_index(shd_gaussian_vertical,"vignette");
vigTex = sprite_get_texture(s_vignette,0);
For the horizontal drawing and
Code:
texture_set_stage(vigHor, vigTex);
this is for the vertical drawing
Code:
texture_set_stage(vigVer, vigTex);
They should be placed with all the shader_set_uniform() functions, inbetween shader_set() and draw_surface().
the above having replaced "s_vignette" with the name of the sprite one would be using...

and then for the shaders...
Then for the 2 shaders add this on the top of both of them
Code:
//Get the vignette
uniform sampler2D vignette;
This allows me to pass in a texture to the shader

Then this line for both of them, replace this line
Code:
gl_FragColor = sum;
To this line
Code:
vec4 base = texture2D(vignette, v_texcoord);
float value = (base.r + base.g + base.b) / 3.0; //If the colour is white, then apply the shader
gl_FragColor = mix(sum,texture2D(gm_BaseTexture,v_texcoord),value);
Basically, if there is a white pixel located on the vignette, the shader will be applied to the base texture.
Correct?
 
Last edited by a moderator:

Bingdom

Googledom
Hmm. Maybe I'm a bit unclear... :(

Do only what is under this line
---------------------------------------------------------
Shader from the marketplace asset
At the top of both shaders, put this line
Code:
uniform sampler2D vignette;
Near the bottom of the shader replace this line
Code:
gl_FragColor = sum;
to this
Code:
vec4 base = texture2D(vignette, v_texcoord);
float value = (base.r + base.g + base.b) / 3.0; //If the colour is white, then apply the shader
gl_FragColor = mix(sum,texture2D(gm_BaseTexture,v_texcoord),value);
Do that for both shaders.

Object from the marketplace asset.
For the create event, add this:
Code:
vigHor = shader_get_sampler_index(shd_gaussian_horizontal,"vignette");
vigVer = shader_get_sampler_index(shd_gaussian_vertical,"vignette");
vigTex = sprite_get_texture(s_vignette,0);
Draw event:
You can see that there's comments. One says horizontal, the other says vertical.
For the horizontal drawing*
Code:
texture_set_stage(vigHor, vigTex);
For is for the vertical drawing*
Code:
texture_set_stage(vigVer, vigTex);
*They should be placed with all the shader_set_uniform() functions, inbetween shader_set() and draw_surface(). Should only be one of them for each shader_set(). Place them accordingly.

The shader will not work properly without these changes. You need to pass in the vignette mask for the shader to read.
 
Last edited:
A

Anomaly

Guest
yep all that was read loud and clear before.. just making sure..
edited that last post probably after you saw the first one.. apologies..
got it working..
however there are some strange artifacts going on
i took a video and am uploading now i'll show you.
 
A

Anomaly

Guest
so the first frame of the game when it starts...gets captured somehow and appears as a faded ghost image that affects the blurring. this may be because certain parts of my game are straight WHITE.. like the cartoon shack you see..
i'll circle the area of the screen where it's ghost image appears and how it makes the rock tiles go unblurred..

when my character jumps.. it triggers the original pack's gaussian object spacebar up event which toggles the shader on or off..so you can see when it's on or off.

There's also ghosting on the far right of the screen (hard to see in video compression)...a stack of images of the ball-bullet that the player shoots ...even if he hadn't shot any yet in the game...odd..

the vignette also seems to be shifted at least 900 pixels upward on the Y axis, because the only things that are un-blurred when it's on.. are things towards the upper center of the screen..

heres the video...
plz excuse the player physics and controls.. (he's going through some experimental upgrades hah)

Do you have any idea how these artifacts could be fixed?

i really appreciate your help and patience with this.. it's been great!
 
Last edited by a moderator:
Top