curious about what AGK allows for surfaces (verticescount, trianglescount)

Started by RemiD, February 24, 2018, 23:10:02

Previous topic - Next topic

Derron

@ shader support
Hmm, for the same stuff as in other languages?

- preprocessing (?)
- postprocessing
- ...

stuff you do in 2D games. Dunno how people use it in 3D engines (missing personal experience there). In 2D I would have used it for "water backgrounds" at a certain "z index" (so more a 2D in 3D). means you could render 2D islands sprites covered by shaderized water around it ... hmm this more and more sounds as if you needed 3D.
Postprocessing and the likes: to blur/freeze/desaturate a screen before eg. rendering an ingame-popup-menu.
As said I am not used to use shaders and others here might have way more ideas of what usage shaders in "2D" could have.


bye
Ron

TomToad

Quote from: col on June 01, 2018, 13:32:57
Off-topic
I do have a system in place for shaders... getting it working nicely with the Max2D graphics contexts is another thing.

I managed to get shaders to work in Max2D a while ago.  Posted a thread with some of the experiments I did on the blitzbasic forum.  It isn't as difficult to do as one might think, Max2D are really just 3D textured quads that always face the camera.

http://mojolabs.nz/posts.php?topic=105697
------------------------------------------------
8 rabbits equals 1 rabbyte.

col

Hi TomToad,

Derron and I are referring to a single command set that will work with all 3 standard ( plus I'm sure Derron favours SDL too ) graphics contexts. For GL, D3D9 and D3D11.
This means to abstract away the underlying access to the shader uniforms/constants/samplers/textures etc.

For Max2D let's assume for the moment that only vertex and pixel shaders are being used.
There are some subtle differences between Dx and GL, for example in GL you access a uniform ( in Dx its a called a constant ) by querying the shader program which includes both a vertex and pixel shader. In Dx the vertex and pixel shaders are queried individually for their 'variables'.

To get over these issues and create a single code base for all 3 I created a TShaderFramework, TShaderProgram, TVertexShader and TPixelShader, TShaderUniform, TShaderTexture and TShaderSampler. Each one abstracts away the underlying gpu API required to set their datas.

TShaderFramework
    This just helps reduce name clashing for functions/methods but also identifies the underlying graphics context - gl, d3d9 or d3d11. The TShaderFramework has methods to create a vertex shader and pixel shaders ( which could, in the future, be extended to support the shaders for geometry and tesselation ). They return an appropriate instance of each which is where the compiled shader binary lives. TShaderFramework is used  to create an instance of TShaderProgram too.

TVertexShader TPixelShader
    You create these passing in your shader source code as standard text ( GLSL for GL, and HLSL for D3D9/D3D11 ). The shader gets compiled into binary form and held in these.

TShaderProgram
    You create a TShaderProgram using a TVertexShader and a TPixelShader, which for GL links the binaries ( Dx doesn't require linking ). The TShaderProgram auto creates instances of TShaderUniform, TShaderTexture, TShaderSampler as required for the shaders using the underlying gpu API reflection methods. TShaderProgram has methods to query for those shader 'variable' instances. As a part of those 'variables' it also sets up 'cpu backing memory' so that you can set values without the shader being in use at the time the 'value' is set. When the shader is then set to be used the values are passed to the shader/gpu as required.

TShaderUniform, TShaderSampler, TShaderTexture
    Have methods to set floats, ints, matrix, sampler and texture as appropriate. Some are not used in GL and D3D9. Some are required for D3D11.

The latter types is where it all starts to get gritty when setting things up with Max2D due to Max2D hiding away the current gpu state. I guess you can query for the state when needed but that's where it all starts to get a little messy :/
If you/anyone have some ideas and suggestions on how to clean that bit up then that would be awesome  :)


I guess 2D special effects would be 'nice', most of which require more than one texture.
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Derron

@ Qube
I think it might be possible to split the "blitzmax shader" posts into a new thread - sorry for derailing ;-)


@ Col
Thanks for that elaborative explanation.

I think as "vanilla blitzmax" can use Brucey's "MaxMod/brl.mod and MaxMod/pub.mod" it should be fairly doable to add or change some stuff in that modules - eg to expose data which is set to private for now. Also your needed adjustments for Render2Texture could find its way into the maxmod-repos.
But already asking for this exposes that you have knowledge about this specific parts which others surely do not have. So our chances to help are very....limited. Sorry.


@ TomToad
Thanks for your link - but as Col already wrote I am more interested in some cross-platform approach. So yes, it should work with all the "official" supported render paths (ogl, dx9, dx11 - and throw out on dx7 ?). SDL would be cool as it allows usage with Android/iOS then.


@ special effects
Dunno if this is a shader, but the "torch effect" (black screen with torch-areas lightening up the playground) could surely be done via shader - or some kind of "fog" (instead of having multiple layers of high-res/app-res textures moving in parallax-esque ways along the screen)

bye
Ron

Kryzon

Quote from: col on June 02, 2018, 10:52:03
TShaderFramework
TVertexShader, TPixelShader
TShaderProgram
TShaderUniform, TShaderSampler, TShaderTexture
I think your classes got the T virus. Here, let me help:

ShaderFramework
VertexShader, PixelShader
ShaderProgram
ShaderUniform, ShaderSampler, ShaderTexture

col

https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."