예제 #1
0
    static void SetAmbientProbeShaderUniforms(CommandBuffer cmd, AmbientProbeData ambientProbeData)
    {
        // Ambient probe, i.e. direct sky contribution
        if (ms_AmbientProbeSC == null || ms_AmbientProbeSC.Length != 7)
        {
            ms_AmbientProbeSC = new Vector4[7];
        }

        if (ambientProbeData != null)
        {
#if HDRP_ENABLED
            cmd.SetGlobalVectorArray(Uniforms._AmbientProbeSH, ambientProbeData.sh);
#else
            Shader.SetGlobalVectorArray(Uniforms._AmbientProbeSH, ambientProbeData.sh);
#endif
        }
        else
        {
            SphericalHarmonicsL2 ambientProbe = RenderSettings.ambientProbe;
            // LightProbes.GetShaderConstantsFromNormalizedSH(ref ambientProbe, m_AmbientProbeSC);
            GetShaderConstantsFromNormalizedSH(ref ambientProbe, ms_AmbientProbeSC);
#if HDRP_ENABLED
            cmd.SetGlobalVectorArray(Uniforms._AmbientProbeSH, ms_AmbientProbeSC);
#else
            Shader.SetGlobalVectorArray(Uniforms._AmbientProbeSH, ms_AmbientProbeSC);
#endif
        }
    }
    public void BakeAmbientProbe()
    {
        string dataPath = SceneToOcclusionProbeDataPath(gameObject.scene, "AmbientProbeData");
        // We don't care where was the old asset we were referencing. The new one has to be at the
        // canonical path. So we check if it's there already.
        AmbientProbeData oldData = m_AmbientProbeData;

        m_AmbientProbeData = AssetDatabase.LoadMainAssetAtPath(dataPath) as AmbientProbeData;

        if (m_AmbientProbeData == null || m_AmbientProbeData != oldData)
        {
            // Assigning a new asset, dirty the scene that contains it, so that the user knows to save it.
            EditorUtility.SetDirty(this);
            EditorSceneManager.MarkSceneDirty(gameObject.scene);
        }

        if (m_AmbientProbeData == null)
        {
            m_AmbientProbeData = ScriptableObject.CreateInstance <AmbientProbeData>();
            AssetDatabase.CreateAsset(m_AmbientProbeData, dataPath);
        }

        var ambientProbe = RenderSettings.ambientProbe;

        m_AmbientProbeData.sh = new Vector4[7];
        // LightProbes.GetShaderConstantsFromNormalizedSH(ref ambientProbe, m_AmbientProbeData.sh);
        GetShaderConstantsFromNormalizedSH(ref ambientProbe, m_AmbientProbeData.sh);
        EditorUtility.SetDirty(m_AmbientProbeData);
    }