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.

DarkBASIC Professional Discussion / Even quicker than FADE BITMAP !

Author
Message
Hannibal
17
Years of Service
User Offline
Joined: 5th Mar 2007
Location:
Posted: 19th Mar 2023 07:39
And this was written in 5 minutes, not much optimising !


Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 20th Mar 2023 01:39 Edited at: 20th Mar 2023 02:46
If you just want to fade your RGB values manually you can pre-compute a table of all of the bytes pre-multied by the scaler and perform any clipping required. So the inner loop grabs the byte, and looks up the output colour from the table and writes that to bank.

// mock up untested code bellow



Knowing what code DBPRO produces though It's more like to be better to store the table as mem block but even that includes media validation code in it. DBpro has pointers which I would hope wouldn't have such over heads. So that's most like the quicker option again.


Generally i'd be more inclined to read and write integers (via pointer and not through the memblocks commands) as integers and do parallel mults on them. This get rod of the floats in the inner loops (which Dbpro isn't great at) and we should get an iner loop that doesn't contain branches. Ideally Dbpro doesn't validate write/reading from a pointer. Which would mean possible branches in the inner loop and slower performance.





However, you could just alpha blend a rect/box/sprite of the fade colour over the image. Which would have the same effect and shifts the problem onto the gpu side

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Hannibal
17
Years of Service
User Offline
Joined: 5th Mar 2007
Location:
Posted: 20th Mar 2023 03:54
Very nice, I was thinking precalc table

TY
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 20th Mar 2023 13:59
Pointers are a very useful feature of DBP



And here's your code adapted to use a Pixel Pointer approach


notice how much faster it is... and as Kevin suggests., using a CLUT for the Multiplications can see further performance gains

Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 20th Mar 2023 21:55 Edited at: 20th Mar 2023 22:00
This appears to be a situation of specifically applying a fade to the screen. In a situation like this you're less likely to be desperate for every ounce of performance, I find that slapping a full screen sprite to the screen and adjusting the alpha levels is usually good enough. Particularly if you are just fading out or in briefly.

Another issue is this affect would adjust the whole screen including menus and HUD elements. It would be typically difficult to avoid this unless you can square off a section of the screen from the UI. Simply pasting a sprite would allow you to control layering to avoid this.

This technique is probably best used to create screen color effects as an alternative to shaders. So you could like tint a screen red or flash colors for effects. Or maybe you could create a night vision effect.


The original post is more focused on changing an image/texture that is loaded. The suggestions here can be quite helpful if you are creating dynamic UI elements. For example if you have a character with visual customization, and want a picture of that character in the UI and want it to change color if selected or highlighted or made inactive. You'd have to use a camera to create the current image of the character, then apply techniques like mentioned above to create different UI images needed. In this case being quick might be helpful. You still could also use Sprite commands to do a bunch of this.

Similarly what I do is take a screen grabs of an object with both black and white backgrounds, and then it's possible to compare the images to rebuild the image with a transparent background, preserving transparency. It's used as an automatic speed optimization in my bitmap font system where blocks of text lingering on screen for a while are converted to images and pasted to screen skipping most of the overhead.

Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!
Hannibal
17
Years of Service
User Offline
Joined: 5th Mar 2007
Location:
Posted: 21st Mar 2023 04:48
It is useful for easily doing this sorta thing...

you know, when you're in the mood for doing fishes in space type things...







































Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 21st Mar 2023 15:28


While of course Shaders are a faster approach to handling various effects., it is important to keep in mind that the BITMAP (Render Buffer) that we're Rendering Shaders to can be used as a Throughput and Output.
They are NOT used as inputs, we STILL have to use Images (Texture Stages) on a 3D Object for our Shader Inputs...
As such let's say we want to have a Reflective Surface and generate the Reflections; we STILL have to generate these with a CAMERA to a BITMAP then GET IMAGE to copy that to an Image used as a Texture Stage.

As GET IMAGE is on my Ryzen 1600 is achieving ~4 FPS (250ms)., compared to my Custom GET IMAGE that achieves ~45FPS (22.22ms)... keep in mind we're processing 1280x720 Pixels each grab (921,000)
This means the built-in command is handling about 3.7 Million Pixels per Second; while my custom solution is handling about 41.5 Million Pixels per Second.
Of course Shaders are simply better... after all my RX 5700 XT can handle ~305 Billion Pixels / Second in the Pixel Pipeline., so yeah, just a "smidge" faster... but we can't convert those results into a usable format with Sprites or Objects without using Get Image.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 21st Mar 2023 21:40
Most water reflection demos use "SET CAMERA TO IMAGE" help to draw the camera directly to an image used as a texture stage. This would skip using the Get Image command and be fast enough that a game can be processed and rendered along side the effect.

I will agree though that getting the results of a shader effect back into an image for use in a sprite or whatever is difficult. Typically you are stuck rendering the effect to a bitmap off screen and using Get Image to grab the pixels into an image.

However I will make note of an exception. I mentioned me taking white and black backgrounds of a scene to compare and generate a transparent background.
https://forum.thegamecreators.com/thread/184514
When I first announced this technique, the creator of the Image Kit plugin helped me make a shader optimized, Image Kit version of the technique. This version is fast enough to be done in real time animated. This uses render targets, and "IK Paste Image On Image" command to copy the shader output back to an image. So we managed to escape this particular dungeon.

Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!

Login to post a reply

Server time is: 2024-04-19 05:32:32
Your offset time is: 2024-04-19 05:32:32