In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Projector in Unity3D. The introduction in this article is very detailed and has certain reference value. Interested friends must read it!
Projector
[Principle]
Projector can project a Material onto all objects within a defined frustum. Usually contains two map cookies and Falloff. Cookie is the projected pattern, Falloff's role is mainly to determine the distance to determine the Alpha of the projection, that is, light and dark. The left side of Falloff is white, and the alpha value is 1, which corresponds to the brightest projection distance, and the right side is close to all black. The alpha value is 0, which indicates that the projection will gradually approach transparency or even disappear as the projection distance becomes farther.
[Can be achieved]
0 Character selection aperture
1 Regular blob shadow
2 Fake Dynamic Shadow
3 Light projections
4 projectors (depending on the texture of the Meterial, it can be pictures, videos, scenes seen by another camera)
5 3D or 2D flashlight effects
[Steps]
I. Create Projector.
You can create an empty GameObject and add a Projector component from Component as shown below.
You can also Import Package-> Projector, import the Projector package. The package contents are as follows
II: Precautions
1. Make sure Cookie Texture is set to Clamp
2. To avoid projector bleeding, Cookie Texture enables the Border Mipmaps option or disables Mipmaps directly
3 FallOff
Whether it's orthographic or not.
If FallOff is not used, all projected cookies are the brightest, alpha 1 cookies, and will project forward and backward in frustrum, resulting in a "double projection" effect that we do not want to see. With the Falloff map that the system packs. The projection fades with distance.
[Example Demonstration]
Example 0: Aperture at the foot of the character
projector所使用的shader如下,再加上脚本控制projector旋转即可。
Shader "Custom/Circle" {
Properties {
_ShadowTex ("Cookie", 2D) = "gray" { TexGen ObjectLinear }
}
Subshader {
Tags { "RenderType"="Transparent-1" }
Pass {
ZWrite Off
Fog { Color (1, 1, 1) }
AlphaTest Greater 0
ColorMask RGB
Blend DstColor Zero
SetTexture [_ShadowTex] {
combine texture,texture
Matrix [_Projector]
}
}
}
}
或者用Vertex&Fragment
Shader "Custom/Circle" {
Properties {
_ShadowTex ("Cookie", 2D) = "" { }
}
Subshader {
pass {
ZWrite off
Blend DstColor One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _ShadowTex;
float4x4 _Projector;
struct v2f {
float4 pos:SV_POSITION;
float4 texc:TEXCOORD0;
};
v2f vert(appdata_base v)
{
v2f o;
o.pos=mul(UNITY_MATRIX_MVP,v.vertex);
o.texc=mul(_Projector,v.vertex);
return o;
}
float4 frag(v2f i):COLOR
{
float4 c=tex2Dproj(_ShadowTex,i.texc);
return c;
}
ENDCG
}//endpass
}
}
例1: 普通圆点阴影(blob shadow)
加在角色下面,记得把角色的layer加进 projector设置下的'Ignore Layer'即可。
Shader "Projector/Multiply" {
Properties {
_ShadowTex ("Cookie", 2D) = "gray" { TexGen ObjectLinear }
_FalloffTex ("FallOff", 2D) = "white" { TexGen ObjectLinear }
}
Subshader {
Tags { "RenderType"="Transparent-1" }
Pass {
ZWrite Off
Fog { Color (1, 1, 1) }
AlphaTest Greater 0
ColorMask RGB
Blend DstColor Zero
Offset -1, -1
SetTexture [_ShadowTex] {
combine texture, ONE - texture
Matrix [_Projector]
}
SetTexture [_FalloffTex] {
constantColor (1,1,1,0)
combine previous lerp (texture) constant
Matrix [_ProjectorClip]
}
}
}
}
2 伪动态阴影(Fake Dynamic shadow)
就是用3d Max或者 Maya或者Unity,先把动画对应的阴影烘焙好, 做成序列帧。然后用projector的材质做对应的帧动画即可。
3 光的投影
基本是就把黑的blob cookie换成 中间是白色的cookie即可。
4 投影仪(根据Meterial的贴图,可以是图片,视频,另一个相机看到的景象)
另一个相机绘制到RenderTexture,然后projector的材质使用RenderTexture即可
5 3D或者2D手电筒的效果就是projector的方向和范围设置和手电一致。把电筒的光颜色投出去即可。
以上是"Unity3D中Projector怎么用"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.