Hm, in this case what's the usual technique, copying content of bitmaps or swapping two sets of bitmaps (one for input and one for output) in material textures and FBO attachments in each render pass?Kjell wrote:do keep in mind that you can't use the same texture as input & output at the same time
BallZ
Moderator: Moderators
Re: BallZ
Re: BallZ
Hi Rado1,
By the way, just to be clear .. even though i answered with the MRT solution on your "is there a way how to use FBO with more than 4-float depth?" question, that doesn't mean you necessarily need MRT in every situation where you're working with more than 4 floating point values per pixel. If you don't have all values affecting each other you can usually split the values over multiple buffers & shaders.
K
As you probably noticed in the 2012 example i linked to earlier in this thread, i usually go with the swap approachRado1 wrote:Hm, in this case what's the usual technique, copying content of bitmaps or swapping two sets of bitmaps (one for input and one for output) in material textures and FBO attachments in each render pass?
By the way, just to be clear .. even though i answered with the MRT solution on your "is there a way how to use FBO with more than 4-float depth?" question, that doesn't mean you necessarily need MRT in every situation where you're working with more than 4 floating point values per pixel. If you don't have all values affecting each other you can usually split the values over multiple buffers & shaders.
K
Re: BallZ
Thanks Kjell for answers; now I have all information to implement BallZ with MRT.
I'm using it in the current intermediate version (triple RenderTargets, Shaders, Materials, ...), but my computations of position/size/color use common pre-computed values, so I would like to reduce them to one shader which is much better to maintain/extend.Kjell wrote:If you don't have all values affecting each other you can usually split the values over multiple buffers & shaders.
Re: BallZ
Just in case someone else ( other than Rado1 ) is having trouble with this .. below is a simple MRT example.
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
<OnLoaded>
<ZExternalLibrary ModuleName="opengl32" Source="//" DefinitionsFile="opengl.txt"/>
<ZExpression>
<Expression>
<![CDATA[// Make sure the textures are allocated
@UseMaterial(Material: RedMaterial);
@UseMaterial(Material: GreenMaterial);
//
Buffers[0] = GL_COLOR_ATTACHMENT0;
Buffers[1] = GL_COLOR_ATTACHMENT1;
//
glGenFramebuffers(1, Framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, RedBitmap.Handle, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, GreenBitmap.Handle, 0);
glDrawBuffers(2, Buffers);]]>
</Expression>
</ZExpression>
</OnLoaded>
<OnRender>
<ZExpression>
<Expression>
<![CDATA[//
glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer);]]>
</Expression>
</ZExpression>
<UseMaterial Material="FooMaterial"/>
<RenderMesh Mesh="FooMesh"/>
<ZExpression>
<Expression>
<![CDATA[//
glBindFramebuffer(GL_FRAMEBUFFER, 0);]]>
</Expression>
</ZExpression>
</OnRender>
<OnClose>
<ZExpression>
<Expression>
<![CDATA[//
glDeleteFramebuffers(1, Framebuffer);]]>
</Expression>
</ZExpression>
</OnClose>
<Content>
<Array Name="Buffers" Type="1" SizeDim1="2"/>
<Variable Name="Framebuffer" Type="1"/>
<Bitmap Name="RedBitmap" Filter="1"/>
<Material Name="RedMaterial" Shading="1" Light="0" ZBuffer="0">
<Textures>
<MaterialTexture Texture="RedBitmap" TexCoords="1"/>
</Textures>
</Material>
<Bitmap Name="GreenBitmap" Filter="1"/>
<Material Name="GreenMaterial" Shading="1" Light="0" ZBuffer="0">
<Textures>
<MaterialTexture Texture="GreenBitmap" TexCoords="1"/>
</Textures>
</Material>
<Mesh Name="FooMesh">
<Producers>
<MeshBox Grid2DOnly="255"/>
</Producers>
</Mesh>
<Shader Name="FooShader">
<VertexShaderSource>
<![CDATA[//
void main()
{
gl_Position = gl_Vertex;
}]]>
</VertexShaderSource>
<FragmentShaderSource>
<![CDATA[//
void main()
{
gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);
}]]>
</FragmentShaderSource>
</Shader>
<Material Name="FooMaterial" Shading="1" Light="0" ZBuffer="0" Shader="FooShader"/>
</Content>
</ZApplication>
K
Re: BallZ
A new version of BallZ comes with the following improvements:
- improved performance (all computations are done by GPU)
- new effects; see screenshots
- new scene transition
Thanks to sharing know-how with Kjell, I was able to accomplish my first real usage of FBOs and shaders used for computations. I'm attaching also sources, so you can take some inspiration for your projects.
Please test the current version because I'm not sure how/whether it runs on various GPUs. Thanks.
- improved performance (all computations are done by GPU)
- new effects; see screenshots
- new scene transition
Thanks to sharing know-how with Kjell, I was able to accomplish my first real usage of FBOs and shaders used for computations. I'm attaching also sources, so you can take some inspiration for your projects.
Please test the current version because I'm not sure how/whether it runs on various GPUs. Thanks.
- Attachments
-
- BallZ2.zip
- screensaver, ZGE project
- (138.45 KiB) Downloaded 867 times
-
- screenshots
- ballzscr3.png (117.42 KiB) Viewed 22391 times
Re: BallZ
Cool . It runs real smooth here. Interesting that it is possible to compute all the scenes inside a shader.
I notice that the "scene" variable is a float in the computeshader. Can you change this to an "int"? Or just do "int intScene=(int)scene" and then make the switch use that. I can imagine some GPUs complaining otherwise (because a "switch" statement requires a integer).
I notice that the "scene" variable is a float in the computeshader. Can you change this to an "int"? Or just do "int intScene=(int)scene" and then make the switch use that. I can imagine some GPUs complaining otherwise (because a "switch" statement requires a integer).
Re: BallZ
I see. I thought that all uniforms coming from ZGE ShaderVariable are only floats. If not, then of course "uniform int scene;" is better. BTW can I also pass vec* values as uniforms by ShaderVariable?VilleK wrote:I notice that the "scene" variable is a float in the computeshader. Can you change this to an "int"? Or just do "int intScene=(int)scene" and then make the switch use that. I can imagine some GPUs complaining otherwise (because a "switch" statement requires a integer).
Another issue I had is precision of RenderTarget. I originally use it for computation, but observed (Kjell told me) that it supports only 256 values per channel (RGBA), which is not sufficient for computations. Therefore, usage of own GL_RGBA16 textures was necessary, and of course it requires a lot of cumbersome OpenGL programming as you can see. The situation would be better if RenderTarget allowed to specify also "precision" mapped to internalFormat parameter.
Answer to your older question:
For BallZ I take inspiration in water, sea and sea creatures...VilleK wrote:How do you come up with ideas for all these cool formations?