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 天前
Niagara粒子系统-超炫酷的闪电特效(加餐 纸牌螺旋上升效果)
游戏·游戏引擎
_Li.5 天前
Simulink - 6DOF (Euler Angles)
人工智能·算法·机器学习·游戏引擎·cocos2d
weixin_424294675 天前
Unity 调用Steamworks API 的 SteamUserStats.RequestCurrentStats()报错
unity·游戏引擎·steamwork
HoFunGames5 天前
Unity小地图,Easy Minimap System MT-GPS插件
unity·游戏引擎
wy3258643645 天前
Unity 新输入系统InputSystem(基本操作)
unity·c#·游戏引擎
WarPigs5 天前
着色器multi_compile笔记
unity·着色器
ECHO飞跃 0125 天前
Unity2019 本地推理 通义千问0.5-1.5B微调导入
人工智能·深度学习·unity·llama
Unity游戏资源学习屋5 天前
【Unity UI资源包】GUI Pro - Casual Game 专为休闲手游打造的专业级UI资源包
ui·unity
冰凌糕5 天前
Unity3D Shader 顶点法线外扩实现描边效果
unity
星和月5 天前
Untiy使用说明
c#·游戏引擎