资源简介
本资源是Unity技术应用,脚本直接应用在地面模型上,加上相对应的shader能达到即时地面反射效果,可调节精度。

代码片段和文件信息
using UnityEngine;
using System.Collections;
// This is in fact just the Water script from Pro Standard Assets
// just with refraction stuff removed.
[ExecuteInEditMode] // Make mirror live-update even when not in play mode
public class MirrorReflection : MonoBehaviour
{
public enum NormalAxes { X = 0 Y= 1 Z= 2 }
public NormalAxes mirroraxes = NormalAxes.Z;
public bool m_DisablePixelLights = true;
public int m_TextureSize = 256;
public float m_ClipPlaneOffset = 0.01f;
public Matrix4x4 abc;
public layerMask m_Reflectlayers = -1;
private Hashtable m_ReflectionCameras = new Hashtable(); // Camera -> Camera table
private RenderTexture m_ReflectionTexture = null;
private int m_OldReflectionTextureSize = 0;
private static bool s_InsideRendering = false;
// This is called when it‘s known that the object will be rendered by some
// camera. We render reflections and do other updates here.
// Because the script executes in edit mode reflections for the scene view
// camera will just work!
public void OnWillRenderobject()
{
if( !enabled || !renderer || !renderer.sharedMaterial || !renderer.enabled )
return;
Camera cam = Camera.current;
if( !cam )
return;
// Safeguard from recursive reflections.
if( s_InsideRendering )
return;
s_InsideRendering = true;
Camera reflectionCamera;
CreateMirrorobjects( cam out reflectionCamera );
// find out the reflection plane: position and normal in world space
// 镜面法线,X轴=right,Y轴=up,Z轴=forward
Vector3 pos = transform.position;
Vector3 normal = transform.forward;
if(mirroraxes==NormalAxes.X)
normal = transform.right;
if(mirroraxes==NormalAxes.Y)
normal = transform.up;
// Optionally disable pixel lights for reflection
int oldPixelLightCount = QualitySettings.pixelLightCount;
if( m_DisablePixelLights )
QualitySettings.pixelLightCount = 0;
UpdateCameraModes( cam reflectionCamera );
// Render reflection
// Reflect camera around reflection plane
float d = -Vector3.Dot (normal pos) - m_ClipPlaneOffset;
Vector4 reflectionPlane = new Vector4 (normal.x normal.y normal.z d);
Matrix4x4 reflection = Matrix4x4.zero;
CalculateReflectionMatrix (ref reflection reflectionPlane);
Vector3 oldpos = cam.transform.position;
Vector3 newpos = reflection.MultiplyPoint( oldpos );
reflectionCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection;
// Setup oblique projection matrix so that near plane is our reflection
// plane. This way we clip everything below/above it for free.
Vector4 clipPlane = CameraSpacePlane( reflectionCamera pos normal 1.0f );
Matrix4x4 projection = cam.projectionMatrix;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-07-07 13:27 Unity地面反射脚本和shader\
文件 4545 2014-07-07 13:27 Unity地面反射脚本和shader\MGKJ_ba
文件 6200 2014-07-07 13:27 Unity地面反射脚本和shader\MGKJ_Cubemap_1.00.shader
文件 5583 2014-07-07 13:27 Unity地面反射脚本和shader\MGKJ_Glass_ba
文件 5140 2014-07-07 13:27 Unity地面反射脚本和shader\MGKJ_Mirror_ba
文件 10426 2014-07-07 13:27 Unity地面反射脚本和shader\MirrorReflection.cs
文件 1183888 2014-07-07 13:27 Unity地面反射脚本和shader\MyCubeMap.cubemap
文件 1048620 2014-07-07 13:27 Unity地面反射脚本和shader\Normalmap_512.tga
文件 812 2014-07-07 13:27 Unity地面反射脚本和shader\Nromal_map_flat.tga
- 上一篇:硬件工程师 经典笔试面试题
- 下一篇:伺服电机的设计和特性
相关资源
- Unity3D登录界面工程
- unity3d反编译工具
-
UnityWebPla
yer及UnityWebPla yerFull -
UnityWebPla
yerFull - unity4.0官方正式版
- Behavior Designer 1.6.3(u2018.3.0).unitypa
- Unity纪念碑谷.rar
- A Pathfinding Project Pro v4.2.2.rar
- Unity 声音播放插件,支持将字符串转
- Gaia 1.7.2
- Unity3d实现扭动挤压浏览效果
- UnityShader卷轴效果
- 爱酱(绊爱Kizuna)模型
- 遗传算法越野小车unity5.5
- unity 3D 百度语音合成 并播放
- unity案例入门坦克大战源码
- Graph And Chart 1.91.unitypackage
- Animated Steel Coaster 1.51.rar
- Unity3D游戏开发.pdf 宣雨松著完整高清
- Unity3D版水果忍者
- unity3d爆炸特效包
- unity3d_见缝插针源码及报告.zip
- Unity3d车库场景模型
- unity3d 警察动画模型
- unity20多种烟雾以及爆炸特效
- unity博物馆.zip
- burpsuite_community社区版x86系统
- unity3D 新手引导遮罩,支持圆形和矩形
- 兼容unity的System.Drawing.dll
- unity3d枪支武器包FPS第一人称射击游戏
评论
共有 条评论