From 341e33ee784429a9d3bfdd99bbd294d8f845ac92 Mon Sep 17 00:00:00 2001 From: lanariel Date: Wed, 18 Dec 2013 20:36:41 +0100 Subject: [PATCH] Rebased Lights to Use World Coordinates --- Code/OysterGraphics/Definitions/GraphicalDefinition.h | 1 + Code/OysterGraphics/Render/Rendering/BasicRender.cpp | 1 + Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Defines.hlsli | 1 + .../Shader/HLSL/Deffered Shaders/LightCalc.hlsli | 3 ++- Code/Tester/MainTest.cpp | 2 +- 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h index d4c6adb8..e81d787b 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -37,6 +37,7 @@ namespace Oyster Math::Float2 Pixels; int Lights; float Pad; + Oyster::Math::Float4x4 View; }; struct Pointlight diff --git a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp index ce7f6239..e61bd656 100644 --- a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp +++ b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp @@ -33,6 +33,7 @@ namespace Oyster lc.InvProj = Projection.GetInverse(); lc.Pixels = Core::resolution; lc.Lights = numLights; + lc.View = View; data = Resources::Deffered::LightConstantsData.Map(); memcpy(data, &lc, sizeof(Definitions::LightConstants)); diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Defines.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Defines.hlsli index 4931c36a..b934484c 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Defines.hlsli +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Defines.hlsli @@ -21,6 +21,7 @@ cbuffer LightConstants : register(b0) float2 Pixels; int Lights; float Pad; + float4x4 View; } Texture2D DiffuseGlow : register(t0); diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli index a5070532..64c3c98c 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli @@ -4,7 +4,8 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord) { DiffSpec output; 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); lightVec = lightVec/d; diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index 73858d39..4a684915 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -210,7 +210,7 @@ HRESULT InitDirect3D() Oyster::Graphics::Definitions::Pointlight pl; pl.Color = Oyster::Math::Float3(1,1,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; Oyster::Graphics::API::AddLight(pl);