Home Technical Talk

Shader - Specular Term - Fresnel

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

I was wondering what would be the best way to put up a Specular-Fresnel term.

For example, I currently have my Fresnel term mutiplied with the Blinn/Phong term, before being fed into the Exponent and etc. which is lastly being added to the final output, so that at glancing angles, the fresnel kicks in, but only parts being hit by the light (specular term).

I have read at the same time some documentation which say Fresnel should just be standard added to the Specular term, which strikes me as odd.

Anyone have hints in that area? Would much appreciate it.

Replies

  • Brendan
    Offline / Send Message
    Brendan polycounter lvl 8
    I assume that's because you're likely to get a Fresnel effect facing away from the main light/s.

    Think of a shiny car, at maybe 4pm. Looking across the (flat roof), away from the lights, you're likely to get a similar effect from the surface.

    Fresnel just plain added to spec could be interesting, maybe a bit overblown as well in some circumstances I can think of.

    The only thing I can think of is multiplying something (cavity map?) over the fresnel so you don't get bright areas where they should be 'reflecting' a dark area.
  • Farfarer
    The way I've been using it is multiplying the final spec value by the frensel value then adding that to the diffuse * diffuse lighting.

    The fresnel value is usually extremely low (most non-metal surfaces are between 0.01 and 0.04 - metals can go up to about 0.5).

    This means that the specular result is strongest at glancing angles between the camera vector and the light vector but is very low when the camera and light are in close alignment.
    float3 h = normalize(lightDir + viewDir); // Half-vector.
    float specBase = saturate(dot(normalTexture, h)); // Regular spec.
    float fresnel = 1.0 - dot(viewDir, h); // Caculate fresnel.
    fresnel = pow(fresnel, 5.0);
    fresnel += fresnelValue * (1.0 - fresnel);
    float finalSpec = pow(specBase, glossTexture * 128) * specTexture * fresnel;
    float3 finalColor = diffuseTexture * diffuseLighting + finalSpec;
    

    Based on: http://filmicgames.com/archives/557 and http://seblagarde.wordpress.com/2011/08/17/feeding-a-physical-based-lighting-mode/
  • Gestalt
    Offline / Send Message
    Gestalt polycounter lvl 11
    This is sort of a point I'm curious about as well because in my mind the fresnel should handle most cases of specular, and for all intents and purposes, to me 'fresnel' is the specular term.

    Multiplying a reflected cubemap with the fresnel term (after you've adjusted it's falloff etc) is pretty common for shiny materials, but if you look around, just about every material has a 'glancing angle specular response' (most diffuse materials actually have it more prominently than they have the directly reflected specular 'dot' seen with Blinn/Phong).

    I think of the fresnel as a way to describe the reflectance of the material in a similar way that lambert describes the diffuse falloff, to say the light that could potentially bounce off of the microsurface as specular given the angle (typically stronger with more of a glancing angle).

    So I think of the direct specular 'dot' as appearing due to some amount of overall reflectance, and rather than thinking of it as something that is always tagged on (Blinn/Phong), I think of it as a bias in the fresnel term (toward 1). The fact that the light's direct reflection is more apparent than the other reflectance here being due to the fact that the light itself has greater intensity than the indirect light sources (ideally cubemaps would capture values greater than 1 and the ratio of specular vs diffuse reflectance, conservation of energy, absorption, etc would be taken into account before adding them).

    As for multiplying the fresnel with the lambert (or whatever you use), I see this as a way of avoiding lighting/haloing in the shadows, but If you are using a cubemap it seems like that reflection info should still be applicable in those areas as well (just with less intensity than the direct light source).
  • Farfarer
    I dunno if I'd call fresnel the specular term, but it's certainly a major part of realistic specular.

    You still need to calculate the traditional specular term, but the fresnel value acts as a mask in order to ensure that the specular highlights are most prominent at glancing angles.

    There's a whole other thing with energy conservation, too... which further complicates things.
  • CrazyButcher
  • kodde
    Offline / Send Message
    kodde polycounter lvl 19
    I just updated my Physically Based cgfx shader for Maya earlier today. Added a version which has multiplier sliders for several textures per request.

    It features many similar things to the black ops slides you mention CrazyButcher. It has an energy conserving specularity which you control with a roughness texture along with a fresnel term based on a substance texture. Utilizes the roughness texture to determine which cube mip to use for reflections and a few other features.
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Thanks guys for the input, although I'm still getting weird results when I combine the Fresnel with the final spec output via a multi, namely, a strange halo in the middle of my spec.

    The only ones that seems to work for my case is either a Lerp or an Add, controlling the spec by itself and the fresnel on it's own, but in both cases, feeding the Spec Map and color into my fresnel unless I'm misunderstanding something.

    Please, do bare with me since most common things do fly over my head sometimes.
  • kodde
    Offline / Send Message
    kodde polycounter lvl 19
    How is your Fresnel tweaked?
    Do you have any way to debug? As in visualize the fresnel just as color?
    As far as I can remember it should just be a matter of multiplying the spec with the fresnel, same for reflections.
  • Gestalt
    Offline / Send Message
    Gestalt polycounter lvl 11
    Are you multiplying you fresnel by an environment map? Is that environment map linear? If you have a full diffuse (with all it's lighting and intensity set up without the spec factored in) then lerping between your full specular reflectance (environment map) and full diffuse reflectance (ideally including the indirect lighting) might be a good place to start (you don't want them to add up to more than your total light). If you are using an environment map and it contains data for the light source then adding on the blinn/phong spec highlight is probably redundant. Keep in mind that when I use 'fresnel' I mean based on the individual material's fresnel values (with a bias and some amount of reflectance at a 0 incidence angle) and not just the ndotv.

    fihms.jpg

    What I mentioned above would ideally have hdr values for the environment map and the material using the fresnel in this way (as a measurement of specular reflectance based on incidence angle).
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Ah, OK, understood, my Cube was Emissive based, hence the reason I wasn't able to read my spec properly, d'oh and red face all around, totally forgot to add the Cube into my whole process.

    Cheers guys and thanks.
Sign In or Register to comment.