Example #1
0
    public override void OnInspectorGUI()
    {
        Manager = target as NuajManager;
        if ( Manager == null )
        {	// Invalid manager !
            Debug.LogError( "Invalid NuajManager to inspect in GUI !" );
            return;
        }

        // Setup the current UNDO target
        GUIHelpers.ms_UNDOObject = Manager;

        // Show the tab control
        GUI.changed = false;
        GUIHelpers.TabPage( ref m_SelectedTab, m_ModuleTabCaptions );
        ModuleEditorBase	ModuleEditor = m_ModuleEditors[m_SelectedTab];
        if ( ModuleEditor == null )
            return;

        ModuleEditor.OnInspectorGUIAdvanced();

        GUI.enabled = true;

        // Mark the manager as dirty
        if ( GUI.changed )
            EditorUtility.SetDirty( target );
    }
        internal override void UpScaleTechniqueChanged( NuajManager.UPSCALE_TECHNIQUE _Technique )
        {
            base.UpScaleTechniqueChanged( _Technique );

            // Forward to layers
            foreach ( CloudLayerBase Layer in CloudLayers )
                Layer.UpScaleTechniqueChanged( _Technique );
        }
            internal override void UpScaleTechniqueChanged( NuajManager.UPSCALE_TECHNIQUE _Technique )
            {
                base.UpScaleTechniqueChanged( _Technique );

                // Re-allocate render targets
                DestroyRenderTargets();
                CreateRenderTargets( m_Owner.m_Width, m_Owner.m_Height );
            }
Example #4
0
        /// <summary>
        /// Computes the luminance of the provided image by LOG-downscaling to a 1x1 target
        /// </summary>
        /// <param name="_SceneTexture">The source image containing the unaffected scene rendering to compute the luminance from</param>
        /// <param name="_ScatteringTexture">The source image containing the scene's scattering and extinction to alter the source scene with</param>
        /// <param name="_SceneDirectionalLuminanceMultiplier">The factor to apply to scene's directional light color for LDR->HDR conversion</param>
        /// <param name="_SceneAmbientLuminanceLDR">The scene's LDR ambient light color</param>
        /// <param name="_SceneAmbientLuminanceHDR">The scene's HDR ambient light color</param>
        /// <param name="_bSceneIsHDR">True if the source scene was rendered in LDR</param>
        /// <returns>The global luminance of the image</returns>
        public float ComputeImageLuminanceLog( NuajManager _Caller, RenderTexture _SceneTexture, RenderTexture _ScatteringTexture, float _SceneDirectionalLuminanceMultiplier, float _SceneAmbientLuminanceLDR, float _SceneAmbientLuminanceHDR, bool _bSceneIsHDR )
        {
            if ( m_MaterialLog == null )
            {	// Damn it !
                Help.LogError( "Image Downscale Luminance DISABLED ! => Recreate render targets..." );
                return 1.0f;
            }

            // Downscale
            m_MaterialLog.SetFloat( "_LerpAvgMax", m_AverageOrMax );
            m_MaterialLog.SetTexture( "_TexScattering", _ScatteringTexture );
            m_MaterialLog.SetFloat( "_SceneDirectionalLuminanceFactor", _SceneDirectionalLuminanceMultiplier );
            m_MaterialLog.SetFloat( "_SceneAmbientLuminanceLDR", _SceneAmbientLuminanceLDR );
            m_MaterialLog.SetFloat( "_SceneAmbientLuminanceLDR2HDR", _SceneAmbientLuminanceHDR / Math.Max( 1e-3f, _SceneAmbientLuminanceLDR ) );

            RenderTexture	SourceTexture = _SceneTexture;
            int		MaterialPassIndex = _bSceneIsHDR ? 1 : 0;

            #if USE_FIXED_RENDERTARGETS
            Vector3	dUV = Vector3.zero;
            for ( int PassIndex=0; PassIndex < m_MipMaps.Length; PassIndex++ )
            {
                // Setup the delta UV to reach for
                dUV.x = 1.0f / SourceTexture.width;
                dUV.y = 1.0f / SourceTexture.height;
                m_MaterialLog.SetVector( "_dUV", dUV );

                // Downscale
                m_MaterialLog.Blit( SourceTexture, m_MipMaps[PassIndex], MaterialPassIndex );
            //Help.LogDebug( "ToneMapping Pass #" + PassIndex + " SourceSize=" + SourceTexture.width + "x" + SourceTexture.height + " TargetSize=" + m_MipMaps[PassIndex].width + "x" + m_MipMaps[PassIndex].height + " dUV=" + dUV );

                // Next level
                SourceTexture = m_MipMaps[PassIndex];
                MaterialPassIndex = 2;
            }

            // Last blit from 2x2 to 1x1
            _Caller.RenderToCPU( SourceTexture, 0, m_Material, 3 );
            #else
            int	CurrentWidth = m_Width;
            int	CurrentHeight = m_Height;
            RenderTexture	TargetTexture = null;
            Vector3	dUV = Vector3.zero;
            for ( int PassIndex=0; PassIndex < m_MipLevelsCount; PassIndex++ )
            {
                // Setup the delta UV to reach for
                dUV.x = 1.0f / SourceTexture.width;
                dUV.y = 1.0f / SourceTexture.height;
                m_Material.SetVector( "_dUV", dUV );

                // Create target mip map
                CurrentWidth = Math.Max( 2, CurrentWidth + 1 >> 1 );
                CurrentHeight = Math.Max( 2, CurrentHeight + 1 >> 1 );
                TargetTexture = Help.CreateTempRT( CurrentWidth, CurrentHeight, RenderTextureFormat.ARGBHalf, FilterMode.Point, TextureWrapMode.Clamp );

                // Downscale
                m_Material.Blit( SourceTexture, TargetTexture, MaterialPassIndex );

                // Next level
                if ( SourceTexture != null && SourceTexture != _SceneTexture )
                    Help.ReleaseTemporary( SourceTexture );
                SourceTexture = TargetTexture;
                MaterialPassIndex = 2;
            }

            // Last blit from 2x2 to 1x1
            _Caller.RenderToCPU( SourceTexture, 0, m_Material, 3 );

            Help.ReleaseTemporary( SourceTexture );
            #endif
             			// HDR result is packed in a RGBA32 color
            Color	PackedResult = _Caller.CPUReadBack( 0 );
            float	Result = PackedResult.b * 65535.0f + PackedResult.g * 255.0f + PackedResult.r;

            return Math.Max( 0.001f, Result );
        }
