Light Component를 구현하세요.
라이트를 나타내는 Icon Sprite를 LightColor로 렌더링 하세요.
classULightComponentBase :public USceneComponent
{
float Intensity;
FColor LightColor;
bool bVisible;
};
classULightComponent :public ULightComponentBase
{
};
Ambient Light (환경 광원)을 구현하세요.
classUAmbientLightComponent :public ULightComponent
{
};
Directional Light (직사광원, 태양광원)을 구현하세요.
와이어 프레임으로 화살표 방향을 렌더링 하세요.
classUDirectionalLightComponent :public ULightComponent
{
};
Point Light (점 광원)을 구현하세요.
와이어 프레임으로 Radius를 렌더링 하세요.
classUPointLightComponenet :public UPrimitiveComponent
{
float AttenuationRadius;
float LightFalloffExponent;
};
Spot Light (집중광원)을 구현하세요.
방향과 Inner, Outer Cone Angle을 와아어 프레임으로 렌더링 하세요.
classUSpotLightComponenet :public UPointLightComponenet
{
float InnerConeAngle;
float OuterConeAngle;
};
3가지 Lighting Model을 한 개의 쉐이더 파일로 구현하세요.
// UberLit.hlsl
#define NUM_POINT_LIGHT 4
#define NUM_SPOT_LIGHT 4
structFAmbientLightInfo
{
...
};
structFDirectionalLightInfo
{
...
};
structFPointLightInfo
{
...
};
structFSpotLightInfo
{
...
};
cbuffer PerObject : register(b0)
{
matrix World;
matrix View;
matrix Projection;
};
cbuffer Lighting : register(b1)
{
FAmbientLightInfo Ambient;
FDirectionalLightInfo Directional;
FPointLightInfo PointLights[NUM_POINT_LIGHT];
FSpotLightInfo SpotLights[NUM_SPOT_LIGHT];
};
float4CalculateAmbientLight(FAmbientLightInfo info)
{
float4 result;
...
return result;
}
VS_OUTUber_VS(VS_IN Input)
{
VS_OUT out;
#if LIGHTING_MODEL_GOURAUD
#elif LIGHTING_MODEL_LAMBERT
#elif LIGHTING_MODEL_PHONG
#endifreturn out;
}
float4Uber_PS(VS_OUT Input) : SV_TARGET
{
float4 finalPixel = TextureColor;
finalPixel += Emissive;
#if LIGHTING_MODEL_GOURAUD
#elif LIGHTING_MODEL_LAMBERT
finalPixel += CalculateAmbientLight(...);
for(It : PointLights)
{
finalPixel += CalculatePointLight(...);
}
#elif LIGHTING_MODEL_PHONG
// Specular Reflectance
#endifreturn finalPixel;
}
Normal Mapping을 구현하세요.
// UberLit.hlsl
#if HAS_NORMAL_MAP
Texture2D NormalMap : register(t1);
#endiffloat4PS_Main(VS_OUTPUT input) : SV_TARGET
{
...
#if HAS_NORMAL_MAP
float3 mappedNormal = GetNormalFromMap(input.Normal, input.Tex);
float4 lighting = CalculateLighting(input.WorldPos, mappedNormal);
#else
float4 lighting = CalculateLighting(input.WorldPos, input.Normal);
#endifreturn lighting * diffuseColor;
}
