Skip to content

Commit

Permalink
improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Geokureli committed Aug 8, 2023
1 parent 1e21691 commit 347e5b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 16 additions & 11 deletions Effects/DynamicShadows/source/PlayStateShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@ class PlayStateShader extends PlayState

override function createCams()
{
// FlxG.camera draws the actual world. In this case, that means the background
final mainCam = FlxG.camera;
mainCam.bgColor = 0x5a81ad;
gem.camera = mainCam;
background.camera = mainCam;
FlxG.cameras.setDefaultDrawTarget(mainCam, false);
// FlxG.camera draws the actual world. In this case, that means the background and the gem
// Note, the shader also draws this cam, so in the end this camera is completely covered by shaderCam
final bgCam = FlxG.camera;
bgCam.bgColor = 0x5a81ad;
gem.camera = bgCam;
background.camera = bgCam;
FlxG.cameras.setDefaultDrawTarget(bgCam, false);

// shaderCam draws casted shadows from everything drawn to it, these draw above FlxG.camera
// In this case that means everything except ui and the background
/* shaderCam draws the foreground elements (except the gem), then passes that as input to
* the shader along with the bg camera, the fg is used to cast shadows on the bg
* In this case that means everything except the gem, ui and background
*/
shaderCam = new FlxCamera(0, 0, FlxG.width, FlxG.height);
FlxG.cameras.add(shaderCam);
shaderCam.bgColor = 0x0;
shader = new Shader();
mainCam.buffer = new BitmapData(mainCam.width, mainCam.height);
shader.bgImage.input = mainCam.buffer;
// add the bg camera as an image to the shader so we can add color effects to it
bgCam.buffer = new BitmapData(bgCam.width, bgCam.height);
shader.bgImage.input = bgCam.buffer;
shaderCam.setFilters([new openfl.filters.ShaderFilter(shader)]);

// draws anything above the sahdows, in this case infoText
// draws anything above the shadows, in this case infoText
uiCam = new FlxCamera(0, 0, FlxG.width, FlxG.height);
FlxG.cameras.add(uiCam, false);
uiCam.bgColor = 0x0;
Expand All @@ -51,6 +55,7 @@ class PlayStateShader extends PlayState
{
super.draw();

// draw the camera's canvas to it's buffer so it shows up in the shader
drawCameraBuffer(FlxG.camera);
}

Expand Down
2 changes: 1 addition & 1 deletion Effects/DynamicShadows/source/Shader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Shader extends flixel.system.FlxAssets.FlxShader
vec3 add = fg.rgb + glowRgb;
return vec4((mult + add)/2.0, fg.a);
}
const vec3 unshadedRgb = vec3(0.6, 0.6, 1.0);
const vec4 shadeColor = vec4(0.0, 0.0, 0.4, 0.6);
const vec4 bgGlow = vec4(1.0, 0.125, 0.0, 0.25);
Expand All @@ -81,7 +82,6 @@ class Shader extends flixel.system.FlxAssets.FlxShader
float shadowAmount = getShadow(uv);
float glowAmount = getGlow(uv);
// gl_FragColor = applyBgGlow(bg, shadowAmount, glowAmount);
gl_FragColor = mix(applyBgGlow(bg, shadowAmount, glowAmount), applyFgGlow(fg, glowAmount), fg.a);
}
')
Expand Down

0 comments on commit 347e5b3

Please sign in to comment.