RichHopefulComposer
Member
EDITED IN A TLDR AT THE BOTTOM OF THE POST. I actually figured out a way to get all of this working, but I don't understand why - picture of what I changed is at the bottom, but I'd still love if someone could explain to me why the code is working now, because it seems like my old code should've worked, too. Thank you to anyone with an answer or ideas!
Hey guys! Having some trouble with surfaces. I have a basic set up in my "DrawScreen" object's End Draw event:
If I comment out DrawScreen_DrawLighting() or DrawScreen_PostProcessing2(), things work as intended. For whatever reason, they just aren't playing well together! DrawLighting draws copies a transparent surface to my main screen surface to darken the room. PostProcessing2 just has a shader running that draws everything to the left (just for testing purposes). Here are how things look with:
JUST LIGHTING -behaving as expected!
JUST POST PROCESSING - behaving as expected, too!
LIGHTING AND PROCESSING - something's wrong. We've got a weird ghost image going on!
I don't get how this is happening, because in Lighting, I just draw the lighting onto the Screen surface. In post processing, I do some ping ponging to rewrite that screen surface. Maybe I'm doing it wrong?
Here's the code for the three functions called up there:
I'm not sure if I'm missing something silly here, or if there's something weird I don't know about when you ping pong transparent surfaces in GM or something, so I figured I'd ask for some fresh eyes! Thanks as always, everyone! =D
Edit: Okay, I'm doing something stupid with my ping ponging during the PostProcessing() function - right now I'm ping ponging effectSurf2 back onto surfFinishedScreen and then drawing surfFinishedScreen in Draw GUI, and that isn't working. If I skip the ping ponging, and just draw effectSurf2 in Draw GUI, the image displays correctly! I'm sure whatever I'm messing up is really silly now!
tldr: after debugging, it seems like the problem is probably coming from the highlighted code here, but I don't know what's wrong with it:
Edit 2: Problem solved! Recreating surfFinishedScreen before drawing surfEffects onto it fixed the ghosting issue:
I'm still not really sure why, though. I figured it had something to do with drawing onto a "dirty" surface, so I intuitively gave recreating surfFinishedScreen a shot, but I don't understand why that fixed the issue, since I was drawing an opaque (I thought) surface on top of it anyway. If someone could explain why this worked, I'd really appreciate it! Thanks guys!
Hey guys! Having some trouble with surfaces. I have a basic set up in my "DrawScreen" object's End Draw event:
Code:
//All Draw scripts here reset target shader and surface when they're finished running:
DrawScreen_DrawGameField(); //Copies base game from app surface to surfFinishedScreen in correct palette chosen in currentShader.
DrawScreen_DrawLighting(); //Copies surfLighting onto surfFinishedScreen.
DrawScreen_PostProcessing2();
JUST LIGHTING -behaving as expected!
JUST POST PROCESSING - behaving as expected, too!
LIGHTING AND PROCESSING - something's wrong. We've got a weird ghost image going on!
I don't get how this is happening, because in Lighting, I just draw the lighting onto the Screen surface. In post processing, I do some ping ponging to rewrite that screen surface. Maybe I'm doing it wrong?
Here's the code for the three functions called up there:
Code:
function DrawScreen_DrawGameField() //Copies base game from app surface to surfFinishedScreen in correct palette chosen in currentShader. ======================================================
{
surfFinishedScreen = SurfaceCreate(surfFinishedScreen);
surface_set_target(surfFinishedScreen);
shader_set(currentShader);
shaderColorIndexMod = shader_get_uniform(currentShader, "colorIndexMod");
shader_set_uniform_i(shaderColorIndexMod, colorIndexMod);
draw_surface(application_surface, 0, 0);
shader_reset();
surface_reset_target();
}
function DrawScreen_DrawLighting()//==============================================================================================================================================================
{
surfLighting = SurfaceCreate(surfLighting);
if (surfLightingAlphaVariance < -.9)
{
surfLightingAlphaVariance = -.9;
}
draw_set_alpha(surfLightingAlpha + surfLightingAlphaVariance);
surface_set_target(surfFinishedScreen);
draw_surface(surfLighting, 0, 0);
surface_reset_target();
draw_set_alpha(1);
surfLightingAlphaVariance = 0; //this is added to by flames and stuff to create flickers/more light.
//reset it each frame, since every flame in the scene will add to this every frame.
}
function DrawScreen_PostProcessing2() //=========================================================================
{
if(effectShader2 != shader_Passthrough)
{
surfEffects = SurfaceCreate(surfEffects);
switch(effectShader2)
{
case shader_Waves:
draw_set_alpha(1);
surface_set_target(surfEffects);
shader_set(effectShader2);
draw_surface(surfFinishedScreen,0,0);
shader_reset();
surface_reset_target();
surface_set_target(surfFinishedScreen);
draw_surface(surfEffects,0,0);
surface_reset_target();
break;
case shader_Pixelate:
draw_set_alpha(1);
surface_set_target(surfEffects);
shader_set(effectShader2);
u_cellSize = shader_get_uniform(shader_Pixelate,"cellSize");
shader_set_uniform_f(u_cellSize, pixelCellSize);
draw_surface(surfFinishedScreen,0,0);
shader_reset();
surface_reset_target();
surface_set_target(surfFinishedScreen);
draw_surface(surfEffects,0,0);
surface_reset_target();
break;
}
}
}
Edit: Okay, I'm doing something stupid with my ping ponging during the PostProcessing() function - right now I'm ping ponging effectSurf2 back onto surfFinishedScreen and then drawing surfFinishedScreen in Draw GUI, and that isn't working. If I skip the ping ponging, and just draw effectSurf2 in Draw GUI, the image displays correctly! I'm sure whatever I'm messing up is really silly now!
tldr: after debugging, it seems like the problem is probably coming from the highlighted code here, but I don't know what's wrong with it:
Edit 2: Problem solved! Recreating surfFinishedScreen before drawing surfEffects onto it fixed the ghosting issue:
I'm still not really sure why, though. I figured it had something to do with drawing onto a "dirty" surface, so I intuitively gave recreating surfFinishedScreen a shot, but I don't understand why that fixed the issue, since I was drawing an opaque (I thought) surface on top of it anyway. If someone could explain why this worked, I'd really appreciate it! Thanks guys!
Last edited: