Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: Fresnel without cubemapping

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2018

    Fresnel without cubemapping


    Now I working on transparency and refraction in Opengl and GLSL. How to add fresnel calculation in GLSL code without using cubemapping.

    I have used the method as per the below tutorial,


    Code glsl:
    vec3 lightcalc(lightdata mlight)
        vec3 lightDir; vec3 total;
        float attenuation; 
        float specPhong,specBlinn,diff;
        vec3 diffuse,specular;
        vec3 norm = normalize(Normal);
        vec3 view_pos = vec3(0.0,0.0,10.0);
        lightDir = normalize( - FragPos);
    /************** DIFFUSE EFFECT *************/
        diff = max(dot(norm, lightDir), 0.0);
        diffuse = diff * diffuse_color *;
    /************** SPECULAR EFFECT *************/
        vec3 viewDir = normalize(viewPos - FragPos);
        vec3 reflectDir = reflect(-lightDir, norm);  
        vec3 halfwayDirection = normalize(lightDir + viewDir); 
        float w = pow(1.0 - max(0.0, dot(halfwayDirection, norm)), 5.0); 
        //float spec = pow(max(dot(viewDir, halfwayDirection), 0.0), 511.0);
            specBlinn = pow(max(dot(norm, halfwayDirection), 0.0), shine);
        specPhong = pow(max(dot(viewDir, reflectDir), 0.0), shine);
        specular = mix(specular_color,vec3(1.0),w) * specBlinn *;
           total = ambient + diffuse + specular;
    void main()
          vec3 result;
          result = lightcalc(light[0]);
          FragColor = vec4(result,1.0);

    But it does not give the result what i expect. Any one have any idea to render transparent object with fresnel? I want to render it as the below image.

    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	fresnel.jpg 
Views:	23 
Size:	3.8 KB 
ID:	2780  
    Last edited by Dark Photon; 06-06-2018 at 05:58 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts