【AR】关于AR实时阴影的制作


原作者网址:http://m.manew.com/thread-41259-1-1.html

大家都知道,ar本身对平行光的阴影是不现实的,之前用过momo的一个方法实现了实时阴影,但是效果不是非常好,后面在论坛中发现了一个比较实用的方法。

话不多说,切入正题。
首先 写一个shader用来作为接收光照阴影
[mw_shl_code=applescript,true]Shader "FX/Matte Shadow" {

Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}

SubShader {

    Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    LOD 200
    Blend Zero SrcColor

CGPROGRAM

#pragma surface surf ShadowOnly alphatest:_Cutoff

fixed4 _Color;

struct Input {
    float2 uv_MainTex;
};

inline fixed4 LightingShadowOnly (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
    fixed4 c;
    c.rgb = s.Albedo*atten;
    c.a = s.Alpha;

    return c;
}

void surf (Input IN, inout SurfaceOutput o) 
{

    fixed4 c = _Color; 
    o.Albedo = c.rgb;
    o.Alpha = 1;

}

ENDCG

}

Fallback "Transparent/Cutout/VertexLit"

}[/mw_shl_code]



把这个材质赋给一个plane上,把plane放到你的模型下面,打上一个平行光,设置好阴影的参数。
跑起来看看效果吧。
影子一不小心就出来了。

你可能感兴趣的:(【AR】关于AR实时阴影的制作)