Ejemplo n.º 1
0
 public static void Initialize()
 {
     m_ZeroAmbientProbe.Clear();
     if (m_SkyboxMaterial == null)
     {
         m_SkyboxMaterial = new Material(Shader.Find("Skybox/Cubemap"));
     }
     if (m_ScreenQuadMesh == null)
     {
         m_ScreenQuadMesh           = new Mesh();
         m_ScreenQuadMesh.vertices  = new Vector3[] { new Vector3(-1f, -1f, 0f), new Vector3(1f, 1f, 0f), new Vector3(1f, -1f, 0f), new Vector3(-1f, 1f, 0f) };
         m_ScreenQuadMesh.triangles = new int[] { 0, 1, 2, 1, 0, 3 };
     }
     if (m_GBufferPatchMaterial == null)
     {
         m_GBufferPatchMaterial = new Material(EditorGUIUtility.LoadRequired("LookDevView/GBufferWhitePatch.shader") as Shader);
         m_DrawBallsMaterial    = new Material(EditorGUIUtility.LoadRequired("LookDevView/GBufferBalls.shader") as Shader);
     }
     if (m_LookDevCompositing == null)
     {
         m_LookDevCompositing = new Material(EditorGUIUtility.LoadRequired("LookDevView/LookDevCompositing.shader") as Shader);
     }
     if (m_DeferredOverlayMaterial == null)
     {
         m_DeferredOverlayMaterial = EditorGUIUtility.LoadRequired("SceneView/SceneViewDeferredMaterial.mat") as Material;
     }
     if (m_DefaultHDRI == null)
     {
         m_DefaultHDRI = EditorGUIUtility.Load("LookDevView/DefaultHDRI.exr") as Cubemap;
         if (m_DefaultHDRI == null)
         {
             m_DefaultHDRI = EditorGUIUtility.Load("LookDevView/DefaultHDRI.asset") as Cubemap;
         }
     }
     if (m_LookDevCubeToLatlong == null)
     {
         m_LookDevCubeToLatlong = new Material(EditorGUIUtility.LoadRequired("LookDevView/LookDevCubeToLatlong.shader") as Shader);
     }
     if (m_SelectionTexture == null)
     {
         m_SelectionTexture = new RenderTexture(250, 0x7d, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
     }
     if (m_BrightestPointRT == null)
     {
         m_BrightestPointRT = new RenderTexture(250, 0x7d, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default);
     }
     if (m_BrightestPointTexture == null)
     {
         m_BrightestPointTexture = new Texture2D(250, 0x7d, TextureFormat.RGBAHalf, false);
     }
 }
Ejemplo n.º 2
0
        public SphericalHarmonicsL2 ProjectCubeIntoSH(Cubemap src, int miplevel)
        {
            Vector3[] vectorArray1 = new Vector3[0x12];
            vectorArray1[0]    = new Vector3(0f, 0f, -1f);
            vectorArray1[1]    = new Vector3(0f, -1f, 0f);
            vectorArray1[2]    = new Vector3(-1f, 0f, 0f);
            vectorArray1[3]    = new Vector3(0f, 0f, 1f);
            vectorArray1[4]    = new Vector3(0f, -1f, 0f);
            vectorArray1[5]    = new Vector3(1f, 0f, 0f);
            vectorArray1[6]    = new Vector3(1f, 0f, 0f);
            vectorArray1[7]    = new Vector3(0f, 0f, 1f);
            vectorArray1[8]    = new Vector3(0f, -1f, 0f);
            vectorArray1[9]    = new Vector3(1f, 0f, 0f);
            vectorArray1[10]   = new Vector3(0f, 0f, -1f);
            vectorArray1[11]   = new Vector3(0f, 1f, 0f);
            vectorArray1[12]   = new Vector3(1f, 0f, 0f);
            vectorArray1[13]   = new Vector3(0f, -1f, 0f);
            vectorArray1[14]   = new Vector3(0f, 0f, -1f);
            vectorArray1[15]   = new Vector3(-1f, 0f, 0f);
            vectorArray1[0x10] = new Vector3(0f, -1f, 0f);
            vectorArray1[0x11] = new Vector3(0f, 0f, 1f);
            Vector3[]            vectorArray = vectorArray1;
            float                num         = 0f;
            SphericalHarmonicsL2 sl          = new SphericalHarmonicsL2();

            sl.Clear();
            int num2 = 0;

            while (num2 < 6)
            {
                Vector3 vector  = vectorArray[num2 * 3];
                Vector3 vector2 = -vectorArray[(num2 * 3) + 1];
                Vector3 vector3 = -vectorArray[(num2 * 3) + 2];
                Color[] pixels  = src.GetPixels((CubemapFace)num2, miplevel);
                int     num3    = src.width >> (miplevel & 0x1f);
                if (num3 < 1)
                {
                    num3 = 1;
                }
                float num4 = -1f + (1f / ((float)num3));
                float num5 = (2f * (1f - (1f / ((float)num3)))) / (num3 - 1f);
                int   num6 = 0;
                while (true)
                {
                    if (num6 >= num3)
                    {
                        num2++;
                        break;
                    }
                    float num7 = (num6 * num5) + num4;
                    int   num8 = 0;
                    while (true)
                    {
                        if (num8 >= num3)
                        {
                            num6++;
                            break;
                        }
                        Color   color   = pixels[num8 + (num6 * num3)];
                        float   num9    = (num8 * num5) + num4;
                        float   f       = (1f + (num9 * num9)) + (num7 * num7);
                        float   num11   = 4f / (Mathf.Sqrt(f) * f);
                        Vector3 vector4 = (vector3 + (vector * num9)) + (vector2 * num7);
                        vector4.Normalize();
                        Color color2 = (color * color.a) * 8f;
                        sl.AddDirectionalLight(-vector4, (QualitySettings.activeColorSpace != ColorSpace.Linear) ? color2 : color2.linear, num11 * 0.5f);
                        num += num11;
                        num8++;
                    }
                }
            }
            return(sl * (4f / num));
        }
Ejemplo n.º 3
0
        static public void Initialize()
        {
            m_ZeroAmbientProbe.Clear();

            // For some reason, a few frames after LoadRenderDoc reset the gfx device, the pointers turn null. Is there a better way to handle that?
            if (m_SkyboxMaterial == null)
            {
                m_SkyboxMaterial = new Material(Shader.Find("Skybox/Cubemap"));
            }

            if (m_ScreenQuadMesh == null)
            {
                // Draw a full screen quad with GBuffer patch material
                m_ScreenQuadMesh          = new Mesh();
                m_ScreenQuadMesh.vertices = new Vector3[]
                {
                    // Note: Invert Z or not should not have influence here.
                    new Vector3(-1, -1, 0),
                    new Vector3(1, 1, 0),
                    new Vector3(1, -1, 0),
                    new Vector3(-1, 1, 0)
                };

                m_ScreenQuadMesh.triangles = new int[]
                {
                    0, 1, 2, 1, 0, 3
                };
            }

            // Material can be null if we switch API device or when we init the first time. We can safely re-allocate everything if this is null
            if (m_GBufferPatchMaterial == null)
            {
                m_GBufferPatchMaterial = new Material(EditorGUIUtility.LoadRequired("LookDevView/GBufferWhitePatch.shader") as Shader);
                m_DrawBallsMaterial    = new Material(EditorGUIUtility.LoadRequired("LookDevView/GBufferBalls.shader") as Shader);
            }

            if (m_LookDevCompositing == null)
            {
                m_LookDevCompositing = new Material(EditorGUIUtility.LoadRequired("LookDevView/LookDevCompositing.shader") as Shader);
            }

            if (m_DeferredOverlayMaterial == null)
            {
                m_DeferredOverlayMaterial = EditorGUIUtility.LoadRequired("SceneView/SceneViewDeferredMaterial.mat") as Material;
            }

            if (m_DefaultHDRI == null)
            {
                m_DefaultHDRI = EditorGUIUtility.Load("LookDevView/DefaultHDRI.exr") as Cubemap;
                if (m_DefaultHDRI == null)
                {
                    m_DefaultHDRI = EditorGUIUtility.Load("LookDevView/DefaultHDRI.asset") as Cubemap;
                }
            }

            if (m_LookDevCubeToLatlong == null)
            {
                m_LookDevCubeToLatlong = new Material(EditorGUIUtility.LoadRequired("LookDevView/LookDevCubeToLatlong.shader") as Shader);
            }

            /*
             * // Debug code to remove
             * bool tutu = false;
             * if (tutu)
             * {
             *  Shader devShader = Shader.Find("Custom/DevShader2") as Shader;
             *  if (devShader != null)
             *      m_LookDevCubeToLatlong = new Material(devShader);
             * }
             */


            if (m_SelectionTexture == null)
            {
                m_SelectionTexture = new RenderTexture((int)LookDevEnvironmentWindow.m_HDRIWidth, (int)LookDevEnvironmentWindow.m_latLongHeight, 0, SystemInfo.GetGraphicsFormat(DefaultFormat.LDR));
            }

            if (m_BrightestPointRT == null)
            {
                m_BrightestPointRT = new RenderTexture((int)LookDevEnvironmentWindow.m_HDRIWidth, (int)LookDevEnvironmentWindow.m_latLongHeight, 0, GraphicsFormat.R16G16B16A16_SFloat);
            }

            if (m_BrightestPointTexture == null)
            {
                m_BrightestPointTexture = new Texture2D((int)LookDevEnvironmentWindow.m_HDRIWidth, (int)LookDevEnvironmentWindow.m_latLongHeight, TextureFormat.RGBAHalf, false);
            }
        }
Ejemplo n.º 4
0
    public SphericalHarmonicsL2 ProjectCubeIntoSH3Func(Cubemap src, int miplevel)
    {
        Vector4[] array = new Vector4[]
        {
            new Vector4(0f, 0f, -1f, 0f),
            new Vector4(0f, -1f, 0f, 0f),
            new Vector4(-1f, 0f, 0f, 0f),
            new Vector4(0f, 0f, 1f, 0f),
            new Vector4(0f, -1f, 0f, 0f),
            new Vector4(1f, 0f, 0f, 0f),
            new Vector4(1f, 0f, 0f, 0f),
            new Vector4(0f, 0f, 1f, 0f),
            new Vector4(0f, -1f, 0f, 0f),
            new Vector4(1f, 0f, 0f, 0f),
            new Vector4(0f, 0f, -1f, 0f),
            new Vector4(0f, 1f, 0f, 0f),
            new Vector4(1f, 0f, 0f, 0f),
            new Vector4(0f, -1f, 0f, 0f),
            new Vector4(0f, 0f, -1f, 0f),
            new Vector4(-1f, 0f, 0f, 0f),
            new Vector4(0f, -1f, 0f, 0f),
            new Vector4(0f, 0f, 1f, 0f)
        };
        Quaternion rotation = base.gameObject.transform.rotation;
        Matrix4x4  matrix4x = this.QuaternionToMatrix(rotation);

        for (int i = 0; i < 6; i++)
        {
            array[i] = matrix4x * array[i];
        }
        Shader.SetGlobalMatrix("_SkyRotation", matrix4x);
        float num = 0f;
        SphericalHarmonicsL2 sphericalHarmonicsL = default(SphericalHarmonicsL2);

        sphericalHarmonicsL.Clear();
        for (int j = 0; j < 6; j++)
        {
            Vector3 a      = array[j * 3];
            Vector3 a2     = -array[j * 3 + 1];
            Vector3 a3     = -array[j * 3 + 2];
            Color[] pixels = src.GetPixels((CubemapFace)j, miplevel);
            int     num2   = src.width >> miplevel;
            if (num2 < 1)
            {
                num2 = 1;
            }
            float num3 = -1f + 1f / (float)num2;
            float num4 = 2f * (1f - 1f / (float)num2) / ((float)num2 - 1f);
            for (int k = 0; k < num2; k++)
            {
                float num5 = (float)k * num4 + num3;
                for (int l = 0; l < num2; l++)
                {
                    Color   a4   = pixels[l + k * num2];
                    float   num6 = (float)l * num4 + num3;
                    float   num7 = 1f + num6 * num6 + num5 * num5;
                    float   num8 = 4f / (Mathf.Sqrt(num7) * num7);
                    Vector3 a5   = a3 + a * num6 + a2 * num5;
                    a5.Normalize();
                    Color color = a4 * a4.a * 8f;
                    sphericalHarmonicsL.AddDirectionalLight(-a5, (QualitySettings.activeColorSpace != ColorSpace.Linear) ? color : color.linear, num8 * 0.5f);
                    num += num8;
                }
            }
        }
        float rhs = 4f / num;

        sphericalHarmonicsL *= rhs;
        return(sphericalHarmonicsL);
    }