mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-28 15:57:59 +03:00
Added Function to spawn dynamic spot lights
Fixing some lighting discrepancies as a byproduct
This commit is contained in:
parent
fe965bfe60
commit
29ce1228e1
9 changed files with 65 additions and 28 deletions
|
@ -1186,6 +1186,11 @@ void TriggerDynamicLight(int x, int y, int z, short falloff, byte r, byte g, byt
|
|||
g_Renderer.AddDynamicLight(x, y, z, falloff, r, g, b);
|
||||
}
|
||||
|
||||
void TriggerDynamicSpotLight(Vector3& position, Vector3& direction, Vector3& color, float range, float angle)
|
||||
{
|
||||
g_Renderer.AddDynamicSpotLight(position, direction, color, range, angle);
|
||||
}
|
||||
|
||||
void SetupRipple(int x, int y, int z, int size, int flags)
|
||||
{
|
||||
for (int i = 0; i < MAX_RIPPLES; i++)
|
||||
|
|
|
@ -207,6 +207,7 @@ void ControlWaterfallMist(short itemNumber);
|
|||
void TriggerWaterfallMist(int x, int y, int z, int angle);
|
||||
void KillAllCurrentItems(short itemNumber);
|
||||
void TriggerDynamicLight(int x, int y, int z, short falloff, byte r, byte g, byte b);
|
||||
void TriggerDynamicSpotLight(Vector3& position, Vector3& direction, Vector3& color, float range, float angle);
|
||||
void TriggerRocketFlame(int x, int y, int z, int xv, int yv, int zv, int itemNumber);
|
||||
void TriggerRocketSmoke(int x, int y, int z, int bodyPart);
|
||||
void TriggerFireFlame(int x, int y, int z, int flag1, int flag2);
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace TEN::Entities::Vehicles
|
|||
|
||||
const vector<int> JeepJoints = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16 };
|
||||
const vector<int> JeepBrakeLightJoints = { 15, 16 };
|
||||
|
||||
const vector<int> JeepLightJoints = { 0 };
|
||||
const vector<VehicleMountType> JeepMountTypes =
|
||||
{
|
||||
VehicleMountType::LevelStart,
|
||||
|
@ -1339,6 +1339,26 @@ namespace TEN::Entities::Vehicles
|
|||
}
|
||||
}
|
||||
|
||||
static void DrawJeepHeadLights(ItemInfo* jeepItem) {
|
||||
//Jeep Base Mesh is weirdly rotated, which is why axes are mixed up
|
||||
Vector3Int start = Vector3Int(-300, -120, -300);
|
||||
Vector3Int target = Vector3Int(-1024, -120, -150);
|
||||
GetJointAbsPosition(jeepItem, &start, JeepLightJoints[0]);
|
||||
GetJointAbsPosition(jeepItem, &target, JeepLightJoints[0]);
|
||||
Vector3 direction = (target - start).ToVector3();
|
||||
direction.Normalize();
|
||||
// TODO: Use target as direction vector for spotlight.
|
||||
TriggerDynamicSpotLight(start.ToVector3(), direction, Vector3(255, 250, 220), 32, 25);
|
||||
start = Vector3Int(-300, 120, -300);
|
||||
target = Vector3Int(-1024, 120, -150);
|
||||
GetJointAbsPosition(jeepItem, &start, JeepLightJoints[0]);
|
||||
GetJointAbsPosition(jeepItem, &target, JeepLightJoints[0]);
|
||||
direction = (target - start).ToVector3();
|
||||
direction.Normalize();
|
||||
// TODO: Use target as direction vector for spotlight.
|
||||
TriggerDynamicSpotLight(start.ToVector3(), direction, Vector3(255, 250, 220), 32, 25);
|
||||
}
|
||||
|
||||
int JeepControl(ItemInfo* laraItem)
|
||||
{
|
||||
auto* lara = GetLaraInfo(laraItem);
|
||||
|
@ -1382,9 +1402,12 @@ namespace TEN::Entities::Vehicles
|
|||
drive = -1;
|
||||
collide = 0;
|
||||
}
|
||||
else
|
||||
else {
|
||||
DrawJeepHeadLights(jeepItem);
|
||||
drive = JeepUserControl(jeepItem, laraItem, floorHeight, &pitch);
|
||||
|
||||
}
|
||||
|
||||
if (jeep->Velocity || jeep->Revs)
|
||||
{
|
||||
jeep->Pitch = pitch;
|
||||
|
|
|
@ -317,16 +317,17 @@ namespace TEN::Entities::Vehicles
|
|||
if (motorbike->LightPower <= 0)
|
||||
return;
|
||||
|
||||
auto start = Vector3Int(0, -470, 1836);
|
||||
GetJointAbsPosition(motorbikeItem, &start, 0);
|
||||
auto start = Vector3Int(0, -200, 0);
|
||||
GetJointAbsPosition(motorbikeItem, &start, MotorbikeHeadLightJoints[0]);
|
||||
|
||||
auto target = Vector3Int(0, -470, 20780);
|
||||
GetJointAbsPosition(motorbikeItem, &target, 0);
|
||||
auto target = Vector3Int(0, -150, 20780);
|
||||
GetJointAbsPosition(motorbikeItem, &target, MotorbikeHeadLightJoints[0]);
|
||||
|
||||
int random = (motorbike->LightPower * 2) - (GetRandomControl() & 0xF);
|
||||
|
||||
Vector3 direction = (target - start).ToVector3();
|
||||
direction.Normalize();
|
||||
// TODO: Use target as direction vector for spotlight.
|
||||
TriggerDynamicLight(start.x, start.y, start.z, 8, random, random / 2, 0);
|
||||
TriggerDynamicSpotLight(start.ToVector3(), direction, Vector3(random, random / 2, 0),64,22);
|
||||
}
|
||||
|
||||
static void TriggerMotorbikeExhaustSmoke(int x, int y, int z, short angle, short speed, bool moving)
|
||||
|
|
|
@ -610,6 +610,7 @@ namespace TEN::Renderer
|
|||
void DrawString(int x, int y, const char* string, D3DCOLOR color, int flags);
|
||||
void FreeRendererData();
|
||||
void AddDynamicLight(int x, int y, int z, short falloff, byte r, byte g, byte b);
|
||||
void AddDynamicSpotLight(Vector3& position, Vector3& direction, Vector3& color, float range, float angle);
|
||||
void RenderLoadingScreen(float percentage);
|
||||
void UpdateProgress(float value);
|
||||
void GetLaraBonePosition(Vector3* pos, int bone);
|
||||
|
|
|
@ -988,6 +988,21 @@ namespace TEN::Renderer
|
|||
dynamicLights.push_back(dynamicLight);
|
||||
}
|
||||
|
||||
void Renderer11::AddDynamicSpotLight(Vector3& position,Vector3& direction, Vector3& color, float range, float angle)
|
||||
{
|
||||
RendererLight dynamicLight = {};
|
||||
dynamicLight.Intensity = 1.0f;
|
||||
dynamicLight.Direction = direction;
|
||||
dynamicLight.Position = position;
|
||||
dynamicLight.Out = range * 256.0f;
|
||||
dynamicLight.OutRange = angle;
|
||||
dynamicLight.In = range * 128.0f;
|
||||
dynamicLight.InRange = angle / 4;
|
||||
dynamicLight.Type = LIGHT_TYPES::LIGHT_TYPE_SPOT;
|
||||
dynamicLight.Color = color/255.0f;
|
||||
dynamicLights.push_back(dynamicLight);
|
||||
}
|
||||
|
||||
void Renderer11::ClearDynamicLights()
|
||||
{
|
||||
dynamicLights.clear();
|
||||
|
|
|
@ -91,7 +91,7 @@ PixelShaderOutput PS(PixelShaderInput input)
|
|||
|
||||
float3 normal = NormalTexture.Sample(Sampler, input.UV).rgb;
|
||||
normal = normal * 2 - 1;
|
||||
normal = normalize(mul(input.TBN, normal));
|
||||
normal = normalize(mul(input.TBN, normal));
|
||||
|
||||
float3 color = (BoneLightModes[input.Bone / 4][input.Bone % 4] == 0) ?
|
||||
CombineLights(AmbientLight.xyz, input.Color.xyz, tex.xyz, input.WorldPosition, normal, input.Sheen) :
|
||||
|
|
|
@ -311,7 +311,7 @@ PixelShaderOutput PS(PixelShaderInput input)
|
|||
|
||||
float3 Normal = NormalTexture.Sample(Sampler,input.UV).rgb;
|
||||
Normal = Normal * 2 - 1;
|
||||
Normal = normalize(mul(Normal, input.TBN));
|
||||
Normal = normalize(mul(input.TBN,Normal));
|
||||
|
||||
float3 lighting = input.Color.xyz;
|
||||
bool doLights = true;
|
||||
|
@ -336,23 +336,14 @@ PixelShaderOutput PS(PixelShaderInput input)
|
|||
{
|
||||
for (int i = 0; i < NumLights; i++)
|
||||
{
|
||||
float3 lightPos = Lights[i].Position.xyz;
|
||||
float3 color = Lights[i].Color.xyz;
|
||||
float radius = Lights[i].Out;
|
||||
|
||||
float3 lightVec = (lightPos - input.WorldPosition);
|
||||
float distance = length(lightVec);
|
||||
if (distance > radius)
|
||||
continue;
|
||||
|
||||
lightVec = normalize(lightVec);
|
||||
float d = saturate(dot(Normal, -lightVec ));
|
||||
if (d < 0)
|
||||
continue;
|
||||
|
||||
float attenuation = pow(((radius - distance) / radius), 2);
|
||||
|
||||
lighting += color * attenuation * d;
|
||||
if (Lights[i].Type == LT_SPOT)
|
||||
{
|
||||
lighting += DoSpotLight(input.WorldPosition, Normal, Lights[i]);
|
||||
}
|
||||
else if (Lights[i].Type == LT_POINT)
|
||||
{
|
||||
lighting += DoPointLight(input.WorldPosition, Normal, Lights[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ float3 DoSpotLight(float3 pos, float3 n, ShaderLight light)
|
|||
float3 lightPos = light.Position.xyz;
|
||||
float3 color = light.Color.xyz;
|
||||
float intensity = light.Intensity;
|
||||
float3 direction = -light.Direction.xyz;;
|
||||
float3 direction = light.Direction.xyz;;
|
||||
float innerRange = light.In;
|
||||
float outerRange = light.Out;
|
||||
float coneIn = light.InRange;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue