资源简介
绝对齐全的玻璃反光和镜面反射效果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文件
相关资源
- AngryBots unity3D源码版带资源
- Unity3d 插件 破碎效果 MeshExplosion
- unity3d最全面试题
- Haste Pro v1.8.6
- Unity3dforPsv开发资源和教程
- Unity3D的传送带工程实现
- 网狐U3D旗舰版源码全套包含服务器端
- Unity3d实现的十字路口的模拟
- Unity3D客户端PureMVC框架视屏讲解
- unity3d斗地主
- Unity4.x从入门到精通课本及源码
- Shader编程教程 完整
- Unity3d视频教程
- [手游] Unity3D《最后一战》全套完整源
- Unity3D_4.x_5.x全系列通用一键破解工具
- SUIMONO Water System v2.1.6最新版
- Unity3D一个打地鼠游戏的De‘moemo
- Unity3d ShaderLab开发实战详解pdf+源码
- Unity3D图表插件——柱状图、折
- Unity3D中文api开发手册
- Unity3D5.6201720182019中文版本语言包.ra
- 基于Unity3D的矿井提升机虚拟实训装置
- Unity3D AssetBundle的无缝地图实现
- Dynamic Bone 1.20 制作ru摇臀摇头发尾巴摆
- unity3d 打包成webgl 错误解决办法
- unity3D汉化版(汉化补丁)不需要安装
- 2D平台动作游戏插件 Smart Platform Coll
- UGUI 官方demo
- unity3d 游戏插件 Mesh Explosion 物体破碎
- unity3d 素材包粒子特效的
评论
共有 条评论