Home Technical Talk

Shader - Equation - Blinn (over Phong)

polycounter lvl 12
Offline / Send Message
Ace-Angel polycounter lvl 12
Hey to all,

I wanted to ask, in the opinion of the general census, is Blinn the better option over Phong, or is there a better option which is as flexible as these two?

From what I understood, Blinn has a better retention of the angle of view over Phong, and costs only 20-10 instructions more.

However, this is me, Ace De La Vegas, King of the Second Land of Gluttony, so I could be talking out of my arse from what I understood.

Also, I could not find a proper equation for Blinn, anyone mind showing me a link if possible which is the actual implementation of Blinn, and the half arsed 'faked' Blinn.

Cheers and thanks to all.

EDIT: Also, here another question, which ones deals with Normal Map artifact in a rational way? I was reading up on this and it seems like Lyon is Blinn but better? http://theinstructionlimit.com/isotropic-specular-reflection-models-comparison

Replies

  • Ark
    Options
    Offline / Send Message
    Ark polycounter lvl 11
    I'm no expert on the matter, but i think there only difference is how the specular is represented. Blinn is generally better for metals and glass, whereas Phong works better for plastics due to it's sharp circular specular highlights. Then theres Blinn-Phong which is believe is a slightly cheaper model of Blinn.
  • The Flying Monk
    Options
    Offline / Send Message
    The Flying Monk polycounter lvl 18
    The only time I've seen the difference explained in a way I was able to understand was in Bobo's explaining the matrix maxscript tutorials.
    From memory, Blinn uses only one dot product where Phong uses two. But Phong was more technically accurate.
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    Actually the Blinn and Blinn Phong are the same thing. Blinn's method for specular highlights is an approximation of Phong's which is a mathematically accurate model for pure specular surfaces.

    Blinn's is faster to compute with slightly lower accuracy. Essentially you get a softer wider highlight for the same exponent.

    Phongs specular model:
    V = View vector
    L = Light vector
    N = Normal Vector
    //all unit vectors
    
    Phong = (V dot R)^Shinyness
    R = L+(2* (L dot N)
    
    //what this does is reflect the light vector across the normal, then compares the view and light vector.
    
    Blinn =  (((V + L)*0.5) dot N)^Shinyness
    

    blinn has one less dot product. Both Blinn and Phong specular equations tend to use a lambertian diffuse term. (N dot L)* diffuse color * light color

    Neither one "deals" with normal map artifacts. They just do their computation differently. On modern hardware I'd bet the difference is minimal seeing as our GPU's have the dot product as a hardware instruction and dedicated vector processors, but in the old days, not calculating the reflection vector for every pixel was a real time saver.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    That's what confusing me, the first issue is that almost everyone making shaders claims that Blinn is more accurate and process intensive as opposed to Phong, which is what is driving me nuts since as you said, Phong as 2 dots.

    Secondly, the Normal Map artifacts is something I read here: http://forums.epicgames.com/threads/743037-vol.17-FXAA..-as-in-Battlefield-3-../page15
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    :shrug: ignorance is often widespread.

    No idea on the particulars of that guy's spec model. I'll look up the implementation later.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Vailias wrote: »
    :shrug: ignorance is often widespread.

    Thus we shall educate the masses!
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    After a quick read, my bet on the normal artifacting issue is one of two things.
    1: his normal map is pretty good anyway, and may not have been in its uncompressed state before saving the package.

    2: The anisotropic nature of the brdf winds up sampling the normal map twice for each coordinate and blending the output, effectively doing some filtering of the normal map in the shader.
    Could be either, or something else.
    The shader model is pretty cool too. Combination of a lot of people's work into something new with some original bits tossed in too of course.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Ah, that makes sense, didn't think 2x sample could filter out so much nasties.
  • equil
    Options
    Offline / Send Message
    Deja vu. Blinn is more correct, end of story.

    Blinn does not cost 20-10 instructions more. Phong is not better or worse for certain materials (it's always worse), but some distributions with a broader falloff (Trowbridge-Reitz, GGX) better fits reflectance data for certain materials, while Beckmann is a fairly good fit for most other. Phong is not 'mathematically accurate', it's not even geometrically interpretable. Blinn is not less accurate.

    I get the impression that the specular artifacts mentioned stem from floating point innaccuracies, as the author himself considers. There is no model which inherently comes with interpolation artifacts like that. The second link has nothing to do with any errors, he's just talking about normal map compression. Also, Ashikhmin-Shirley is little more than a bivariate Blinn with zero covariance. It does not sample the normal map twice.
    :shrug: ignorance is often widespread.
    :polytwitch:
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Erhm, I'm not responsible for anything other then reading up 'experts' writing stuff, such as this:

    http://dmg3d.blogspot.com/2011/03/modifying-unreal-source-shaders.html

    I tried recreating Blinn in UDK, so far it look like it 10 instructions 'cheaper' then Phong, as opposed to what many people claimed, which again, only confuses noobs like me, and it only read the light direction.

    Which I need to ask, is there a way to 'control' the marriage of Phong and Blinn in a common shader that blends the two specular entities?

    I tried using a Lerp to marry the two, but they end up instead killing each other when I reach a value of 0,5.
  • uncle
    Options
    Offline / Send Message
    I am confuse, what do you want to achieve blending blinn and phong? :headscratch:

    From what I had on my course Blinn actually is just approximated Phong(for faster computation). Only difference is the way of calculating reflection vector which is used in calculating specular. Thus specular highlight looks different, but it really doesn't matter as both models aren't physically correct - they can emit more energy than they receive.


    http://en.wikipedia.org/wiki/Phong_reflection_model ----> Computationally more efficient alterations subsection
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    Ace.. .don't blend them. They're doing the same exact thing, one just has a mathematical optimization.


    [highlight]EDIT: Equil is actually correct. I made the mistake of using Distance/directional lights and forgot to normalize my half vector.[/highlight]
    Equil: We went over this in that thread. Blinn is not more accurate, nor is it anisotropic in its essential format. An individual software package may treat its own internal blinn and phong materials differently than their basic specular model.

    Both blinn and phong models will generate round highlights as they are both based on the cosine of the angle between two vectors.

    Phong is more accurate for what these models do, and that is simulated reflection. As for not geometrically interprable.. what are you talking about? Look lemme draw you a diagram
    HowPhongWorks.jpg

    That's it. Its simple, and its mathematically accurate for highly/purely specular phenomena. The angle of incidence = the angle of reflection, and for perfectly specular materials you'd only see a "highlight" at exactly the reflection vector. Try it with a laser pointer and a mirror.

    As far as what I meant when I said it samples the normal map more than once, its not exactly doing that, but for each pixel it generates a U and V specular term, then combines them for the end resulting shape of the highlight.
    from the Ashikhmin-Shirley paper their specular term is this
    nu = specular exponent horizontal(local)
    nv = specular exponent vertical(local)
    n= normal

    ρs(Light, eye) =
    Sqrt((nu+ 1)(nv + 1)/8π) * ((n
  • equil
    Options
    Offline / Send Message
    Vailias, no one is claiming that blinn is anisotropic, an isotropic material can have anisotropic reflections (ie a simple cylinder, the ocean during sunset, etc). Your diagram accurately predicts how specular reflections work in the incident plane, but not in the azimuthal plane. This talk compares the half and reflection lobes to each other and to reflectance data.

    Not sure what you mean by "sample" in this case. to me a sample is (as long as we're talking about normal maps) a tex() function call, dot products just compare angles, so calculating n.l and n.v isn't sampling the normal twice, it's measuring two angles in relation to a normal that has been sampled once.

    edit: whoops posted before seeing that edit. oh well have a repost. blinn on the left, phong on the right. they are both planes in case that isn't clearBlinnvsPhong.png
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    Ah ok. Thanks for the paper. I was wondering what the heck was causing the lengthened highlight, as it didn't seem to be in the main part of the model, and doesn't seem to occur under some lighting conditions. I've finally been able to replicate it though, so I see where I went wrong.

    I'd made an error in my blinn implementation in that I didn't normalize the half vector after calculation. And my testing pieces were too small to show the elongated highlight under a directional light at the specular exponents I had set.

    Thanks for the extra info.

    As far as the multisampling thing, I mean that, while the same normal is being only sampled once via a single tex2D call, the data from that sample is being used more than once for the same output, while for more simple specular models its being used directly and only once. That extra calculation per pixel may, and I believe DOES, reduce the errors in compressed normal maps in UDK. Where the Ashikhmin model has the NdotH/HdotL*max(edotn, ldotn) I think is creating a smoothing effect.

    Here's an animated gif of this sorta thing in action. I chose an intentionally badly artifacted normal map. The second frame what I did was simply take the exact same normal, add it to itself, divide by 2, then renormalize the output before using it in the normal calculations of the blinn specular.
    Normal_smoothing.gif
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    By any chance, is EDotN a:
    EdotN = dot(normalize(vecEye), normalize(N))

    ?
  • Simmo
    Options
    Offline / Send Message
    Simmo polycounter lvl 12
    Sorry to bump this old thread but it's exactly what i'm asking about. :) I'm trying to implement a blinn shader for my next UDK scene, and I've gotten it to work perfectly fine with dynamic and dominant lights after building lights, but any other kind of light, such as a normal point light, and there wont be any specular at all.

    Can a custom lighting model work with baked/built "regular" lights, or will i have to just use the engines phong for that? Does anyone know?

    Cheers
Sign In or Register to comment.