资源简介
绝对齐全的玻璃反光和镜面反射效果shader

代码片段和文件信息
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class Mirror : MonoBehaviour
{
public bool m_DisablePixelLights = true;
public int m_TextureSize = 256;
public float m_ClipPlaneOffset = 0.07f;
public bool m_IsFlatMirror = true;
public layerMask m_Reflectlayers = -1;
private Hashtable m_ReflectionCameras = new Hashtable();
private RenderTexture m_ReflectionTexture = null;
private int m_OldReflectionTextureSize = 0;
private static bool s_InsideRendering = false;
public void OnWillRenderobject()
{
if( !enabled || !renderer || !renderer.sharedMaterial || !renderer.enabled )
return;
Camera cam = Camera.current;
if( !cam )
return;
if( s_InsideRendering )
return;
s_InsideRendering = true;
Camera reflectionCamera;
CreateMirrorobjects( cam out reflectionCamera );
Vector3 pos = transform.position;
Vector3 normal;
if(m_IsFlatMirror){
normal = transform.up;
}
else{
normal= transform.position - cam.transform.position ;
normal.Normalize();
}
int oldPixelLightCount = QualitySettings.pixelLightCount;
if( m_DisablePixelLights )
QualitySettings.pixelLightCount = 0;
UpdateCameraModes( cam reflectionCamera );
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;
Vector4 clipPlane = CameraSpacePlane( reflectionCamera pos normal 1.0f );
Matrix4x4 projection = cam.projectionMatrix;
CalculateObliqueMatrix (ref projection clipPlane);
reflectionCamera.projectionMatrix = projection;
reflectionCamera.cullingMask = ~(1<<4) & m_Reflectlayers.value;
reflectionCamera.targetTexture = m_ReflectionTexture;
GL.SetRevertBackfacing (true);
reflectionCamera.transform.position = newpos;
Vector3 euler = cam.transform.eulerAngles;
reflectionCamera.transform.eulerAngles = new Vector3(0 euler.y euler.z);
reflectionCamera.Render();
reflectionCamera.transform.position = oldpos;
GL.SetRevertBackfacing (false);
Material[] materials = renderer.sharedMaterials;
foreach( Material mat in materials ) {
if( mat.HasProperty(“_Ref“) )
mat.SetTexture( “_Ref“ m_ReflectionTexture );
}
if( m_DisablePixelLights )
QualitySettings.pixelLightCount = oldPixelLightCount;
s_InsideRendering = false;
}
vo
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1954 2012-08-11 15:25 Mirror Shaders\Mirror-AlphaBumpSpec.shader
文件 1730 2012-08-11 16:35 Mirror Shaders\Mirror-AlphaSpecSphere.shader
文件 1530 2012-08-11 06:02 Mirror Shaders\Mirror-BumpSpec.shader
文件 7777 2012-08-11 14:01 Mirror Shaders\Mirror.cs
目录 0 2012-08-11 16:35 Mirror Shaders
----------- --------- ---------- ----- ----
12991 5
- 上一篇:基础算法1.ppt
- 下一篇:leaflet加载本地shp文件
相关资源
- Unity3D登录界面工程
- unity3d反编译工具
-
UnityWebPla
yerFull - Unity纪念碑谷.rar
- Unity3d实现扭动挤压浏览效果
- unity案例入门坦克大战源码
- Unity3D游戏开发.pdf 宣雨松著完整高清
- Unity3D版水果忍者
- unity3d爆炸特效包
- unity3d_见缝插针源码及报告.zip
- Unity3d车库场景模型
- unity3d 警察动画模型
- unity3D 新手引导遮罩,支持圆形和矩形
- unity3d枪支武器包FPS第一人称射击游戏
- unity3d制作贪吃蛇
- unity3D暴力街区射击大战游戏源码
- Unity3D 实战视频教程 保卫萝卜 2D 游戏
- unity3d调用中央气象局城市天气数据,
- Unity 3D Paint in 3D (1.7.3)
- 2014年最新最好的Unity3d圣典之中文脚本
- Unity3D搓牌效果支持4个方向
- Unity3D课程设计 模拟火焰效果
- 贝塞尔曲线的unity3d实现
- [资源插件]Unity3D_UGUI HUD Text v1.4.1.zip
- ShaderlabVSCode 1.1.6.unitypackage
- Camera Path Animator unity3d 插件
- Unity录屏模块封装清晰的可调AVPro Mo
- FBX格式人物模型,资源齐全,带动画
- Unity3D 3D炸弹超人Demo
- unity3d坐标轴插件
评论
共有 条评论