Unity图形学之CubeMap立方体贴图

1.CubeMap:有六个面的贴图组成

  1. 假反射:反射天空盒子

(1)正常UV采样:

(2)Cube的采样:利用反射角采样,反射角X和Cube的交点采样

cs 复制代码
Shader "Custom/TestReflect"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _CubeMap("Cube Map",CUBE) = "" {}
        _CubePower("Cube Power",float) = 0.5
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all  light types
        #pragma surface surf Lambert
        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0
        sampler2D _MainTex;
        samplerCUBE _CubeMap;
        struct Input
        {
            float2 uv_MainTex;
            float3 worldRefl;
        };
        fixed4 _Color;
        float _CubePower;
        
        void surf (Input IN, inout SurfaceOutput o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            o.Emission = texCUBE(_CubeMap,IN.worldRefl).rgb*_CubePower;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

3.真反射:立方体上直接反映场景中的所有渲染的东西,都反射显示到cube上了,非常 消耗性能

(1)创建一个RenderTexture:

(2)主相机上的Target Texture设置为RenderTexture:

(3)需要反射的立方体的材质球上的贴图设置为RenderTexture:

相关推荐
懒狗跑ai的程序员Brain18 小时前
如何利用粒子系统在unity制作一个烟花(粒子系统学习向)
学习·unity·游戏引擎
xcLeigh19 小时前
Unity基础:材质与纹理入门——给物体穿上“衣服“
unity·游戏引擎·材质
unityのkiven19 小时前
理解 GUILayout 与 EditorGUILayout,并探究 ScrollView 滚轮失效可能的原因
unity
ellis197019 小时前
u3d插件xLua[二]例2:U3DScripting,例3:UIEvent分析
unity·lua
派葛穆1 天前
Unity-UI 输入框功能
ui·unity·游戏引擎
玖玥拾1 天前
Unity3D RPG 入门项目(一)开场动画/人物移动/摄像机跟随场景切换
unity·游戏引擎
2401_894915531 天前
GEO 搜索优化完整源码从零部署:环境配置、集群搭建全流程
开发语言·python·tcp/ip·算法·unity
WarPigs1 天前
PC端加载安卓AB包资源显示紫色的问题
unity
scott.cgi1 天前
Unity使用AndroidX获取,导航栏与虚拟键盘的高度
unity·androidx·keyboard·导航栏高度·虚拟键盘高度·判断键盘关闭·获取虚拟键盘高度
丁小未2 天前
Unity车机地图Tile流式渲染系统高性能架构方案
unity·架构·ecs·dots·车机系统·车机系统架构图