Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [Test for fun] Calculation with Shader

Author
Message
Riusz
8
Years of Service
User Offline
Joined: 27th Feb 2016
Location:
Posted: 24th Jul 2019 14:57
Hello,

I wanted to test something : AppGameKit Tier 1 is slow to treat a lot of data so I thinking of using shader to calculate some things.
In my case, to test, I imagined 100 elements with random x, y coordonates from 0 to 1000.
I wanted to know for every element which ones are closer than 100 pixels.

I do it with AppGameKit and with a shader to see the calculation time.
With the shader, I give a table vec2 to the shader that I applied to a 100x100 sprite. The result i a image where every line is a element with pixel of "close" elements are white.
To analyse that I use GetImage avec a memblock to check the pixel colors.


This is my code :


And the shader in test.glsl


With 100 elements, AppGameKit is faster than the shader.
I wanted to try with 1000 elements (you have to change the AppGameKit constants and the table size in the shader).

But now the GetImage command is cropped (because it depends of the resolution).
I see no other solution to get the result of the shader (GetSpriteImageID returns the original image).
There is maybe another solution...

It's not important, only for "fun"/"test" porpose but feel free to play with this code and shar your propositions.

Bye,
Riusz





fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 24th Jul 2019 15:42
100 calls to the shader is the reason its slowed down its the equivalent of having AppGameKit syncing 100 times before continuing

the idea of the shader is to do the calculation inside the shader

fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Riusz
8
Years of Service
User Offline
Joined: 27th Feb 2016
Location:
Posted: 25th Jul 2019 11:31
My idea is to do the calculation by the GPU on every pixel in parallel. That seems to be the case here.
I think the slow part is to read the result (with GetImage and MemBlock). And the GetImage doesn't work with a big image in my case.
Don't you think ?

The calls to the shader (in a loop) is only to give the table values (with SetShaderConstantArrayByName) but I think my shader is called one time by DrawSprite... Or I haven't understand everything..
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 25th Jul 2019 14:37
I'm not sure what you are testing.......the agk code is timed based only on floating calculations.....the shader test is based on the calculation, rendering, grabbing the image buffer as an image, creating a memblock, then reading the memblock (through an interpreted loop). The calcs in the shader were likely hundreds, probably thousands, of times faster, but transferring back to agk through a memory block would not be.

Try setting your timer for the shader test directly after rendering.

Login to post a reply

Server time is: 2024-11-22 16:15:35
Your offset time is: 2024-11-22 16:15:35