Fixed wierd ambience, 2DText Render and Lighting

This commit is contained in:
lanariel 2014-02-12 08:24:24 +01:00
parent f0df377bcd
commit 474744c72a
7 changed files with 54 additions and 44 deletions

View File

@ -50,11 +50,11 @@ namespace Oyster
{ {
if(Lights.size()) if(Lights.size())
{ {
Render::DefaultRenderer::NewFrame(View, Projection, Lights[0], (int)Lights.size()); Render::DefaultRenderer::NewFrame(View, Projection, &Lights[0], (int)Lights.size());
} }
else else
{ {
Render::DefaultRenderer::NewFrame(View, Projection, Definitions::Pointlight(), 0); Render::DefaultRenderer::NewFrame(View, Projection, NULL, 0);
} }
} }
@ -178,7 +178,7 @@ namespace Oyster
m->Animation.AnimationPlaying = &(*m->info->Animations.find(name)).second; m->Animation.AnimationPlaying = &(*m->info->Animations.find(name)).second;
m->Animation.AnimationTime=0; m->Animation.AnimationTime=0;
m->Animation.LoopAnimation = looping; m->Animation.LoopAnimation = looping;
return m->Animation.AnimationPlaying->duration; return (float)m->Animation.AnimationPlaying->duration;
} }
void API::Update(float dt) void API::Update(float dt)

View File

@ -14,11 +14,12 @@ namespace Oyster
{ {
Definitions::Pointlight pl; Definitions::Pointlight pl;
void DefaultRenderer::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight Lights, int numLights) void DefaultRenderer::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights)
{ {
Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(1,0,0,1)); Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(1,0,0,1));
Preparations::Basic::ClearRTV(Resources::GBufferRTV,Resources::GBufferSize,Math::Float4(0,0,0,0)); Preparations::Basic::ClearRTV(Resources::GBufferRTV,Resources::GBufferSize,Math::Float4(0,0,0,0));
Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::Pass); Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::Pass);
Lights[1];
void* data; void* data;
@ -35,12 +36,12 @@ namespace Oyster
Resources::Light::LightConstantsData.Unmap(); Resources::Light::LightConstantsData.Unmap();
data = Resources::Light::PointLightsData.Map(); data = Resources::Light::PointLightsData.Map();
memcpy(data, &Lights, sizeof(Definitions::Pointlight) * numLights); memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights);
Resources::Light::PointLightsData.Unmap(); Resources::Light::PointLightsData.Unmap();
Definitions::PostData pd; Definitions::PostData pd;
pd.x = lc.Pixels.x; pd.x = (int)lc.Pixels.x;
pd.y = lc.Pixels.y; pd.y = (int)lc.Pixels.y;
data = Resources::Post::Data.Map(); data = Resources::Post::Data.Map();
memcpy(data, &pd, sizeof(Definitions::PostData)); memcpy(data, &pd, sizeof(Definitions::PostData));
@ -164,11 +165,11 @@ namespace Oyster
Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1);
Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass); //Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass);
Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); //Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1);
Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass); //Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass);
Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); //Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1);
Core::PipelineManager::SetRenderPass(Resources::Post::Pass); Core::PipelineManager::SetRenderPass(Resources::Post::Pass);

View File

@ -13,7 +13,7 @@ namespace Oyster
class DefaultRenderer class DefaultRenderer
{ {
public: public:
static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight Lights, int numLights); static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights);
static void RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float DeltaTime = 0); static void RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float DeltaTime = 0);
static void EndFrame(); static void EndFrame();
}; };

View File

