commonFilters improperly handles screen edges

Bug #424640 reported by Craig Macomber
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Panda3D
Fix Released
High
Unassigned

Bug Description

As discussed and verified http://www.panda3d.org/phpbb2/viewtopic.php?p=44052
When a window has non power of 2 dimensions, filters such as the bloom filter appear to sample from an uninitialized section of the texture beyond the top and/or right edges of the windows.

Initially found on a mac with a Nvidia GeForce 9600m GT. Related issue found by FenrirWolf on Windows, Nvidia 6800 Ultra.

I suspect it has to do with both the bloom shader and the resizing shader sampling outside of the screen region of the texture. This is possible related to a lack of padding being specified in CommonFilters.py, or likely could be resolved by modifying the shaders in question to specially handle the top and right screen edges.

Fix for the filter-bloomx.sha file:
added the clamps to these 3 lines:
  l_texcoord0 = clamp(float4(c.x-offset* -4, c.x-offset* -3, c.x-offset* -2, c.y), 0, 2*texpad_src.xxxy);
  l_texcoord1 = clamp(float4(c.x-offset* -1, c.x-offset* 0, c.x-offset* 1, c.y), 0, 2*texpad_src.xxxy);
  l_texcoord2 = clamp(float4(c.x-offset* 2, c.x-offset* 3, c.x-offset* 4, c.y), 0, 2*texpad_src.xxxy);

tried to fix bloom y the same way, and failed.

Found with the released 1.6.2 version of panda.

Workaround:
In prc file: "textures-power-2 none"

Craig Macomber (craigm)
description: updated
Revision history for this message
rdb (rdb) wrote : Re: [Bug 424640] [NEW] commonFilters improperly handles screen edges

Can you see if the problem still occurs with "textures-auto-power-2 #t" in
your Config.prc?

Revision history for this message
Craig Macomber (craigm) wrote :

Tried extures-auto-power-2 #t. No change.

Revision history for this message
rdb (rdb) wrote :

I think I've figured out the problem. Panda pads the buffer with some extra space in the case of a non-power-of-two window size, and when it samples the corner pixels in the screen (with Linear mode) it also samples into the padded area of the buffer.

This is going to require some thought.

Changed in panda3d:
importance: Undecided → High
status: New → Triaged
Revision history for this message
Treeform (starplant) wrote : Re: [Bug 424640] Re: commonFilters improperly handles screen edges

Do we clear the padded buffer, the padded parts??

Craig is the buffer you use this one set to be cleared every frame?

What type of buffer does it select? Does it do it on all types of buffers?

On Fri, Sep 4, 2009 at 10:54 PM, pro-rsoft<email address hidden> wrote:
> I think I've figured out the problem. Panda pads the buffer with some
> extra space in the case of a non-power-of-two window size, and when it
> samples the corner pixels in the screen (with Linear mode) it also
> samples into the padded area of the buffer.
>
> This is going to require some thought.
>
> ** Changed in: panda3d
>   Importance: Undecided => High
>
> ** Changed in: panda3d
>       Status: New => Triaged
>
> --
> commonFilters improperly handles screen edges
> https://bugs.launchpad.net/bugs/424640
> You received this bug notification because you are subscribed to
> Panda3D.
>

Craig Macomber (craigm)
description: updated
Revision history for this message
rdb (rdb) wrote :

No, we do not clear the padded buffer. It won't fix anything either, because if we cleared it to e.g. black, there would still be a border, but it would be black.

The real solution would be to implement clamping in the shader, like Craig proposed.

rdb (rdb)
Changed in panda3d:
milestone: none → 1.7.1
rdb (rdb)
Changed in panda3d:
milestone: 1.7.1 → 1.7.2
rdb (rdb)
Changed in panda3d:
milestone: 1.7.2 → none
Revision history for this message
Juha Jeronen (juha-jeronen) wrote :

I can confirm this occurs also in 1.8.1.

The same workaround (textures-power-2 none) works in Linux on a Radeon HD 2600.

Until a real solution is found, I would like to vote for clearing the padded buffer with zeroes. At least in the case of the bloom filter (which most visibly shows this problem), black borders would not trigger the bloom threshold, and hence the result should look correct.

Revision history for this message
rdb (rdb) wrote :

This is fixed. 1.9 already adds clears the buffer to black. As of https://github.com/panda3d/panda3d/commit/3eb91e3 Panda will also clamp the coordinates to the pad region.

Changed in panda3d:
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.