unity-shader-曲面细分与置换贴图

88 篇文章 8 订阅
31 篇文章 7 订阅

title: unity-shader-曲面细分与置换贴图
categories: Unity3d-Shader
tags: [unity, shader, tessellation, displacement]
date: 2019-05-22 15:37:34
comments: false

低模通过 置换贴图 增加曲面, 表现出高模效果
相比较 法线贴图 , 置换贴图 是真实改变顶点的位置, 会有遮挡, 而 法线贴图 只是在改变 片段 光照的视觉效果, 并不会修改模型的顶点位置.


前篇

在细分后采样置换贴图,对顶点进行偏移
需要注意的是在 surf 和 frag 以外采样贴图只能使用 tex2Dlod

使用限制: the shader is automatically compiled into the Shader Model 4.6 target, 只能在 sm4.6 以后才能使用.


测试

  • 使用的资源 Organic 2

  • shader

    Shader "test/Tessellation" {
        Properties {
            _MainTex ("Base (RGB)", 2D) = "white" {}
            _DispTex ("Disp Texture", 2D) = "gray" {}
            _NormalMap ("Normalmap", 2D) = "bump" {}
            _RoughnessMap ("RoughnessMap", 2D) = "white" {}
            _AoMap ("AoMap", 2D) = "white" {}
            _Displacement ("Displacement", Range(0, 1.0)) = 0.3
            _Color ("Color", color) = (1,1,1,0)
            _Metallic ("Metallic", Range(0, 1.0)) = 1.0
        }
        SubShader {
            Tags { "RenderType"="Opaque" }
            LOD 300
            
            CGPROGRAM
            #include "UnityPBSLighting.cginc"
            #pragma surface surf Standard addshadow fullforwardshadows vertex:disp nolightmap
            #pragma target 4.6
    
            struct appdata {
                float4 vertex : POSITION;
                float4 tangent : TANGENT;
                float3 normal : NORMAL;
                float2 texcoord : TEXCOORD0;
            };
    
            sampler2D _DispTex;
            float _Displacement;
    
            void disp (inout appdata v) {
                float d = tex2Dlod(_DispTex, float4(v.texcoord.xy,0,0)).r * _Displacement;
                v.vertex.xyz += v.normal * d;
            }
    
            struct Input {
                float2 uv_MainTex;
            };
    
            sampler2D _MainTex;
            sampler2D _NormalMap;
            sampler2D _RoughnessMap;
            sampler2D _AoMap;
            fixed4 _Color;
            float _Metallic;
    
            void surf (Input IN, inout SurfaceOutputStandard o) {
                half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
                o.Albedo = c.rgb;
                o.Metallic = _Metallic;
                o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTex));
                o.Smoothness = 1 - tex2D(_RoughnessMap, IN.uv_MainTex).r;
                o.Occlusion = tex2D(_AoMap, IN.uv_MainTex).r;
            }
            ENDCG
        }
        FallBack "Diffuse"
    }
    
  • 效果

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蝶泳奈何桥.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值