diff --git a/assets b/assets index d645f8fd6..718832388 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit d645f8fd60014ea64a595c0c7d0b0b0726d6d068 +Subproject commit 7188323882d99d6cf4de22cd71044fa5164c11ae diff --git a/hmm.json b/hmm.json index 31e88af10..94d782150 100644 --- a/hmm.json +++ b/hmm.json @@ -59,7 +59,7 @@ "name": "flixel-animate", "type": "git", "dir": null, - "ref": "84cd1915161eb49fba33b3f81a8c7ea3f05ae053", + "ref": "c61476f4b3a3d225631ab3065e4e925a4b63c076", "url": "https://github.com/MaybeMaru/flixel-animate" }, { diff --git a/source/funkin/graphics/shaders/DropShadowShader.hx b/source/funkin/graphics/shaders/DropShadowShader.hx index f137c7b94..e3d0d9b7d 100644 --- a/source/funkin/graphics/shaders/DropShadowShader.hx +++ b/source/funkin/graphics/shaders/DropShadowShader.hx @@ -2,115 +2,119 @@ package funkin.graphics.shaders; import flixel.system.FlxAssets.FlxShader; import flixel.util.FlxColor; -import flixel.FlxSprite; +import funkin.graphics.FunkinSprite; import flixel.math.FlxAngle; import flixel.graphics.frames.FlxFrame; import openfl.display.BitmapData; -/* - A shader that aims to *mostly recreate how Adobe Animate/Flash handles drop shadows, but its main use here is for rim lighting. - - Has options for color, angle, distance, and a threshold to not cast the shadow on parts like outlines. - Can also be supplied a secondary mask which can then have an alternate threshold, for when sprites have too many conflicting colors - for the drop shadow to look right (e.g. the tankmen on GF's speakers). - - Also has an Adjust Color shader in here so they can work together when needed. +/** + * A shader that aims to *mostly recreate how Adobe Animate/Flash handles drop shadows, but its main use here is for rim lighting. + * + * Has options for color, angle, distance, and a threshold to not cast the shadow on parts like outlines. + * Can also be supplied a secondary mask which can then have an alternate threshold, for when sprites have too many conflicting colors + * for the drop shadow to look right (e.g. the tankmen on GF's speakers). + * + * Also has an Adjust Color shader in here so they can work together when needed. */ class DropShadowShader extends FlxShader { - /* - The color of the drop shadow. + /** + * The color of the drop shadow. */ public var color(default, set):FlxColor; - /* - The angle of the drop shadow. - - for reference, depending on the angle, the affected side will be: - 0 = RIGHT - 90 = UP - 180 = LEFT - 270 = DOWN + /** + * The angle of the drop shadow. + * + * for reference, depending on the angle, the affected side will be: + * 0 = RIGHT + * 90 = UP + * 180 = LEFT + * 270 = DOWN */ public var angle(default, set):Float; - /* - The distance or size of the drop shadow, in pixels, - relative to the texture itself... NOT the camera. + /** + * The distance or size of the drop shadow, in pixels, + * relative to the texture itself... NOT the camera. */ public var distance(default, set):Float; - /* - The strength of the drop shadow. - Effectively just an alpha multiplier. + /** + * The strength of the drop shadow. + * Effectively just an alpha multiplier. */ public var strength(default, set):Float; - /* - The brightness threshold for the drop shadow. - Anything below this number will NOT be affected by the drop shadow shader. - A value of 0 effectively means theres no threshold, and vice versa. + /** + * The brightness threshold for the drop shadow. + * Anything below this number will NOT be affected by the drop shadow shader. + * A value of 0 effectively means theres no threshold, and vice versa. */ public var threshold(default, set):Float; - /* - The amount of antialias samples per-pixel, - used to smooth out any hard edges the brightness thresholding creates. - Defaults to 2, and 0 will remove any smoothing. + /** + * The amount of antialias samples per-pixel, + * used to smooth out any hard edges the brightness thresholding creates. + * Defaults to 2, and 0 will remove any smoothing. */ public var antialiasAmt(default, set):Float; - /* - Whether the shader should try and use the alternate mask. - False by default. + /** + * Whether the shader should try and use the alternate mask. + * False by default. */ public var useAltMask(default, set):Bool; - /* - The image for the alternate mask. - At the moment, it uses the blue channel to specify what is or isnt going to use the alternate threshold. - (its kinda sloppy rn i need to make it work a little nicer) - TODO: maybe have a sort of "threshold intensity texture" as well? where higher/lower values indicate threshold strength.. + /** + * The image for the alternate mask. + * At the moment, it uses the blue channel to specify what is or isnt going to use the alternate threshold. + * (its kinda sloppy rn i need to make it work a little nicer) + * TODO: maybe have a sort of "threshold intensity texture" as well? where higher/lower values indicate threshold strength.. */ public var altMaskImage(default, set):BitmapData; - /* - An alternate brightness threshold for the drop shadow. - Anything below this number will NOT be affected by the drop shadow shader, - but ONLY when the pixel is within the mask. + /** + * An alternate brightness threshold for the drop shadow. + * Anything below this number will NOT be affected by the drop shadow shader, + * but ONLY when the pixel is within the mask. */ public var maskThreshold(default, set):Float; - /* - The FlxSprite that the shader should get the frame data from. - Needed to keep the drop shadow shader in the correct bounds and rotation. + /** + * The FunkinSprite that the shader should get the frame data from. + * Needed to keep the drop shadow shader in the correct bounds and rotation. */ - public var attachedSprite(default, set):FlxSprite; + public var attachedSprite(default, set):FunkinSprite; - /* - The hue component of the Adjust Color part of the shader. + /** + * The hue component of the Adjust Color part of the shader. */ public var baseHue(default, set):Float; - /* - The saturation component of the Adjust Color part of the shader. + /** + * The saturation component of the Adjust Color part of the shader. */ public var baseSaturation(default, set):Float; - /* - The brightness component of the Adjust Color part of the shader. + /** + * The brightness component of the Adjust Color part of the shader. */ public var baseBrightness(default, set):Float; - /* - The contrast component of the Adjust Color part of the shader. + /** + * The contrast component of the Adjust Color part of the shader. */ public var baseContrast(default, set):Float; - /* - Sets all 4 adjust color values. + /** + * Sets all 4 adjust color values. + * @param b The brightness value + * @param h The hue value + * @param c The contrast value + * @param s The saturation value */ - public function setAdjustColor(b:Float, h:Float, c:Float, s:Float) + public function setAdjustColor(b:Float, h:Float, c:Float, s:Float):Void { baseBrightness = b; baseHue = h; @@ -189,18 +193,28 @@ class DropShadowShader extends FlxShader return val; } - function set_attachedSprite(spr:FlxSprite):FlxSprite + function set_attachedSprite(spr:FunkinSprite):FunkinSprite { attachedSprite = spr; updateFrameInfo(attachedSprite.frame); + + // Enable render texture for texture atlas sprites + // This allows the shader to work properly on them + if (attachedSprite.isAnimate && !attachedSprite.useRenderTexture) + { + attachedSprite.useRenderTexture = true; + } + return spr; } - /* - Loads an image for the mask. - While you *could* directly set the value of the mask, this function works for both HTML5 and native targets. + /** + * Loads an image for the mask. + * While you *could* directly set the value of the mask, this function works for both HTML5 and native targets. + * + * @param path The path to the image to load */ - public function loadAltMask(path:String) + public function loadAltMask(path:String):Void { #if html5 BitmapData.loadFromFile(path).onComplete(function(bmp:BitmapData) { @@ -211,19 +225,24 @@ class DropShadowShader extends FlxShader #end } - /* - Should be called on the animation.callback of the attached sprite. - TODO: figure out why the reference to the attachedSprite breaks on web?? + /** + * Should be called on the animation.callback of the attached sprite. + * TODO: figure out why the reference to the attachedSprite breaks on web?? + * + * @param name The name of the animation + * @param frameNum The current frame number + * @param frameIndex The current frame index */ - public function onAttachedFrame(name, frameNum, frameIndex) + public function onAttachedFrame(name:String, frameNum:Int, frameIndex:Int):Void { if (attachedSprite != null) updateFrameInfo(attachedSprite.frame); } - /* - Updates the frame bounds and angle offset of the sprite for the shader. + /** + * Updates the frame bounds and angle offset of the sprite for the shader + * @param frame The frame to retrieve the information from */ - public function updateFrameInfo(frame:FlxFrame) + public function updateFrameInfo(frame:FlxFrame):Void { // NOTE: uv.right is actually the right pos and uv.bottom is the bottom pos uFrameBounds.value = [frame.uv.left, frame.uv.top, frame.uv.right, frame.uv.bottom]; @@ -232,12 +251,6 @@ class DropShadowShader extends FlxShader angOffset.value = [frame.angle * FlxAngle.TO_RAD]; } - public function updateFrameInfoSimple(width:Float, height:Float, angle:Float):Void - { - uFrameBounds.value = [0, 0, width, height]; - angOffset.value = [angle * FlxAngle.TO_RAD]; - } - function set_altMaskImage(_bitmapData:BitmapData):BitmapData { altMask.input = _bitmapData; @@ -408,7 +421,8 @@ class DropShadowShader extends FlxShader vec2 imageRatio = vec2(1.0/openfl_TextureSize.x, 1.0/openfl_TextureSize.y); // check the pixel in the direction and distance specified - vec2 checkedPixel = vec2(openfl_TextureCoordv.x + (dist * cos(ang + angOffset) * imageRatio.x), openfl_TextureCoordv.y - (dist * sin(ang + angOffset) * imageRatio.y)); + vec2 checkedPixel = vec2(openfl_TextureCoordv.x + (dist * cos(ang + angOffset) * imageRatio.x), + openfl_TextureCoordv.y - (dist * sin(ang + angOffset) * imageRatio.y)); // multiplier for the intensity of the drop shadow float dropShadowAmount = 0.0;