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:

相关推荐
Oiiouui18 小时前
Godot-GridGame架构DI容器全局联动设计
架构·游戏引擎·godot
平行云1 天前
建筑BIM/3D可视化轻量级实时评审与分享方案
unity·ue5·3dsmax·实时云渲染·云桌面·云游戏·建筑bim
2501_915106322 天前
Windows 上开发 Unity iOS,使用 KXBuild 进行真机调试、性能采样与打包 ipa
windows·vscode·unity·ios·个人开发·swift·敏捷流程
FFFFujige2 天前
【Unity】一个的Dots用Ruhanka踩坑记录
unity·游戏引擎
wgslucky2 天前
Godot UI管理与使用
游戏引擎·godot
Oiiouui2 天前
Godot-GridGame架构屏幕UI层
架构·游戏引擎·godot
凯基迪科技3 天前
Unity游戏加密锁逆向方案、选型与攻防分析
游戏·unity·游戏引擎
阿松爱学习3 天前
【Unity开发】局部区域截图功能实现
unity·c#
淡海水3 天前
08-02-优化-LINQ与函数式编程的GC代价
unity·c#·.netcore·linq·gc
警醒与鞭策3 天前
Codex桌面版与Claude桌面版使用设置
android·unity·ai·性能优化