@ -9,7 +9,7 @@ namespace Oyster
namespace Render namespace Render
{ {
const int TEXT_NR_LETTERS=95; const int TEXT_NR_LETTERS=95;
const float TEXT_SIZE=2.5; const float TEXT_SPACING=1.8f;
void Gui::Begin2DRender() void Gui::Begin2DRender()
{ {
@ -45,37 +45,21 @@ namespace Oyster
void Gui::RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size) void Gui::RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size)
{ {
//Pos.x -= instance.sizeX/2;
//Pos.x += size.x; size.x = size.x / (text.length() * TEXT_SPACING /2);
//Pos.y -= instance.sizeY/2;
//Pos.y += size.y;
//Matrix m;
//m = Math::Matrix::identity;
//float width = (1.0f/(instance.sizeX/2.0f));
//float height = (1.0f/(instance.sizeY/2.0f));
//m.m41=Pos.x * width;
//m.m42=-Pos.y * height;
//m.m43=Pos.z;
//m.m11=width*size.x;
//m.m22=height*size.y;
//void* dest = Resources::Buffers::CBufferGs.Map();
//memcpy(dest,&m.GetTranspose(),64);
//Resources::Buffers::CBufferGs.Unmap();
//Oyster::Render::Textbox::Update(text, size.x);
//Oyster::Engine::PrepareForRendering::Begin2DTextRender();
//Oyster::Core::DeviceContext->PSSetShaderResources(0,1,&(Oyster::Render::Textbox::Texture));
////Should be able to be outside of the for loop. Keeping it here for now though.
//Oyster::Core::DeviceContext->Draw(Oyster::Render::Textbox::NumLetters, 0);
pos *= 2; pos *= 2;
pos -= 1; pos -= 1;
pos.y *= -1; pos.y *= -1;
pos.x = pos.x - (size.x * (text.length()-1) * TEXT_SPACING /2);
Definitions::GuiData gd; Definitions::GuiData gd;
gd.Translation = Math::Matrix::identity; gd.Translation = Math::Matrix::identity;
gd.Translation.m41 = (pos.x - (size.x/2 * text.length())); gd.Translation.m41 = pos.x;
gd.Translation.m42 = pos.y; gd.Translation.m42 = pos.y;
gd.Translation.m11 = size.x; gd.Translation.m11 = size.x;
gd.Translation.m22 = size.y; gd.Translation.m22 = size.y;
@ -93,7 +77,7 @@ namespace Oyster
{ {
tmpInst.coff=(1.0f/TEXT_NR_LETTERS); tmpInst.coff=(1.0f/TEXT_NR_LETTERS);
tmpInst.offset=text[i]-32; tmpInst.offset=text[i]-32;
tmpInst.pos=i*(size.x*2); tmpInst.pos=i*(size.x * TEXT_SPACING);
//float tst=getCharID(_str[i]); //float tst=getCharID(_str[i]);
//tmpInst.offset=tst; //tmpInst.offset=tst;
//tmpInst.charOffset.x=_pos.x-i*TEXT_SIZE; //tmpInst.charOffset.x=_pos.x-i*TEXT_SIZE;

View File

@ -163,8 +163,8 @@ namespace Oyster
D3D11_SAMPLER_DESC sdesc; D3D11_SAMPLER_DESC sdesc;
sdesc.Filter = D3D11_FILTER_ANISOTROPIC; sdesc.Filter = D3D11_FILTER_ANISOTROPIC;
sdesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; sdesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sdesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; sdesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sdesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; sdesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
sdesc.MipLODBias = 0; sdesc.MipLODBias = 0;
sdesc.MaxAnisotropy =4; sdesc.MaxAnisotropy =4;

View File

@ -17,7 +17,7 @@ void main( uint3 DTid : SV_DispatchThreadID )
float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]); float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]);
float4 Amb = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w, 0); float4 Amb = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w, 0);
float4 GUI; float4 GUI;
uint2 index = DTid.xy/2 + int2(Pixels.x/2,0); uint2 index = DTid.xy/2 + uint2(Pixels.x/2,0);
float3 PostLight = Amb.xyz * AmbFactor; float3 PostLight = Amb.xyz * AmbFactor;
PostLight = PostLight + Light.xyz; PostLight = PostLight + Light.xyz;
GUI = float4(Ambient[index]); GUI = float4(Ambient[index]);

View File

