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:

相关推荐
南無忘码至尊2 小时前
Unity学习90天 - 第 6天 - 学习协程 Coroutine并实现每隔 2 秒生成一波敌人
学习·unity·c#·游戏引擎
张老师带你学3 小时前
unity 老版本资源迁移,第一人称,完整城市,有出身点房内视图,有gun shop视图,urp
科技·游戏·unity·模型·游戏美术
米猴设计师3 小时前
PS图案融合到褶皱布料上怎么弄?贴图教程
图像处理·人工智能·贴图·ps·nanobanana
mxwin11 小时前
Unity URP 下 UI 特效开发指南 深入探索顶点色、Mask 交互与扭曲特效的实战技巧
ui·unity·游戏引擎·shader
CandyU211 小时前
Unity入门
unity·游戏引擎
呆呆敲代码的小Y12 小时前
48个AI智能体搭建完整游戏开发工作室:Claude Code Game Studios
人工智能·游戏·unity·ai·游戏引擎·ai编程·ai游戏
思航14 小时前
Mcp for unity原理详解
unity·ai编程
一只蝉nahc1 天前
vue使用iframe内嵌unity模型,并且向模型传递信息,接受信息
前端·vue.js·unity
WiChP1 天前
【V0.1B6】从零开始的2D游戏引擎开发之路
java·log4j·游戏引擎
小拉达不是臭老鼠1 天前
Unity05_3D数学
学习·unity·游戏引擎