faint-toothbrush-51643
02/05/2023, 9:56 PMgifted-whale-78169
02/05/2023, 10:04 PMfaint-toothbrush-51643
02/05/2023, 10:32 PMgifted-whale-78169
02/05/2023, 10:32 PMfaint-toothbrush-51643
02/05/2023, 10:33 PMgifted-whale-78169
02/05/2023, 10:33 PMgifted-whale-78169
02/05/2023, 10:34 PMfaint-toothbrush-51643
02/05/2023, 10:43 PMfaint-toothbrush-51643
02/05/2023, 10:43 PMgifted-whale-78169
02/05/2023, 10:44 PMgifted-whale-78169
02/06/2023, 12:24 AMambitious-knife-25690
02/06/2023, 12:25 AMgifted-whale-78169
02/06/2023, 12:26 AMgifted-whale-78169
02/06/2023, 12:27 AMambitious-knife-25690
02/06/2023, 12:30 AMgifted-whale-78169
02/06/2023, 12:32 AMgifted-whale-78169
02/06/2023, 12:32 AMgifted-whale-78169
02/06/2023, 12:33 AMgifted-whale-78169
02/06/2023, 12:36 AMfaint-toothbrush-51643
02/06/2023, 12:37 AMgifted-whale-78169
02/06/2023, 12:38 AMgifted-whale-78169
02/06/2023, 12:39 AMfaint-toothbrush-51643
02/06/2023, 1:31 AMfaint-toothbrush-51643
02/06/2023, 1:37 AMfaint-toothbrush-51643
02/06/2023, 1:44 AMhx
class Darkness extends PrexObject {
var quad:Quad;
var shad:Shader;
public function new(sin:PrexScene) {
super();
scene = sin;
//Make sure this shader is loaded!
shad = scene.assets.shader(Shaders.SPELL__SPOTLIGHT);
//The quad that actually does the display
quad = new Quad();
//Creates a blank texture. Size determines resolution. Just make sure the width*height in both functions match.
quad.texture = Texture.fromPixels(360, 300, Pixels.create(360, 300, 0xff000000));
quad.shader = shad;
add(quad);
}
/** This just gets called in the preload of the scene */
public static inline function preload(asses:Assets) {
asses.add(Shaders.SPELL__SPOTLIGHT);
}
override function setSize(w, h) {
super.setSize(w, h);
quad.size(w, h);
}
public function setSpotlight(sx:Float, sy:Float, radius:Float):Void {
shad.setVec2("lightPos", sx/width, sy/height);
shad.setVec2("lightRad", radius/width, radius/height);
}
}
Spotlight.glsl
glsl
//I don't know what this does but it's in all of Ceramic's default shaders
#ifdef GL_ES
precision mediump float;
#else
#define mediump
#endif
//Ceramic's things
uniform sampler2D tex0;//texture
varying vec2 tcoord;//coordinates of this particular pixel
varying vec4 color;//both color and alpha (premultiplied).
//The spotlight filter's specific things
uniform vec2 lightPos;
uniform vec2 lightRad;
void main() {
vec4 tex = texture2D(tex0, tcoord);//The color of the texture
float dist = length((tcoord-lightPos)/lightRad);//Distance from center, adjusting for radii
if (dist < 0.9) {//Clear
gl_FragColor = vec4(0.0);
} else if (dist < 1.0) {//Fade at edges. Alpha must be premultiplied
gl_FragColor = color * tex * ((dist - 0.9) * 10.0);
} else {//Outside light
gl_FragColor = color * tex;//default
}
}
faint-toothbrush-51643
02/06/2023, 1:44 AMgifted-whale-78169
02/06/2023, 1:48 AMgifted-whale-78169
02/06/2023, 1:49 AMfaint-toothbrush-51643
02/06/2023, 1:56 AM