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:

相关推荐
程序猿多布5 分钟前
Unity + HybirdCLR热更新 入门篇
unity·hybirdclr
变身缎带8 分钟前
Unity中的MonoSingleton<T>与Singleton<T>
unity·单例模式·c#·游戏引擎
suixinger_lmh36 分钟前
功能结构整理
unity·设计模式·c#·源代码管理
EucliwoodXT2 小时前
【Unity】相机 Cameras
unity·游戏引擎·相机·camera
程序猿多布4 小时前
Unity使用Lua框架和C#框架开发游戏的区别
unity·c#·lua
EQ-雪梨蛋花汤6 小时前
【Part 3 Unity VR眼镜端播放器开发与优化】第二节|VR眼镜端的开发适配与交互设计
unity·交互·vr
CApp9 小时前
GODOT引擎学习日志
学习·游戏引擎·godot
AgilityBaby19 小时前
UE5打包项目设置Project Settings(打包widows exe安装包)
c++·3d·ue5·游戏引擎·unreal engine
Magnum Lehar1 天前
vulkan游戏引擎的vulkan_utils实现
游戏引擎
画中影1 天前
AR/MR实时光照阴影开发教程
unity·ar·mr·实时光照阴影·光影变换·pico4 ultra