openfl / openfl-samples

Haxelib-based OpenFL sample projects
http://www.openfl.org
MIT License
78 stars 41 forks source link

Added Shaders examples #28

Closed mrcdk closed 9 years ago

mrcdk commented 9 years ago

It needs this PR https://github.com/openfl/openfl/pull/697

Don't merge yet, let's see if people like how it works.

TheSHEEEP commented 9 years ago

The interface is really intuitive, congrats!

jcward commented 9 years ago

Wow, pretty! Hey, it worked fine in neko, but not html5 for me (and the away3d examples worked in html5, so I assume it's not a hardware issue.) html5 (on the right) just sits there: Nvm, I keep forgetting to use -Dwebgl with html5 target.

jcward commented 9 years ago

Oh, I see this PR is fairly old, I assumed it was updated with @mrcdk 's shaders_again branch, no?

Also, fyi, once I start rotating or translating the shape, the light doesn't track the mouse. I tried various combinations of globalToLocal, or sprite.mouseX/Y, but I couldn't get the light to properly track the sprite once I altered the positioning of the sprite.

Of importance to these shaders, since they apply to displayobjects, is that it's obvious how to interact with the shader varibles appropriately in the (potentially transformed) displaylist.

mrcdk commented 9 years ago

Are you compiling html5 with webgl? haxelib run lime test html5 -Dwebgl http://i.imgur.com/jawqIsT.png

jcward commented 9 years ago

You're right, sorry -- I keep forgetting the in html5 target, -Dwebgl isn't the default. It worked!

mrcdk commented 9 years ago

It's old but they should work. I'll close it and open a new one later.

You will have to modify the code to do that. Right now it takes the global coordinates of the mouse and tells the shader what the size of that global coordinate will be. What you want to do are local coordinates so you have to tell the shader the local coordinates of the point and the local size of the object.

        sprite.x = 100;
        sprite.y = -100;
        sprite.rotation = 20;

        stage.addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent) {
            lightShader.uLightPos[0] = sprite.mouseX;
            lightShader.uLightPos[1] = sprite.mouseY;
        });

        stage.addEventListener(MouseEvent.MOUSE_WHEEL, function(e:MouseEvent) {
            lightShader.uLightPos[2] += e.delta * 0.005;
        });

        var bounds;
        stage.addEventListener(Event.RESIZE, function(_) {
            bounds = sprite.getBounds(null);
            lightShader.uResolution = [bounds.width, bounds.height];
        });
jcward commented 9 years ago

Cool, thanks for the info. And thanks for all your work on this!