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.

카테고리:tutorials

Tagged as:

답글 남기기

아래 항목을 채우거나 오른쪽 아이콘 중 하나를 클릭하여 로그 인 하세요:

WordPress.com 로고

WordPress.com의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Google photo

Google의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Twitter 사진

Twitter의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Facebook 사진

Facebook의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

%s에 연결하는 중