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:

相关推荐
优雅永不过时·29 分钟前
实现一个漂亮的Three.js 扫光地面 圆形贴图扫光
前端·javascript·智慧城市·three.js·贴图·shader
LouSean39 分钟前
Unity按钮事件冒泡
经验分享·笔记·学习·unity·游戏引擎
VTheShow40 分钟前
Unity Gizmos
unity
龙湾开发3 小时前
计算机图形学编程(使用OpenGL和C++)(第2版)学习笔记 05.纹理贴图
c++·笔记·学习·3d·图形渲染·贴图
虾球xz10 小时前
游戏引擎学习第264天:将按钮添加到分析器
c++·学习·游戏引擎
虾球xz12 小时前
游戏引擎学习第266天:添加顶部时钟概览视图。
数据库·c++·学习·游戏引擎
Magnum Lehar13 小时前
ApophisZerg的vulkan游戏引擎的platform平台
游戏引擎
虾球xz14 小时前
游戏引擎学习第267天:为每个元素添加裁剪矩形
c++·学习·游戏引擎
惊鸿醉16 小时前
Unity_JK框架【4】MonoSystem 和 协程工具类 的剖析与实践
游戏·unity·单例模式
FAREWELL000751 天前
Untiy基础学习(六)MonoBehaviour基类的简单介绍
学习·unity·游戏引擎