ABOUT ME

Today
Yesterday
Total
  • Tutorial 28: Screen Fades
    Directx 11 with rastertek 2022. 9. 25. 23:49

    To Do Exercises

    1. Recompile and run the program. The cube show slowly fade in over a 5 second period and then start rendering normally. Press escape to quit.

    2. Change the speed at which the scene fades in.

    3. Change the color the back buffer is cleared to in the render to texture so you can see the exact moment the application switches to rendering normally.

    4. Change the code to fade the scene out after fading it in.

     

    1. 프로그램을 다시 컴파일하여 실행합니다. 큐브는 5초 동안 서서히 페이드를 보여준 다음 정상적으로 렌더링을 시작합니다. 종료하려면 ESC를 누르십시오.

    5초 간 페이딩



    2. 장면이 희미해지는 속도를 변경합니다.

    graphicsclass.cpp

    bool GraphicsClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
    {
    ..........................생략..........................
    	// Set the fade in time to 3000 milliseconds.
    	m_fadeInTime = 2000.0f;
    ..........................생략..........................
    }

    2000.0f = 2000ms = 2초

    2초 간 페이딩


    3. 프로그램이 정상적으로 렌더링으로 전환되는 정확한 순간을 볼 수 있도록 렌더링에서 백 버퍼가 지워진 색상을 텍스처로 변경합니다.

    ??


    4. 씬을 페이드 인한 후 페이드 아웃 하도록 코드를 변경합니다.

    graphicsclass.cpp

    bool GraphicsClass::Frame(HWND hwnd, int fps, int cpu, float rotationY, float frameTime)
    {
    .................................생략.................................
    	bool result;
    
    	if (!m_fadeDone)
    	{
    		// Update the accumulated time with the extra frame time addition.
    		
    		m_accumulatedTime += frameTime;
    
    		// While the time goes on increase the fade in amount by the time that is passing each frame.
    		if (m_accumulatedTime < m_fadeInTime)
    		{
    			// Calculate the percentage that the screen should be faded in based on the accumulated time.
    			m_fadePercentage = m_accumulatedTime / m_fadeInTime;
    		}
    		else
    		{
    			// If the fade in time is complete then turn off the fade effect and render the scene normally.
    			m_fadeDone = true;
    
    			// Set the percentage to 100%.
    			m_fadePercentage = 1.0f;
    		}
    	}
    	else
    	{
    		m_accumulatedTime -= frameTime;
    
    		// While the time goes on increase the fade in amount by the time that is passing each frame.
    		if (m_accumulatedTime > 0)
    		{
    			// Calculate the percentage that the screen should be faded in based on the accumulated time.
    			m_fadePercentage = m_accumulatedTime / m_fadeInTime;
    		}
    		else
    		{
    			// If the fade in time is complete then turn off the fade effect and render the scene normally.
    			m_fadeDone = false;
    
    			// Set the percentage to 0%.
    			m_fadePercentage = 0.0f;
    		}
    	}
    .................................생략.................................
    }

     

    graphicsclass.cpp

    bool GraphicsClass::Render()
    {
    	bool result;
    	static float rotation = 0.0f;
    
    	// Update the rotation variable each frame.
    	rotation += (float)D3DX_PI * 0.005f;
    	if (rotation > 360.0f)
    	{
    		rotation -= 360.0f;
    	}
    
    	// If fading in is not complete then render the scene to a texture and fade that texture in.
    	result = RenderToTexture(rotation);
    	if (!result)
    	{
    		return false;
    	}
    
    	result = RenderFadingScene();
    	if (!result)
    	{
    		return false;
    	}
    
    	return true;
    }

Designed by Tistory.