Fresnel Effect GLSL

fresnel in glsl for rim light

The Fresnel effect increases the intensity of light (or reflectivity) at extreme angles (when the view direction is almost parallel to the surface) and decreases it when viewed head-on (perpendicular to the surface). In simpler terms, surfaces at grazing angles (the edges or rims) appear brighter or more reflective than surfaces viewed straight-on.

This property is useful in shaders as it can be used for variety of effects such as glow on borders, or smoothing the borders and so on. I used this effect in my engine flame shader for Godot:

sci fi rocket shader godot
Jet engine flame without Fresnel.
engine flame vfx godot shader
With Fresnel (see smooth edges).

Fresnel Function Code

We just take dot product of view vector & normal vector. And then we clamp its results between 0.0 & 1.0.

float fresnel(float amount, vec3 normal, vec3 view){
	return pow(
		1.0 - clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0),
		amount
	);
}


// Godot shader usage.
// Surface NORMAL & Camera VIEW direction are calculated by the engine.
void fragment(){
	float fresnel_effect = fresnel(3.0, NORMAL, VIEW);
	ALBEDO += fresnel_effect; // Assign to surface COLOR/ALBEDO
}

Thank you for reading <3

Leave a Reply

Your email address will not be published. Required fields are marked *