Shader showing up in the corner.

C

Charyb

Guest
So basically I'm trying to imitate the overlay effect that Photoshop has. I'm attempting to overlay a background overtop of my game screen.

Basically the shader appears in the top left corner of the screen and is somewhat smaller than the actual screen size. That red square is the background with the overlay effect, but it's drawing in the top left corner of the screen instead of the entire screen like I want:



shd_overlay fragment:
Code:
//
// Overlay Shader
//

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

uniform sampler2D texOverlay;

void main()
{
    vec4 inColor = v_vColour * texture2D(gm_BaseTexture, v_vTexcoord);
    vec4 outColor = vec4(0.0, 0.0, 0.0, inColor.a);
    vec4 overlay = texture2D(texOverlay, v_vTexcoord);
   
    if (inColor.r > 0.5)
    {
        outColor.r = (1.0 - (1.0 - 2.0 * (inColor.r - 0.5)) * (1.0 - overlay.r));
    }
    else
    {
        outColor.r = ((2.0 * inColor.r) * overlay.r);
    }

    if (inColor.g > 0.5)
    {
        outColor.g = (1.0 - (1.0 - 2.0 * (inColor.g - 0.5)) * (1.0 - overlay.g));
    }
    else
    {
        outColor.g = ((2.0 * inColor.g) * overlay.g);
    }

    if (inColor.b > 0.5)
    {
        outColor.b = (1.0 - (1.0 - 2.0 * (inColor.b - 0.5)) * (1.0 - overlay.b));
    }
    else
    {
        outColor.b = ((2.0 * inColor.b) * overlay.b);
    }
    gl_FragColor = mix(outColor, inColor,1.0 - overlay.a);
}
Game Start Event:
Code:
application_surface_draw_enable(false);
global.game_width = 640; //this is view_wview[0]
global.game_height = 384; //this is view_hview[0]

global.pref_width = 1280; //this is view_wport[0]
global.pref_height = 768; //this is view_hport[0]

display_set_gui_size(global.pref_width, global.pref_height);
Create Event:
Code:
shader = shd_overlay;

stage = shader_get_sampler_index(shader, "texOverlay");

bgToDrawOver = bg_overlay_test;
bgTex = background_get_texture(bgToDrawOver); //bg width/height: 1280x768

Draw GUI Event:
Code:
shader_set(shader);
texture_set_stage(stage, bgTex);
draw_surface(application_surface,0,0);
shader_reset();
Not sure why the shader goes to the top left corner of the screen. I've also tried the 'Post Draw' event instead of the 'Draw GUI' event, same thing.

The really strange thing is, if I use another shader: shd_grey which converts the entire texture to greyscale, it covers the screen perfectly. But this shader does not, this shader only covers a portion of the top left corner.
 
Last edited by a moderator:

Becon

Member
Looks like your draw_surface is telling it to draw at 0,0 in your Draw GUI Event. Upper Left corner.
draw_surface(index, x, y);
 
C

Charyb

Guest
Looks like your draw_surface is telling it to draw at 0,0 in your Draw GUI Event. Upper Left corner.
draw_surface(index, x, y);
Yeah it's supposed to be there. I want it to cover the whole screen.

The shader however, is not filling up the entire screen. I think it might have something to do with the background? The background is the exact same as at the viewport though so I'm confused.
 

Becon

Member
I'm not that familiar with shaders...I thought the problem was that it was in upper left. How big is the shader image? Maybe there's nothing to scale the shader itself so it's drawing it's original size but the size is too small? I see you say your background image is the same size as your viewport...what about the image you se for the shader? Again I don't know anything about them so if that's pointed out in the code, sorry for lack of knowledge. =o)~
 

icuurd12b42

TMC Founder
GMC Elder
you need to scale the drawing based on its width and height of the surface and the width and height of the application derived from application_get_position(), whic will give you the x,y to draw from and the xto,yto that define the extent.

Alternatively, since you resized the gui to be a known virtual size, you can scale the drawing of the surface to match the virtual size, same idea, different input values for scaling. ie, using global.pref_width, global.pref_height

Alternatively, you could simply resize the application surface to be the same size as your virtual gui extent and draw the surface not scaled...


3 solutions. good luck
 
Top