What is the fresnel effect in Unity?

The fresnel effect in Unity is an essential tool to achieve realistic reflections on various materials. It defines the way light interacts with a surface, depending on the angle of view. Unity's shader graphs offer a very simple way of creating this effect.

Definition: fresnel effect

The fresnel effect represents how the light reflects off a surface based on the angle between the surface and the viewer. The greater the angle, the more light the surface reflects, giving a shiny appearance to the GameObjects.

What is a shader graph?

The shader graph is a feature that provides a visual editor for creating complex shadersA software that determines how the properties of a 3D model reacts to lights, shadows, reflections, textures, and color. . It uses nodes that are connected together to create a flowchart-like representation of the shader functionality.

It is an intuitive method for creating shaders as it allows you to visualize the components and the flow of the shader code. With shader graphs, you can create and experiment with complex visual effects without having to write any code.

How does it work

Shader graphs in Unity allow you to create the fresnel effect without having to write any code. Given below is detailed guide on how to create a fresnel effects in Unity.

Create a shader graph

  • Right click in the project window.

  • Go to shader graph.

  • Choose the type of the shader graph.

    • You will be able to see the shader graph in the project window.

Open the shader graph

  • Double click on the shader graph to open it.

    • A new window opens up showing a shader graph with only a final output node.

Add nodes

  • Right click in the graph window.

  • Click on create new node.

  • Search fresnel effect node.

    • Add the node and connect its output to the input of the final node.

  • Modify the fresnel effect node's properties to control how reflective the surface should be from different angles.

Apply shader to the material

  • Right click in the project window.

  • Click create material.

  • In the inspector pane, click on shader.

  • Select shader graph from the drop down menu.

  • Select the newly created shader graph.

  • Drag and drop the material onto the GameObject.

    • You will be able to see the fresnel effect on the objects in the scene.

Demonstration

Create a new shader graph
1 of 15

Sample project

The sample project makes use of the fresnel effect as the base effect and adds other types of nodes to it to amplify the final effect.

Note: You can see the shader graph for the sample project in the demonstration.

Click Run to see the final results of the fresnel effect.

import React from 'react';
require('./style.css');

import ReactDOM from 'react-dom';
import App from './app.js';

ReactDOM.render(
  <App />, 
  document.getElementById('root')
);

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved