zoukankan      html  css  js  c++  java
  • Shader-内轮廓自发光效果

    需求

    1 基于涅菲尔反射的变形

    • 原理 (近处的反射少,远处反射多)
      1)公式(近似):F = Fscale + (1-Fscale)(1-v·n)^5
    • 利用fresnel做边缘发光,代码
    fixed fresnel = _FresnelScale + (1 - _FresnelScale) * pow(1 - dot(viewDir, worldNormal), _PowVal);//涅菲尔公式:_PowVal =5
    _ColorFresnel * saturate(fresnel)
    

    2 基于表面着色器Unity2019

    Shader "Unlit/FirstShader"
    {
    	Properties
    	{
    			_MainTex(" Diffuse (RGB)", 2D) = "white" {}
    			_NormalMap("Normal Map", 2D) = "bump" {}
        _RimColor ("Rim Color", Color) = (1.0, 1.0, 1.0, 0.0)
        //_RimConcentration ("Rim Concentration", Range(0.5, 5.0)) = 0.9
        _RimStrength ("Rim Strength", Range(1.0, 4.0)) = 1.45
    	}
    		SubShader
    	{
    		Tags { "RenderType" = "Opaque" }
    
    		CGPROGRAM
    		#pragma surface surf Lambert
    
    		sampler2D _MainTex;
    		sampler2D _NormalMap;
    		float4 _RimColor;
    		float _RimConcentration;
    		float _RimStrength;
    
    		struct Input
    		{
    			float2 uv_MainTex;
    			float2 uv_NormalMap;
    			float3 viewDir;
    		};
    
    		void surf(Input In, inout SurfaceOutput o)
    		{
    				fixed4 c = tex2D(_MainTex, In.uv_MainTex);
    				float Lc = saturate(dot(normalize(In.viewDir), o.Normal));
    				half rim = 1.0 - Lc;
    				o.Albedo = c.rgb;
    				o.Normal = UnpackNormal(tex2D(_NormalMap, In.uv_NormalMap));
    				o.Alpha = c.a;
    				//o.Emission = _RimColor.rgb * pow(rim, _RimConcentration);
    				o.Emission = _RimStrength * (_RimColor.rgb * smoothstep(0.2, 0.6, rim));
    		}
    		ENDCG
    	}
    		FallBack "Diffuse"
    }
    
    
  • 相关阅读:
    Finance_Time-Series-Analysis-with-app-in-R
    Linear_algebra_06_二次型
    Linear_algebra_05_相似对角形
    病理学
    S&p_14_参数的假设检验
    S&p_13_参数区间估计
    Finance_Analysis-of-Financial-Time-Series
    817. Linked List Components
    811. Subdomain Visit Count
    807. Max Increase to Keep City Skyline
  • 原文地址:https://www.cnblogs.com/Jaysonhome/p/12951967.html
Copyright © 2011-2022 走看看