Hello Everyone. I Have A Rather Weird Question/How Do I.
I Am Trying To Make A Falling Sands Type Game I Can Get Everything Working But The Problem I Get Really Poor Performance With A Decent PC.
And The Reason I Put The Title To That Is Because I Saw This Post: scirra.com/forum/falling-sand-on-gpu-through-pixel-shader_t78983
And I'm Trying To Figure Out How To Do Something Similar To This And Expand On It. And I'm Willing To Learn A lot if Needed To Put This to Use.
Any Help Would Be Great.
To use a shader to do it you'll need two things:
1. A effect to do it
2. To store the result of the effect into a texture so it can be used for the next frame.
I'll start with 2 since that's somewhat simpler. You'll need the paster object to do this. Ideally you could have the effect on the paster object and paste it to itself every frame, but you can't paste an object onto itself. So instead you'll need two pasters with the effect and you'll need to alternate the object you're pasting from and pasting to.
So basically the first time do this:
Paster1: disable effect
Paster2: enable effect
Paster1: paste paster2
Second time do this:
Paster1: enable effect
Paster2: disable effect
Paster2: paste paster1
And repeat from the start.
As far as the effect there isn't really a good reference. My thought is you could do it with two effects.
One to move the sand down. It's logic would look like this:
If pixel=white and pixel below is black
Then set result to black
If pixel=black and pixel below is white
Then set result to white
Then the second would shift even or odd scanlines left or right.
So the effects run for one frame could be:
This really cries for a test, but webgl doesn't work on my computer.
I'm Sorry But I'm Completely Lost. How Would I Execute Any Of This? I Know You Said Webgl Does not Work On Your computer But is there anyway you could give me an example? And For The Effect Is This Canvas Plugin Or? Sorry Inadvance I'm A Noob.
Edit: I Have Done Some More Digging And I Have Found This Made By You A While Back:
[quote:3pez871x]Quazi's method would work just as fast in C2 except there is no way in C2 to save the result of an effect to use on the next frame.
Other than that the logic to move the pixels is simple.
* if the area is free below a pixel is free move it down.
* if the area is not free try to move down left or down right if those areas are free.
But I Still Don't Quite Understand.
I can't attempt to make an example for a day or so.
You won't need the canvas plugin, you'll need the "paster" plugin. It's much like the canvas plugin but it can utilize webgl. Notice web browsers used to let my machine use webgl.
Other than that the rest is just a rough outline.
Thank You Ill Look That Up Thanks For The Help.
Here's the example with two required shaders. It also requires the paster plugin.
https://dl.dropboxusercontent.com/u/542 ... shader.zip
black is empty
white is wall
everything else is a particle.
There are probably other ways to improve it, but since it's using webgl I get very low fps.
Thelegendvinny If you ever get an optimization working, let me know please.
R0J0hound The Example Works Great But The Only Problem Is The Physics, How Could I Get The Physics Working?
Develop games in your browser. Powerful, performant & highly capable.
The example is the physics. The particles move down and shift left and right to settle in heaps instead of tall pixel piles. That is roughly what the particles example you referenced does, except it has more spread.
Did you have a different kind of physics in mind?
R0J0hound For Some Reason It Does Not Do That In Mine. I Have The Paster Plugin And I Put The 2 Effects In The Construct 2 Effects Folder. Is there anything else I had to do? All Mine Does Is Just Float No Physics What So ever. I Don't Know Why I Did Not Edit Anything.
If it runs and nothing is animated then my only guess is webgl isn't being used. Do other effects work for you?
If not then your graphics card is probably blacklisted on your browser and you'll need some solution without effects.
is it possible that you can use this kind of approach? maybe with arrays?
http://w-shadow.com/blog/2009/09/29/fal ... imulation/
R0J0hound Thank You!!! It Was My Browser I Just Switched Browsers And It Works Now. XD Thank You So Much!!
R0J0hound Why Does the "init" object or most of it not fall? Also Is There Any Way I Can Speed Up The Spread? EX. I Place A lot In One Spot It Makes A Tower At The Floor. And It Slowly Spreads. Any Way To Speed It Up? Also Is There Any Way To change the effect when its droping with the outline or following or something when its droping? I'm sorry if I'm asking for to much.
Seems to work fine for me (all of the red falls - and seems to splash!)... Awesome job ROJOjound! : )
I was getting a solid 60 frames a second, although the sand still seemed to fall at about half the speed that gravity would normally make it drop. Also, when sand was flowing over both sides of the white line sand was settling between the lines higher than outside the streams of falling sand - so that didn't look completely natural. But it certainly is a great start - especially since you couldn't see it run!