创建立方体纹理【Unity Shader 入门精要10.1.2】

创建环境映射的立方体纹理C#

public class RenderCubemapWizard : ScriptableWizard
{

    public Transform renderFromPosition;
    public Cubemap cubemap;

    void OnWizardUpdate()
    {
        helpString = "Select transform to render from and cubemap to render into";
        isValid = (renderFromPosition != null) && (cubemap != null);
    }

    void OnWizardCreate()
    {
        // create temporary camera for rendering
        GameObject go = new GameObject("CubemapCamera");
        go.AddComponent();
        // place it on the object
        go.transform.position = renderFromPosition.position;
        go.transform.rotation = Quaternion.identity;
        // render into cubemap		
        go.GetComponent().RenderToCubemap(cubemap);

        // destroy temporary camera
        DestroyImmediate(go);
    }

    [MenuItem("GameObject/Render into Cubemap")]
    static void RenderCubemap()
    {
        ScriptableWizard.DisplayWizard(
            "Render cubemap", "Render!");
    }
}

之后可以在GameObject->Render  into cubemap中打开

创建立方体纹理【Unity Shader 入门精要10.1.2】_第1张图片

面板样子

Render From Position:放入一个空节点,用来获取采集位置

Cubemap:在project下右键->create->Legacy->Cubmap(记得勾选Inspector面板下的Readable)

创建立方体纹理【Unity Shader 入门精要10.1.2】_第2张图片

 

你可能感兴趣的:(创建立方体纹理【Unity Shader 入门精要10.1.2】)