Example #5
0
 /// <summary>
 /// Called by the manager whenever the upscale technique changed
 /// </summary>
 internal virtual void UpScaleTechniqueChanged( NuajManager.UPSCALE_TECHNIQUE _Technique )
 {
 }
 public ModuleEditorMain( NuajManager _Manager )
     : base(null)
 {
     m_Module = _Manager;
 }
    void OnGUI()
    {
        m_bUsingGUI = false;
        if ( Manager == null )
        {	// Get the manager first...
            Manager = FindObjectOfType( typeof(NuajManager) ) as NuajManager;
            if ( Manager == null )
                return;
        }

        // Retrieve the orchestrators
        if ( Orch == null )
            Orch = FindObjectOfType( typeof(NuajOrchestrator) ) as NuajOrchestrator;
        bool	bCanShowSimpleMode = Orch != null;

        // Watermark
        if ( Watermark )
            GUI.Label( new Rect( Screen.width - 0.0f - Watermark.width, Screen.height - 4.0f - Watermark.height, Watermark.width, Watermark.height ), new GUIContent( Watermark ) );

        // Display
        X = Y = 0.0f;

        Label( "Arrow Keys + Space : Move", 250.0f );
        Label( "Left Mouse : Look. Return : Resume demo", 300.0f );

        if ( !(ShowControls = CheckBox( "Show Controls", ShowControls )) )
            return;

        // Show FPS
        if ( FPSDisplay != null )
            FPSDisplay.active = CheckBox( "Show FPS", FPSDisplay.active );

        PreviousY();	// Come back
        if ( bCanShowSimpleMode && GUI.Button( new Rect( X + 120.0f, NextY(), 120.0f, STANDARD_HEIGHT ), AdvancedMode ? "Simple" : "Advanced" ) )
            AdvancedMode = !AdvancedMode;

        Indent();

        Separate( 4 );

        if ( Orch != null && !AdvancedMode )
        {	// ==== SIMPLE CONTROLS ====
            // Simple Day/Night
            Orch.TimeOfDay = Slider( "Time of Day", Orch.TimeOfDay, 0.0f, 24.0f );
            Orch.DensityMultiplierAtNight = Slider( "Sunset Drama", Orch.DensityMultiplierAtNight, 0.0f, 8.0f );

            // Weather interpolant
            GUI.Label( new Rect( X, Y, 100.0f, STANDARD_HEIGHT ), "Source Weather" );
            GUI.Label( new Rect( X + 300.0f, Y, 100.0f, STANDARD_HEIGHT ), "Target Weather" );
            NextY();
            Orch.WeatherTypeSource = (NuajOrchestrator.WEATHER_PRESETS) SourcePreset.List( new Rect( X, Y, 100.0f, STANDARD_HEIGHT ), (int) Orch.WeatherTypeSource, ComboBoxContents, GUIStyle.none );
            Orch.WeatherBalance = HorizontalSlider( new Rect( X + 100.0f, Y + 4, 200.0f, STANDARD_HEIGHT-8.0f ), Orch.WeatherBalance, 0.0f, 1.0f );
            Orch.WeatherTypeTarget = (NuajOrchestrator.WEATHER_PRESETS) TargetPreset.List( new Rect( X + 300.0f, Y, 100.0f, STANDARD_HEIGHT ), (int) Orch.WeatherTypeTarget, ComboBoxContents, GUIStyle.none );
            NextY();
            Orch.WindForce = Slider( "Wind", Orch.WindForce, 0.0f, 0.2f );
        }
        else
        {	// ==== ADVANCED CONTROLS ====
            // Sun
            Manager.SunElevation = Slider( "Sun Elevation", Manager.SunElevation, 0.0f, 180.0f, Mathf.Rad2Deg );
            Manager.SunAzimuth = Slider( "Sun Azimuth", Manager.SunAzimuth, -180.0f, 180.0f, Mathf.Rad2Deg );
            Manager.ModuleSky.DensityRayleigh = Slider( "Air Density", Manager.ModuleSky.DensityRayleigh, 0.0f, 200.0f, 1e5f );
            Manager.ModuleSky.DensityMie = Slider( "Fog", Manager.ModuleSky.DensityMie, 0.0f, 1000.0f, 1e4f );

            Separate();

            // Clouds
            if ( Manager.ModuleCloudVolume.CloudLayersCount > 0 )
            {
                Nuaj.ModuleCloudVolume.CloudLayer	L0 = Manager.ModuleCloudVolume.CloudLayers[0] as Nuaj.ModuleCloudVolume.CloudLayer;
                Label( "Layer 0", 100.0f );
                Indent();
                L0.Coverage = Slider( "Coverage", L0.Coverage, -1.0f, 1.0f );
                L0.Density = Slider( "Density", L0.Density, 0.0f, 1.0f, 0.2e3f );
                L0.Altitude = Slider( "Altitude", L0.Altitude, -1.0f, 12.0f );
                L0.WindForce = Slider( "Wind", L0.WindForce, 0.0f, 0.5f );
                if ( L0.Thickness < 1.0f )
                    L0.Thickness = 1.0f;	// So we can always tweak something...
                UnIndent();
            }

            if ( Manager.ModuleCloudLayer.CloudLayersCount > 0 )
            {
                Nuaj.ModuleCloudLayer.CloudLayer	L1 = Manager.ModuleCloudLayer.CloudLayers[0] as Nuaj.ModuleCloudLayer.CloudLayer;
                Label( "Layer 1", 100.0f );
                Indent();
                L1.Coverage = Slider( "Coverage", L1.Coverage, -1.0f, 1.0f );
                L1.Density = Slider( "Density", L1.Density, 0.0f, 1.0f, 50.0f );
                L1.Altitude = Slider( "Altitude", L1.Altitude, -1.0f, 12.0f );
                L1.WindForce = Slider( "Wind", L1.WindForce, 0.0f, 1.0f );
                UnIndent();
            }
        }

        Manager.ToneMappingGammaHighlights = Slider( "Gamma", Manager.ToneMappingGammaHighlights, 0.0f, 4.0f );

        UnIndent();
    }
