https://linen.dev logo
Join Discord
Powered by
# ceramic
  • f

    faint-toothbrush-51643

    02/05/2023, 9:56 PM
    and just intuitively, the spotlight shader makes way more sense
  • g

    gifted-whale-78169

    02/05/2023, 10:04 PM
    i suppose but i have zero experience with shaders
  • f

    faint-toothbrush-51643

    02/05/2023, 10:32 PM
    well shaders are pretty cool and ceramic supports them
  • g

    gifted-whale-78169

    02/05/2023, 10:32 PM
    yea ik i just havent gotten around to learning glsl
  • f

    faint-toothbrush-51643

    02/05/2023, 10:33 PM
    do you have a specific goal in mind with this spotlight thing, or are you just trying to get familiar with ceramic?
  • g

    gifted-whale-78169

    02/05/2023, 10:33 PM
    i was thinking about implementing it as a sort of flashlight/lantern in a horror game or something similar
  • g

    gifted-whale-78169

    02/05/2023, 10:34 PM
    mainly just fiddling though
  • f

    faint-toothbrush-51643

    02/05/2023, 10:43 PM
    you know, i could use that kind of spotlight effect in my own game
  • f

    faint-toothbrush-51643

    02/05/2023, 10:43 PM
    i'll make it and share
  • g

    gifted-whale-78169

    02/05/2023, 10:44 PM
    oh sweet that would be great, thanks
  • g

    gifted-whale-78169

    02/06/2023, 12:24 AM
    how can i scale an image without making it all blurry or manually scaling it in a separate app
  • a

    ambitious-knife-25690

    02/06/2023, 12:25 AM
    i think the trick is, is to start big and scale down as opposed to the opposite
  • g

    gifted-whale-78169

    02/06/2023, 12:26 AM
    ah shit
  • g

    gifted-whale-78169

    02/06/2023, 12:27 AM
    i already made some art i gotta restart it now
  • g

    gifted-whale-78169

    02/06/2023, 12:27 AM
    it makes sense though
  • a

    ambitious-knife-25690

    02/06/2023, 12:30 AM
    there may be another way, but, that's the way that i recently learnt
  • g

    gifted-whale-78169

    02/06/2023, 12:32 AM
    i found a little hack
  • g

    gifted-whale-78169

    02/06/2023, 12:32 AM
    at least for pixelorama which is what im using
  • g

    gifted-whale-78169

    02/06/2023, 12:33 AM
    just copy and paste it and resize until the proportions are right
  • g

    gifted-whale-78169

    02/06/2023, 12:36 AM
    what size do you typically start with?
  • f

    faint-toothbrush-51643

    02/06/2023, 12:37 AM
    can't you set the whatever to nearest neighbor or something?
  • g

    gifted-whale-78169

    02/06/2023, 12:38 AM
    yea but it distorts it
  • g

    gifted-whale-78169

    02/06/2023, 12:39 AM
    typically it works but in my case it doesnt
  • f

    faint-toothbrush-51643

    02/06/2023, 1:31 AM
    i forgot that ceramic's AlphaColor puts alpha at the front
  • f

    faint-toothbrush-51643

    02/06/2023, 1:37 AM
    there we are
  • f

    faint-toothbrush-51643

    02/06/2023, 1:44 AM
    @gifted-whale-78169
    Copy code
    hx
    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
    Copy code
    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
        }
    }
  • f

    faint-toothbrush-51643

    02/06/2023, 1:44 AM
    a bit of that is my own object system I built on top of Ceramic, but it mostly be alright
  • g

    gifted-whale-78169

    02/06/2023, 1:48 AM
    damn nice
  • g

    gifted-whale-78169

    02/06/2023, 1:49 AM
    does seem a bit like overkill for something like this though lol
  • f

    faint-toothbrush-51643

    02/06/2023, 1:56 AM
    overkill how so?
1...596061...124Latest