-
大小: 5KB文件類型: .rar金幣: 2下載: 0 次發布日期: 2021-05-09
- 語言: 其他
- 標簽: unityshader??反射??實時??
資源簡介
unity鏡面反射材質,支持實時鏡面反射,模糊反射,高光,法線,光澤度,反射強度等參數。手機可支持。

代碼片段和文件信息
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
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1730??2012-08-11?16:35??Mirror-AlphaSpecSphere.shader
?????文件???????1530??2012-08-11?06:02??Mirror-BumpSpec.shader
?????文件???????7777??2012-08-11?14:01??Mirror.cs
?????文件???????1954??2012-08-11?15:25??Mirror-AlphaBumpSpec.shader
-----------?---------??----------?-----??----
????????????????12991????????????????????4
- 上一篇:fpga實現can總線
- 下一篇:linux網絡編程源碼
評論
共有 條評論