How to use to Set properties based on LWRP

How to Set properties based on LWRP.

Purpose of implementations this script.
Someone wanna binding camera FOV(Field of view) value to some of the shader features.

Writing Script.

Create new script as class like SetFovMatfromCamera.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.LWRP;

Adding one of using for LWRP inside script like below.

public Transform target;
private Camera _mMainCamera;
private float _setFov;
public Material mat;

Adding several needed public or private value.

public float SetFov
    {
        get => _setFov;
        set => _setFov = value;
    }

Adding SetFov(or _setFov) Setter function
This method are not necessarily requirement I just some test use this.

void Start()
    {
        _mMainCamera = Camera.main;
        if (_mMainCamera != null && _mMainCamera.enabled)
        {
            Debug.Log(_mMainCamera.name.ToString());
            Debug.Log(_mMainCamera.fieldOfView.ToString());    
        }
    }

Apply to Camera.main component into _mMainCamera value.
Writing to some of debugging.

Adding to Update feature

void Update()
    {
        _setFov = _mMainCamera.fieldOfView;
        Debug.Log(_mMainCamera.fieldOfView.ToString());
        mat.SetFloat("_getFOV", SetFov);
        
    }

Test Shader structure below.

Shader Graph test shader

Remember to Reference name that should be intensely change to your name of purpose.

FOV property that real name is FOV and Property value is _getFOV.

When Camera FOV has change that affect to some of shader features like below.

I just setting up to fresnel fx which is if currently camera fov has over 45 then appearing to fresnel fx to this shader.

because I was implemented comparison between constant value of 45 and _getFOV value from camrea FOV.

Categories: tutorials

Tagged as:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s