资源简介
本资源是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
- 上一篇:硬件工程师 经典笔试面试题
- 下一篇:伺服电机的设计和特性
相关资源
- Vive Input Utility.unitypackage
- [新出炉]Unity 2017 游戏优化 英文原版
- unity框选demo
- unity2018 package manager引入本地包Demo
- UnityShader 用Plane实现旗帜飘扬效果
- unity中道路快速生成插件
- unity插件连接安卓蓝牙测试可用
- unity语音插件
- Unity3D学习 愤怒的小鸟之Play界面二
- Unity3D 海洋,海水效果
- Uniwebview3.0
- unity3d雷达图
- Unity Vectrosity5.6 最新版
- unity 卡通风格室内模型
- Unity3D UGUI源代码源码分享
- Unity打包合并为一个.exe
- 5款Unity3D制作的小游戏,新手必备看评
- Optimized ScrollView Adapter 4.2
- 之UV动画
- Unity 精伦电子阅读器 二次开发 亲测
- Unity简单跳棋项目
- Unity3d 第三人称射击源码
- shaderforge支持unity2018的源代码和插件
- unity3D猜图小游戏
- Unity3D 第三人称射击游戏代码
- UnityGUI强大10多个统计DIY自定义组件分
- Unity3D铅笔风格滤镜
- 加载PPTUnity.unitypackage
- unity3d动态天空
- Unity3D学习 愤怒的小鸟之关卡选择界面
评论
共有 条评论