Example #8
0
        public void Apply( NuajManager _Manager, NuajOrchestrator _Orch, float _Time )
        {
            // Apply orchestrator preset
            _Orch.WeatherTypeSource = PresetSource;
            _Orch.WeatherTypeTarget = PresetTarget;
            _Orch.WeatherBalance = PresetBalanceStart + (PresetBalanceEnd - PresetBalanceStart) * _Time / Duration;

            _Orch.TimeOfDay = TimeOfDayStart + (TimeOfDayEnd - TimeOfDayStart) * _Time / Duration;
            _Orch.DensityMultiplierAtNight = NightDensityFactor;

            _Orch.WindForce = Wind;
            _Orch.WindDirectionAngle = WindAngle;

            // Compute spline position
            if ( !m_bPathPreProcessed )
                PreProcessPath();

            if ( m_KeyIndex > PositionKeys.Length-2 )
                return;	// Can't interpolate...

            while ( _Time > m_KeyTimes[m_KeyIndex+1] )
            {
                m_KeyIndex++;
                if ( m_KeyIndex >= m_IntervalDurations.Length )
                    return;	// End of path...
            }

            // Interpolate position/view vectors
            float	t = (_Time - m_KeyTimes[m_KeyIndex]) / m_IntervalDurations[m_KeyIndex];	// Normalize time
            Vector3	Position = LerpPosition( ref PositionKeys[m_KeyIndex], ref PositionKeys[m_KeyIndex+1], t );
            Vector3	View = LerpView( ref RotationKeys[m_KeyIndex], ref RotationKeys[m_KeyIndex+1], t );

            // Recompute view matrix
             			Transform	T = _Manager.Camera.transform;

            Vector3	Right = Vector3.Cross( Vector3.up, View ).normalized;
            Vector3	Up = Vector3.Cross( View, Right );

            T.right = Right;
            T.up = Up;
            T.forward = View;
            T.position = Position;
        }