@ -21,6 +21,7 @@ Oyster::Graphics::Model::Model* m = NULL;
Oyster::Graphics::Model::Model* m2 = NULL; Oyster::Graphics::Model::Model* m2 = NULL;
Oyster::Graphics::Model::Model* m3 = NULL; Oyster::Graphics::Model::Model* m3 = NULL;
Oyster::Graphics::API::Texture t = NULL; Oyster::Graphics::API::Texture t = NULL;
Oyster::Graphics::API::Texture t2 = NULL;
Oyster::Math::Float4x4 V; Oyster::Math::Float4x4 V;
Oyster::Math::Float4x4 P; Oyster::Math::Float4x4 P;
Oyster::Graphics::Definitions::Pointlight pl; Oyster::Graphics::Definitions::Pointlight pl;
@ -170,11 +171,15 @@ HRESULT InitDirect3D()
} }
m = Oyster::Graphics::API::CreateModel(L"crate_colonists.dan"); m = Oyster::Graphics::API::CreateModel(L"crate_colonists.dan");
m->WorldMatrix.m[0][0] = 50;
m->WorldMatrix.m[1][1] = 50;
m->WorldMatrix.m[2][2] = 0.00000005f;
m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan"); m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan");
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null);
Oyster::Graphics::API::PlayAnimation(m2, L"movement",true); Oyster::Graphics::API::PlayAnimation(m2, L"movement",true);
t = Oyster::Graphics::API::CreateTexture(L"structure_corp_mdg.png"); t = Oyster::Graphics::API::CreateTexture(L"structure_corp_mdg.png");
t2 = Oyster::Graphics::API::CreateTexture(L"whiteGui.png");
P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1280.0f/720.0f,.1f,10000); P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1280.0f/720.0f,.1f,10000);
Oyster::Graphics::API::SetProjection(P); Oyster::Graphics::API::SetProjection(P);
@ -184,9 +189,23 @@ HRESULT InitDirect3D()
pl.Color = Oyster::Math::Float3(1,0,1); pl.Color = Oyster::Math::Float3(1,0,0);
pl.Bright = 1; pl.Bright = 1;
pl.Pos = Oyster::Math::Float3(0,-20.0f,0.4f); pl.Pos = Oyster::Math::Float3(-20,0,0);
pl.Radius = 90;
Oyster::Graphics::API::AddLight(pl);
pl.Color = Oyster::Math::Float3(0,1,0);
pl.Bright = 1;
pl.Pos = Oyster::Math::Float3(0,20,0);
pl.Radius = 90;
Oyster::Graphics::API::AddLight(pl);
pl.Color = Oyster::Math::Float3(0,0,1);
pl.Bright = 1;
pl.Pos = Oyster::Math::Float3(0,0,20);
pl.Radius = 90; pl.Radius = 90;
Oyster::Graphics::API::AddLight(pl); Oyster::Graphics::API::AddLight(pl);
@ -213,9 +232,15 @@ HRESULT Render(float deltaTime)
Oyster::Graphics::API::RenderModel(m); Oyster::Graphics::API::RenderModel(m);
Oyster::Graphics::API::RenderModel(m2); Oyster::Graphics::API::RenderModel(m2);
Oyster::Graphics::API::StartGuiRender(); Oyster::Graphics::API::StartGuiRender();
Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(0.8f,0.2f)); Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1));
Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f));
Oyster::Graphics::API::StartTextRender(); Oyster::Graphics::API::StartTextRender();
Oyster::Graphics::API::RenderText(L"Lanariel Was Here",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.05f,0.08f)); std::wstring fps;
float f = 1/deltaTime;
fps = std::to_wstring(f);
//Oyster::Graphics::API::RenderText(L"Lanariel",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f));
//Oyster::Graphics::API::RenderText(L"Lanariel WAS HERE",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f));
//Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f));
Oyster::Graphics::API::EndFrame(); Oyster::Graphics::API::EndFrame();
return S_OK; return S_OK;