使用unity3D实现全景图像查看器
来源:互联网 发布:淘宝隐形降权查询工具 编辑:程序博客网 时间:2024/06/07 01:19
转载自 http://www.taidous.com/thread-52133-1-1.html
Shader "Unlit / Pano360Shader"{ Properties{ _MainTex("Base(RGB)", 2D) = "white"{} _Color("Main Color", Color) = (1,1,1,0.5)}SubShader{ Tags{ "RenderType" = "Opaque" } //This is used to print the texture inside of the sphere Cull Front CGPROGRAM#pragma surface surf SimpleLambert half4 LightingSimpleLambert(SurfaceOutput s, half3 lightDir, half atten){ half4 c; c.rgb = s.Albedo; return c;}sampler2D _MainTex;struct Input{ float2 uv_MainTex; float4 myColor : COLOR;};fixed3 _Color;void surf(Input IN, inout SurfaceOutput o){ //This is used to mirror the image correctly when printing it inside of the sphere IN.uv_MainTex.x = 1 - IN.uv_MainTex.x; fixed3 result = tex2D(_MainTex, IN.uv_MainTex)*_Color; o.Albedo = result.rgb; o.Alpha = 1;}ENDCG}Fallback "Diffuse"}
遮罩Shader
[AppleScript] 纯文本查看 复制代码
Shader "ImageEffect/MaskIcon"{ Properties { [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {} _Mask("Base (RGB)", 2D) = "white" {} _Color("Tint", Color) = (1,1,1,1) _StencilComp("Stencil Comparison", Float) = 8 _Stencil("Stencil ID", Float) = 0 _StencilOp("Stencil Operation", Float) = 0 _StencilWriteMask("Stencil Write Mask", Float) = 255 _StencilReadMask("Stencil Read Mask", Float) = 255 _ColorMask("Color Mask", Float) = 15 [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0 } SubShader { Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" "CanUseSpriteAtlas" = "True" } Stencil { Ref[_Stencil] Comp[_StencilComp] Pass[_StencilOp] ReadMask[_StencilReadMask] WriteMask[_StencilWriteMask] } Cull Off Lighting Off ZWrite Off ZTest[unity_GUIZTestMode] Blend SrcAlpha OneMinusSrcAlpha ColorMask[_ColorMask] Pass { CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"#include "UnityUI.cginc"#pragma multi_compile __ UNITY_UI_ALPHACLIP struct a2v { fixed2 uv : TEXCOORD0; half4 vertex : POSITION; float4 color : COLOR; }; fixed4 _Color; struct v2f { fixed2 uv : TEXCOORD0; half4 vertex : SV_POSITION; float4 color : COLOR; }; sampler2D _MainTex; sampler2D _Mask; v2f vert(a2v i) { v2f o; o.vertex = mul(UNITY_MATRIX_MVP, i.vertex); o.uv = i.uv; o.color = i.color * _Color; return o; } fixed4 frag(v2f i) : COLOR { half4 color = tex2D(_MainTex, i.uv) * i.color; half4 mask = tex2D(_Mask, i.uv); color.a *= mask.a; return color; } ENDCG } }}
C#代码
[AppleScript] 纯文本查看 复制代码
using System.Collections;using System.Collections.Generic;using UnityEngine;public class Pano360 : MonoBehaviour { public Transform container; float turnSpeedMouse=50; /// <summary> /// 第一次按下的位置 /// </summary> private Vector2 first = Vector2.zero; /// <summary> /// 鼠标的拖拽位置(第二次的位置) /// </summary> private Vector2 second = Vector2.zero; /// <summary> /// 旋转的角度 /// </summary> private float angle = 3f; void OnGUI() { if (Event.current.type == EventType.MouseDown) { //记录鼠标按下的位置 first = Event.current.mousePosition; } if (Event.current.type == EventType.MouseDrag) { //记录鼠标拖动的位置 second = Event.current.mousePosition; if (second.x < first.x) { //拖动的位置的x坐标比按下的位置的x坐标小时,响应向左事件 this.transform.Rotate(Vector3.up , angle); container.Rotate(new Vector3(0 , angle * (-1) , 0f) * Time.deltaTime * turnSpeedMouse); transform.Rotate(new Vector3(angle , 0 , 0) * Time.deltaTime * turnSpeedMouse); } if (second.x > first.x) { //拖动的位置的x坐标比按下的位置的x坐标大时,响应向右事件 this.transform.Rotate(Vector3.down , angle); container.Rotate(new Vector3(0 , angle * (1) , 0f) * Time.deltaTime * turnSpeedMouse); transform.Rotate(new Vector3(angle , 0 , 0) * Time.deltaTime * turnSpeedMouse); } first = second; } }}
阅读全文
0 0
- 使用unity3D实现全景图像查看器
- unity3d利用pano2VR实现全景视图效果
- unity3d利用pano2VR实现全景视图效果
- matlab实现全景图像拼接技术
- Opencv 使用Stitcher类图像拼接生成全景图像
- unity3d 使用Helios渲染360度全景视频
- 全景图像拼接wave correct部分实现原理
- 【OpenCV学习笔记 024】Stitcher类实现全景图像拼接
- 使用threejs实现3D全景漫游
- 全景图像的拼接
- 360全景图像拼接
- opencv图像全景拼接
- 全景图像展开
- 全景:全景图像展开算法opencv代码
- Opencv Sift和Surf特征实现图像无缝拼接生成全景图像
- Opencv Sift和Surf特征实现图像无缝拼接生成全景图像
- Opencv Sift和Surf特征实现图像无缝拼接生成全景图像
- Unity3d陀螺仪看全景图
- 阿里云ECS搭建Docker
- centos7 32bit 安装epel
- wordpress后台无法登录问题
- leetcode 回文数
- 如何去掉git diff 时的 \ no newline at end of file
- 使用unity3D实现全景图像查看器
- redis远程连接超时
- 图像处理: 如何将 像素值 控制在 值域[0, 255]
- MicroPython分析
- yii2.0-Ueditor百度编辑器
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)
- Android系统启动流程与刷机包对应关系
- 实验3:栈和队列的基本操作实现及其应用——顺序队列和链队列
- 解决org.apache.ibatis.binding.BindingException: Type interface xxx is not known to the MapperRegistry