Directx 11 with rastertek

Tutorial 6: Diffuse Lighting 연습문제

코다람쥐 2022. 9. 6. 15:16

To Do Exercises

1. Recompile the project and ensure you get a spinning textured triangle that is being illuminated by a purple light. Press escape to quit.

2. Comment out "color = color * textureColor;" in the pixel shader so that the shaderTexture is no longer used and you should see the lighting effect without the texture.

3. Change the color of the light to green at the m_Light->SetDiffuseColor line of code in the GraphicsClass.

4. Change the direction of the light to go down the positive and the negative X axis. You might want to change the speed of the rotation also.

 

1. 프로젝트를 다시 컴파일하여 회전하는 텍스쳐가 입혀진 삼각형이 자줏빛으로 보여지는 것을 확인해 보십시오. esc키를 눌러 나갈 수 있습니다.

2. 픽셀 셰이더에서 "color = color * textureColor" 부분은 주석 처리하여 텍스쳐 효과 없이 어떻게 조명 효과가 적용되는지 보십시오.

light.ps

float4 LightPixelShader(PixelInputType input) : SV_TARGET
{
.................생략.................
    //color = color * textureColor;
.................생략.................
}

3. GraphicsClass 클래스의 m_Light->SetDiffuseColor 부분의 색상을 녹색으로 바꾸어 보십시오.

graphicsclass.cpp

bool GraphicsClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
{
............................생략.........................
	m_Light->SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f);
............................생략.........................
}

4. 빛의 방향을 X축의 양의 방향과 음의 방향으로 바꾸어 보십시오. 회전 속도도 바꾸어 보면 재미있을 것입니다.

bool GraphicsClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
{
.....................생략.....................
	m_Light->SetDirection(1.0f, 0.0f, 1.0f);
.....................생략.....................
}
bool GraphicsClass::Frame()
{
....................생략....................
// 기존에는 (float)D3DX_PI * 0.01f이었음
	rotation += (float)D3DX_PI * 0.02f;
....................생략....................
}

결과는 사진이라 별 차이가 없어 보이지만 회전속도가 빨라지고 삼각형이 노출되는 각도가 달라진다.