Rebased Lights to Use World Coordinates

This commit is contained in:
lanariel 2013-12-18 20:36:41 +01:00
parent 3139585e7b
commit 341e33ee78
5 changed files with 6 additions and 2 deletions

View File

@ -37,6 +37,7 @@ namespace Oyster
Math::Float2 Pixels; Math::Float2 Pixels;
int Lights; int Lights;
float Pad; float Pad;
Oyster::Math::Float4x4 View;
}; };
struct Pointlight struct Pointlight

View File

@ -33,6 +33,7 @@ namespace Oyster
lc.InvProj = Projection.GetInverse(); lc.InvProj = Projection.GetInverse();
lc.Pixels = Core::resolution; lc.Pixels = Core::resolution;
lc.Lights = numLights; lc.Lights = numLights;
lc.View = View;
data = Resources::Deffered::LightConstantsData.Map(); data = Resources::Deffered::LightConstantsData.Map();
memcpy(data, &lc, sizeof(Definitions::LightConstants)); memcpy(data, &lc, sizeof(Definitions::LightConstants));

View File

@ -21,6 +21,7 @@ cbuffer LightConstants : register(b0)
float2 Pixels; float2 Pixels;
int Lights; int Lights;
float Pad; float Pad;
float4x4 View;
} }
Texture2D DiffuseGlow : register(t0); Texture2D DiffuseGlow : register(t0);

View File

@ -4,7 +4,8 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord)
{ {
DiffSpec output; DiffSpec output;
float4 normalSpec = NormalSpec[texCoord]; float4 normalSpec = NormalSpec[texCoord];
float3 lightVec = pl.Pos - pos.xyz; float4 LPos = mul(View, float4(pl.Pos, 1));
float3 lightVec = LPos.xyz - pos.xyz;
float d = length(lightVec); float d = length(lightVec);
lightVec = lightVec/d; lightVec = lightVec/d;

View File

@ -210,7 +210,7 @@ HRESULT InitDirect3D()
Oyster::Graphics::Definitions::Pointlight pl; Oyster::Graphics::Definitions::Pointlight pl;
pl.Color = Oyster::Math::Float3(1,1,1); pl.Color = Oyster::Math::Float3(1,1,1);
pl.Bright = 1; pl.Bright = 1;
pl.Pos = (V * Oyster::Math::Float4(Oyster::Math::Float3(0,0,5.4f), 1)).xyz; pl.Pos = Oyster::Math::Float3(0,0,5.4f);
pl.Radius = 15; pl.Radius = 15;
Oyster::Graphics::API::AddLight(pl); Oyster::Graphics::API::AddLight(pl);