응애맘마조

230914 강의 본문

공부/3D강의

230914 강의

TH.Wert 2023. 9. 14. 13:30

그림자를 마무리 지었으며 LookAt함수를 이전에 사용한 YawPitchRoll을 사용해 바라보는 방향을 고정시킬 수 있도록 했습니다.

    Matrix R = Matrix::CreateLookAt(player->GetWorldPos(),
    sphere->GetWorldPos(), Vector3(0, 1, 0));

    R = R.Transpose();
    Quaternion q = Quaternion::CreateFromRotationMatrix(R);
    player->rotation = Util::QuaternionToYawPtichRoll(q);

Matrix R은 전치행렬로 만들어진 뷰행렬이고 그 Matrix를 Quaternion으로 변환하고 YawPitchRoll로 변환했습니다.

#include "Common.hlsl"

struct VertexInput
{
	float4 Position : POSITION0;
	float2 Uv : UV0;
	float3 Normal : NORMAL0;
	float3 Tangent : TANGENT0;
    
	float4 Indices : INDICES0;
	float4 Weights : WEIGHTS0;
};
struct PixelInput
{
	float4 Position : SV_POSITION;
	float3 wPosition : POSITION0;
	float2 Uv : UV0;
	float3 Normal : NORMAL;
	float3 Tangent : TANGENT;
	float3 Binormal : BINORMAL;
};

PixelInput VS(VertexInput input)
{
	PixelInput output;
	output.Uv = input.Uv;
	
	Matrix world;
    [flatten]
	if (input.Weights.x)
		world = SkinWorld(input.Indices, input.Weights);
	else
		world = World;
		
	output.Position = mul(input.Position, world);
	output.wPosition = output.Position.xyz;
	output.Position = mul(output.Position, ViewProj);
	output.Normal = mul(input.Normal, (float3x3) world);
	output.Tangent = mul(input.Tangent, (float3x3) world);
	output.Binormal = cross(output.Normal.xyz, output.Tangent.xyz);
    
	return output;
}

float4 PS(PixelInput input) : SV_TARGET
{
	float BaseColor = input.Position.z / input.Position.w;
	
	return float4(BaseColor, BaseColor, BaseColor, 1.0f);
}

새로 추가된 hlsl파일입니다. z값을 변환하여 사용하기에 RGB값을 사용하지 않고 z값을 반환합니다.

어떤 방향에서든 sphere를 바라보는 player

읽어주셔서 감사합니다.

'공부 > 3D강의' 카테고리의 다른 글

230917 ~ 230920 강의  (0) 2023.09.20
230915 강의  (0) 2023.09.16
230913 강의  (0) 2023.09.13
230912 강의  (0) 2023.09.12
230911 강의  (0) 2023.09.11
Comments