Horde3D

Next-Generation Graphics Engine
It is currently 19.03.2024, 06:32

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Rendering to mip-maps?
PostPosted: 29.07.2010, 05:58 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
I'm looking at implementing the visibility/occlusion algorithm from the "rendering with conviction" presentation. I've figured out how to implement each step on Horde3D except for one -- part of the algorithm requries me to render a depth buffer (linear depth, or native z/w depth - doesn't matter) and then generate a mip-chain from this texture, taking the max-value of each 2x2 group of texels at each mip-level.

The only way I can think of doing this at the moment is to make a seperate RT for each level, e.g.
Code:
<RenderTarget ... >
<RenderTarget ... scale="0.5">
<RenderTarget ... scale="0.25">
<RenderTarget ... scale="0.125">
However, in the shader that uses this texture-data, I need to be able to do a mip-mapped texture sample (which seperate RTs doesn't allow for). So, I guess I'll have to make some modifications to Horde to get this working.

1) Does OpenGL have any functions that would build this mip-chain for me (using the max-value when filtering each level).

2) Does anyone have any advice on how to render to a specific mip-level in GL?

3) Does anyone have any input on what the Horde syntax could look like for rendering to a mip level, and for specifying mip-mapped render targets?
e.g.
Code:
<RenderTarget ... mipLevels="6">
...
<SwitchTarget target="..." mip="4">
...
<SwitchTarget target="..." mip="5">
...
or
Code:
<RenderTarget ... mipmapped="true">
...
<GenerateMips target="..." material="myFilter.material.xml">
4) Ideally this would be a single-channel texture format. So far I've been packing depth into RGBA8, but an R32 would be ideal -- would it be easy for me to add this render-target format to Horde while I'm at it? Are there any hardware/GL version issues with this?

[edit] Having mip-mapped render targets and manual generation of mip-maps via shaders would be very handy for DOF implementations as well :D (use a blur shader to generate mips, and in the post-process shader use the "out-of-focus" amount to select a mip level).


Top
 Profile  
Reply with quote  
PostPosted: 29.07.2010, 13:21 
Offline

Joined: 15.02.2009, 02:13
Posts: 161
Location: Sydney Australia
Hi DarkAngel,

From porting to ES2.0 I noticed that the old way of mip-map generation was to set glTexParameteri before glTexImage2D to say that it needs mips generated, but this has been deprecated in GL 3.x and doesn't exist in ES2.0.

The new way is immediately when you make a call to glTexImage2D you need to do glGenerateMipmap (or in desktop opengl 2.x speak it is probably glGenerateMipmapEXT). Anyway, the good thing is that command is part of the framebuffer object extension so this is indeed possible.

Unfortunately I don't think horde has any elegant API function for this yet, in fact it only got the glGenerateMipmap technique introduced in the later SVN revisions, but I can give you a hint at to what to change.

Under egRendererBase.cpp where it does RendererBase::createRenderBuffer I think this function just needs a bool inserted for genMips, so when this guy is called:

uint32 texObj = createTexture( TextureTypes::Tex2D, rb.width, rb.height, format, false, false, false, false );

it does:

uint32 texObj = createTexture( TextureTypes::Tex2D, rb.width, rb.height, format, false, rb.genMips, false, false );

Then later I guess there just needs to be a hook from the egPipeline parsing which lets you use a tag in the pipeline.xml so that when the renderbuffer is created it generates your mipmaps.

I guess I could integrate this feature, but I think marciano or Volker might have a better idea of integrating it.

Edit: I was reading through it and saw that you probably need an additional call to glGenerateMipmap just before finishRendering() inside of egRenderer.cpp's Renderer::Render, or actually inside of finishRendering which first checks the current bounded framebuffer to see if it has any texObj's and if so, checks to see if they have genMips flagged and if so, bind the texture and call glGenerateMipmap. Maybe it is ideal to have its own function in RendererBase or something...

I'm referencing http://www.opengl.org/wiki/GL_EXT_framebuffer_object "Quick example, render_to_texture (2D), mipmaps"

_________________
-Alex
Website


Top
 Profile  
Reply with quote  
PostPosted: 29.07.2010, 14:15 
Offline

Joined: 24.03.2010, 10:17
Posts: 55
Hi.
Quote:
Does anyone have any advice on how to render to a specific mip-level in GL
I guess you'll have to use glFramebufferTexture2DEXT to attach the texture's mipmap level to a FBO color attachment, see RendererBase::createRenderBuffer
Code:
         glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + j, GL_TEXTURE_2D, tex.glObj, MIPMAPLEVEL );
where MIPMAPLEVEL is the level of the texture, normally 0 = base.
See Usage Example (5) at http://www.opengl.org/registry/specs/ARB/framebuffer_object.txt
Quote:
3) Does anyone have any input on what the Horde syntax could look like for rendering to a mip level, and for specifying mip-mapped render targets?
and
Code:
<RenderTarget ... mipLevels="6">

I think this should be only a boolean, because the number of mipmaps is inherently fixed by the resolution (as far as I know, even for NPOT textures).
And then it would be nice to have some kind of automatic loop to select and render to each mipmap.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group