Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if texture derivatives are colinear, then orthogonalize them #246

Closed

Conversation

cmstein
Copy link
Contributor

@cmstein cmstein commented Mar 9, 2012

If we perform a texture lookup where dsdx,dsdy..dtdy=0, then the options.sblur parameter won't get applied.

This is because adjust_width_blur will produce colinear derivative components (dsdx=dtdx=dsdy=dtdy) which then produces numerical problems with the ellipse axes and effectively results in point-lookups.

This fix just "orthogonalizes" the texture derivatives and the blur seems to get applied correctly.

@@ -813,6 +813,11 @@
if (fabsf(dtdy) < eps)
dtdy = copysignf (eps, dtdy);

// If the derivatives are colinear then force them to be orthogonal
if (dsdx * dtdy - dsdy * dtdx == 0.0f) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a floating-point compare with 0.0 appropriate here? It's not fragile?

I dont fully understand the context this is executing in, but anytime equality checks in floating point code are a bit scary. Could you clarify why this is preferable to testing with an epsilon? (such as fabsf(...) < std::numeric_limits::min())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is not a very good fix; it really only applies if the incoming derivs are zero. Perhaps I should test for that explicitly?

@lgritz
Copy link
Collaborator

lgritz commented Mar 9, 2012

Er... concern #1 is what Jeremy said -- what happens when they are nearly colinear, but not completely. Will we still end up with in correct blur? Concern #2 is what else is affected by unilaterally negating dtdy. Concern #3 is I wonder if something is going wrong upstream to give weird derivs in the first place. Do you understand the situation that led to colinear derivatives and think they are sensible (or at least unavoidable) in this situation?

It seems to me that a lot of the code here assumes that the two derivatives will be more or less orthogonal, and that there are probably a number of ways in which we are incorrect when they are significantly non-orthogonal. I suspect there's a more correct transformation of the derivatives when adding blur, that gives us the right new ellipse. Or maybe this is just the wrong place or strategy for accounting for the blur. I'm not sure.

I'm not sure how badly we care about doing it "right" for the usually-improbable non-orthogonal case. I know there's a show that needs the fix. But primarily I want to be sure we aren't breaking anything new in the process. I suppose it can't be too bad -- this only kicks in when the derivs are fairly nonsensical.

Comments, Chris?

@lgritz
Copy link
Collaborator

lgritz commented Mar 9, 2012

OH. Duh, yes, I see the problem now, which is that if the derivs are exactly zero, blur will be as well.

@fpsunflower
Copy link
Contributor

Agreed, I think the real fix should be in the math below. Scaling blur by the normalized derivs doesn't make sense.

@cmstein cmstein closed this Mar 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants