From da5b9c73065ad8335bc89d18cef913956e204c60 Mon Sep 17 00:00:00 2001 From: lanariel Date: Wed, 12 Feb 2014 12:05:27 +0100 Subject: [PATCH 1/5] Nomal Mapping For TA --- .../Shader/Passes/Gather/GatherPixel.hlsl | 43 ++++++++++++++++++- .../Shader/Passes/Gather/GatherVertex.hlsl | 1 + .../Shader/Passes/Gather/Header.hlsli | 2 +- .../Shader/Passes/Post/PostPass.hlsl | 2 +- Code/Tester/MainTest.cpp | 4 +- 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl index b0a2f40f..0fbf0b92 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl @@ -1,9 +1,50 @@ #include "Header.hlsli" + + +float3x3 cotangent_frame( float3 N, float3 p, float2 uv ) +{ + // get edge vectors of the pixel triangle + float3 dp1 = ddx( p ); + float3 dp2 = ddy( p ); + float2 duv1 = ddx( uv ); + float2 duv2 = ddy( uv ); + + // solve the linear system + float3 dp2perp = cross( dp2, N ); + float3 dp1perp = cross( N, dp1 ); + float3 T = dp2perp * duv1.x + dp1perp * duv2.x; + float3 B = dp2perp * duv1.y + dp1perp * duv2.y; + + // construct a scale-invariant frame + float invmax = 1/sqrt( max( dot(T,T), dot(B,B) ) ); + return float3x3( T * invmax, B * invmax, N ); +} + +float3 perturb_normal( float3 N, float3 V, float2 texcoord ) +{ + // assume N, the interpolated vertex normal and + // V, the view vector (vertex to eye) + float3 map = Normal.Sample(S1,texcoord).xyz; + map = map * 255./127. - 128./127.; +#ifdef WITH_NORMALMAP_2CHANNEL + map.z = sqrt( 1. - dot( map.xy, map.xy ) ); +#endif +#ifdef WITH_NORMALMAP_GREEN_UP + map.y = -map.y; +#endif + float3x3 TBN = cotangent_frame( N, -V, texcoord ); + return normalize( mul(transpose(TBN), map) ); +} + PixelOut main(VertexOut input) { PixelOut output; output.DiffuseGlow = Diffuse.Sample(S1, input.UV); - output.NormalSpec = float4(normalize(input.normal), Normal.Sample(S1,input.UV).w); + float3 normal = normalize(input.normal); + + normal = perturb_normal( normal, normalize(-input.ViewPos), input.UV ); + + output.NormalSpec = float4(normal, Normal.Sample(S1,input.UV).w); return output; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl index 4042c224..fd3da6b1 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl @@ -14,6 +14,7 @@ VertexOut main( VertexIn input ) input.normal = mul(boneTrans,float4(input.normal,1)).xyz * Animated + input.normal * int(1-Animated); output.pos = mul(WVP, float4(input.pos,1)); + output.ViewPos = mul(WV, float4(input.pos,1)); output.normal = mul(WV, float4(input.normal,0)).xyz; output.UV = input.UV; return output; diff --git a/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli b/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli index a313a649..14e0db5a 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli @@ -12,7 +12,7 @@ struct VertexIn struct VertexOut { float4 pos : SV_POSITION; - //float4 ViewPos : POSITION; + float4 ViewPos : POSITION; float2 UV : TEXCOORD; float3 normal : NORMAL; //float3 tangent : TANGENT; diff --git a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl index 247efb42..53cfabb2 100644 --- a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl @@ -17,7 +17,7 @@ void main( uint3 DTid : SV_DispatchThreadID ) float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]); float4 Amb = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w, 0); float4 GUI; - uint2 index = DTid.xy/2 + uint2(Pixels.x/2,0); + uint2 index = DTid.xy/2 + uint2((uint)Pixels.x/(uint)2,0); float3 PostLight = Amb.xyz * AmbFactor; PostLight = PostLight + Light.xyz; GUI = float4(Ambient[index]); diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index 4462f060..baf63cb3 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -176,7 +176,7 @@ HRESULT InitDirect3D() m->WorldMatrix.m[2][2] = 0.00000005f; 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); - Oyster::Graphics::API::PlayAnimation(m2, L"movement",false); + Oyster::Graphics::API::PlayAnimation(m2, L"movement"); t = Oyster::Graphics::API::CreateTexture(L"structure_corp_mdg.png"); t2 = Oyster::Graphics::API::CreateTexture(L"whiteGui.png"); @@ -233,7 +233,7 @@ HRESULT Render(float deltaTime) Oyster::Graphics::API::RenderModel(m2); Oyster::Graphics::API::StartGuiRender(); 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::Math::Float3(1,0,0)); + Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float3(1,0,0)); Oyster::Graphics::API::StartTextRender(); std::wstring fps; float f = 1/deltaTime; From 11b6f6eddc983726a02bf4eb86540f8f9d93ebc6 Mon Sep 17 00:00:00 2001 From: lanariel Date: Wed, 12 Feb 2014 13:53:52 +0100 Subject: [PATCH 2/5] Fixed Spec coefficient --- Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl | 2 +- Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli | 2 ++ Code/Tester/MainTest.cpp | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl index 0fbf0b92..464da702 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl @@ -45,6 +45,6 @@ PixelOut main(VertexOut input) normal = perturb_normal( normal, normalize(-input.ViewPos), input.UV ); - output.NormalSpec = float4(normal, Normal.Sample(S1,input.UV).w); + output.NormalSpec = float4(normal, Normal.Sample(S1, input.UV).w*255); return output; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli b/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli index 8a1ff05a..3dc2b45e 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli @@ -24,5 +24,7 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord) output.Diffuse = float3(0,0,0); output.Specular = float3(0,0,0); } + float SpecCo = normalSpec.w < 1 ? 0.0f : 1.0f; + output.Specular = output.Specular * SpecCo; return output; } \ No newline at end of file diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index baf63cb3..3813d3e9 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -229,11 +229,11 @@ HRESULT Render(float deltaTime) Oyster::Graphics::API::SetView(V); Oyster::Graphics::API::NewFrame(); - Oyster::Graphics::API::RenderModel(m); + //Oyster::Graphics::API::RenderModel(m); Oyster::Graphics::API::RenderModel(m2); Oyster::Graphics::API::StartGuiRender(); - 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::Math::Float3(1,0,0)); + //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.5f),Oyster::Math::Float2(1,1),Oyster::Math::Float3(1,0,0)); Oyster::Graphics::API::StartTextRender(); std::wstring fps; float f = 1/deltaTime; From 5fbb901c6971f14bbb81bf4c4f524a8d6f0857b6 Mon Sep 17 00:00:00 2001 From: lanariel Date: Wed, 12 Feb 2014 16:21:46 +0100 Subject: [PATCH 3/5] Model Tint added --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 1 + Code/OysterGraphics/Model/Model.h | 1 + .../OysterGraphics/Render/DefaultRenderer.cpp | 4 ++++ Code/OysterGraphics/Render/GuiRenderer.cpp | 8 ++++---- Code/OysterGraphics/Render/Resources.cpp | 11 ++++++----- Code/OysterGraphics/Render/Resources.h | 4 +++- .../Shader/Passes/Gather/GatherPixel.hlsl | 2 +- .../Shader/Passes/Gather/Header.hlsli | 5 +++++ Code/Tester/MainTest.cpp | 19 ++++++++++++------- 9 files changed, 37 insertions(+), 18 deletions(-) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index b8d8bbae..8cb80fe2 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -87,6 +87,7 @@ namespace Oyster m->WorldMatrix = Oyster::Math::Float4x4::identity; m->Visible = true; m->Animation.AnimationPlaying = NULL; + m->Tint = Math::Float3(1); m->info = (Model::ModelInfo*)Core::loader.LoadResource((Core::modelPath + filename).c_str(),Oyster::Graphics::Loading::LoadDAN, Oyster::Graphics::Loading::UnloadDAN); Model::ModelInfo* mi = (Model::ModelInfo*)m->info; diff --git a/Code/OysterGraphics/Model/Model.h b/Code/OysterGraphics/Model/Model.h index 590d7d6a..b264cf50 100644 --- a/Code/OysterGraphics/Model/Model.h +++ b/Code/OysterGraphics/Model/Model.h @@ -23,6 +23,7 @@ namespace Oyster { ModelInfo* info; Oyster::Math::Float4x4 WorldMatrix; + Oyster::Math::Float3 Tint; bool Visible; AnimationData Animation; }; diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index a92c54d6..8058cd60 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -138,6 +138,10 @@ namespace Oyster memcpy(data,&(pm),sizeof(pm)); Resources::Gather::ModelData.Unmap(); + data = Render::Resources::Color.Map(); + memcpy(data,&models[i].Tint,sizeof(Math::Float3)); + Render::Resources::Color.Unmap(); + if(info->Material.size()) { Core::deviceContext->PSSetShaderResources(0,(UINT)info->Material.size(),&(info->Material[0])); diff --git a/Code/OysterGraphics/Render/GuiRenderer.cpp b/Code/OysterGraphics/Render/GuiRenderer.cpp index fbdfa37c..7f3285e1 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.cpp +++ b/Code/OysterGraphics/Render/GuiRenderer.cpp @@ -35,9 +35,9 @@ namespace Oyster memcpy(data,&gd,sizeof(Definitions::GuiData)); Render::Resources::Gui::Data.Unmap(); - data = Render::Resources::Gui::Color.Map(); + data = Render::Resources::Color.Map(); memcpy(data,&color,sizeof(Math::Float3)); - Render::Resources::Gui::Color.Unmap(); + Render::Resources::Color.Unmap(); Core::deviceContext->Draw(1,0); @@ -76,9 +76,9 @@ namespace Oyster Render::Resources::Gui::Data.Unmap(); Definitions::Text2D tmpInst; - data = Render::Resources::Gui::Color.Map(); + data = Render::Resources::Color.Map(); memcpy(data,&color,sizeof(Math::Float3)); - Render::Resources::Gui::Color.Unmap(); + Render::Resources::Color.Unmap(); void* dest = Resources::Gui::Text::Vertex.Map(); Definitions::Text2D* dataView = reinterpret_cast(dest); diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index 73834071..77988417 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -45,7 +45,7 @@ namespace Oyster Buffer Resources::Gather::AnimationData = Buffer(); Buffer Resources::Light::LightConstantsData = Buffer(); Buffer Resources::Gui::Data = Buffer(); - Buffer Resources::Gui::Color = Buffer(); + Buffer Resources::Color = Buffer(); Buffer Resources::Gui::Text::Vertex = Buffer(); Buffer Resources::Post::Data = Buffer(); @@ -121,7 +121,7 @@ namespace Oyster desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_PS; desc.ElementSize = sizeof(Math::Float3); - Gui::Color.Init(desc); + Color.Init(desc); desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_GS; desc.NumElements = 1; @@ -342,6 +342,7 @@ namespace Oyster Gather::Pass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; Gather::Pass.CBuffers.Vertex.push_back(Gather::AnimationData); Gather::Pass.CBuffers.Vertex.push_back(Gather::ModelData); + Gather::Pass.CBuffers.Pixel.push_back(Color); Gather::Pass.RenderStates.Rasterizer = RenderStates::rs; Gather::Pass.RenderStates.SampleCount = 1; Gather::Pass.RenderStates.SampleState = RenderStates::ss; @@ -383,7 +384,7 @@ namespace Oyster Gui::Pass.Shaders.Geometry = GetShader::Geometry(L"2D"); Gui::Pass.RTV.push_back(GBufferRTV[2]); Gui::Pass.CBuffers.Geometry.push_back(Gui::Data); - Gui::Pass.CBuffers.Pixel.push_back(Gui::Color); + Gui::Pass.CBuffers.Pixel.push_back(Color); D3D11_INPUT_ELEMENT_DESC indesc2D[] = { @@ -427,7 +428,7 @@ namespace Oyster Shader::CreateInputLayout(Text2Ddesc,3, GetShader::Vertex(L"2DText") ,Gui::Text::Pass.IAStage.Layout); Gui::Text::Pass.CBuffers.Geometry.push_back(Gui::Data); - Gui::Text::Pass.CBuffers.Pixel.push_back(Gui::Color); + Gui::Text::Pass.CBuffers.Pixel.push_back(Color); Gui::Text::Pass.SRV.Pixel.push_back(Gui::Text::Font); Gui::Text::Pass.RTV.push_back(GBufferRTV[2]); Gui::Text::Pass.RenderStates.SampleCount = 1; @@ -455,7 +456,7 @@ namespace Oyster Light::LightConstantsData.~Buffer(); Light::PointLightsData.~Buffer(); Gui::Data.~Buffer(); - Gui::Color.~Buffer(); + Color.~Buffer(); Gui::Text::Vertex.~Buffer(); Post::Data.~Buffer(); SAFE_RELEASE(Light::PointLightView); diff --git a/Code/OysterGraphics/Render/Resources.h b/Code/OysterGraphics/Render/Resources.h index d43b5756..684762fd 100644 --- a/Code/OysterGraphics/Render/Resources.h +++ b/Code/OysterGraphics/Render/Resources.h @@ -30,6 +30,9 @@ namespace Oyster static ID3D11UnorderedAccessView* LBufferUAV[LBufferSize]; static ID3D11ShaderResourceView* LBufferSRV[LBufferSize]; + + static Core::Buffer Color; + struct RenderStates { @@ -61,7 +64,6 @@ namespace Oyster { static Core::PipelineManager::RenderPass Pass; static Core::Buffer Data; - static Core::Buffer Color; struct Text { static Core::PipelineManager::RenderPass Pass; diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl index 464da702..542d8c54 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl @@ -40,7 +40,7 @@ float3 perturb_normal( float3 N, float3 V, float2 texcoord ) PixelOut main(VertexOut input) { PixelOut output; - output.DiffuseGlow = Diffuse.Sample(S1, input.UV); + output.DiffuseGlow = Diffuse.Sample(S1, input.UV) * float4(Color, 1); float3 normal = normalize(input.normal); normal = perturb_normal( normal, normalize(-input.ViewPos), input.UV ); diff --git a/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli b/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli index 14e0db5a..ea144417 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli @@ -41,4 +41,9 @@ cbuffer PerModel : register(b1) matrix WVP; int Animated; float3 Pad; +} + +cbuffer Tint : register(b0) +{ + float3 Color; } \ No newline at end of file diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index 3813d3e9..2915d62e 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -175,9 +175,12 @@ HRESULT InitDirect3D() m->WorldMatrix.m[1][1] = 50; m->WorldMatrix.m[2][2] = 0.00000005f; m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan"); + m2->Tint = Oyster::Math::Float3(0.8f,0.8f,1); + m3 = 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); - Oyster::Graphics::API::PlayAnimation(m2, L"movement"); - + Oyster::Graphics::API::PlayAnimation(m2, L"movement", true); + Oyster::Graphics::API::PlayAnimation(m3, L"movement", true); + t = Oyster::Graphics::API::CreateTexture(L"structure_corp_mdg.png"); t2 = Oyster::Graphics::API::CreateTexture(L"whiteGui.png"); @@ -189,21 +192,21 @@ HRESULT InitDirect3D() - pl.Color = Oyster::Math::Float3(1,0,0); + pl.Color = Oyster::Math::Float3(1,1,1); pl.Bright = 1; 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.Color = Oyster::Math::Float3(1,1,1); 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.Color = Oyster::Math::Float3(1,1,1); pl.Bright = 1; pl.Pos = Oyster::Math::Float3(0,0,20); pl.Radius = 90; @@ -218,6 +221,7 @@ HRESULT Update(float deltaTime) { //angle += Oyster::Math::pi/16 * deltaTime; m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * angle,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null); + m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * -angle,Oyster::Math::Float3(-4,0,0),Oyster::Math::Float3::null); //Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity; Oyster::Graphics::API::Update(deltaTime); //m2->Animation.data.AnimationTime += deltaTime;// * 0.5f; @@ -231,8 +235,9 @@ HRESULT Render(float deltaTime) //Oyster::Graphics::API::RenderModel(m); Oyster::Graphics::API::RenderModel(m2); - Oyster::Graphics::API::StartGuiRender(); - //Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1)); + Oyster::Graphics::API::RenderModel(m3); + //Oyster::Graphics::API::StartGuiRender(); + //Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1), Oyster::Math::Float3(0,0,1)); //Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1),Oyster::Math::Float3(1,0,0)); Oyster::Graphics::API::StartTextRender(); std::wstring fps; From 491dc88bd1b440cdd49dca82b5f35dfa22ed40b3 Mon Sep 17 00:00:00 2001 From: lanariel Date: Thu, 13 Feb 2014 15:24:19 +0100 Subject: [PATCH 4/5] Fixed Glow Mapping --- .../Definitions/GraphicalDefinition.h | 9 ++++ .../OysterGraphics/Render/DefaultRenderer.cpp | 46 +++++++++++++++++-- Code/OysterGraphics/Render/Resources.cpp | 18 +++++++- Code/OysterGraphics/Render/Resources.h | 2 + .../Shader/Passes/Blur/BlurHor.hlsl | 11 ++--- .../Shader/Passes/Blur/BlurSharedData.hlsli | 35 +++++++++----- .../Shader/Passes/Blur/BlurVert.hlsl | 12 ++--- .../Shader/Passes/Gather/GatherPixel.hlsl | 3 +- .../Shader/Passes/Light/LightPass.hlsl | 2 +- .../Shader/Passes/Post/PostPass.hlsl | 30 +++++++++++- Code/Tester/MainTest.cpp | 19 ++++---- 11 files changed, 145 insertions(+), 42 deletions(-) diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h index 0b30ee76..958904a8 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -73,6 +73,15 @@ namespace Oyster int offset; float coff; }; + + struct BlurrData + { + unsigned int StartX; + unsigned int StartY; + unsigned int StopX; + unsigned int StopY; + Math::Float4 BlurMask; + }; } } } \ No newline at end of file diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index 8058cd60..c0c2990e 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -162,6 +162,46 @@ namespace Oyster } } + void BlurGlow() + { + Definitions::BlurrData bd; + bd.BlurMask = Math::Float4(1,1,1,1); + bd.StopX = Core::resolution.x/2; + bd.StopY = Core::resolution.y; + bd.StartX = 0; + bd.StartY = Core::resolution.y/2; + + void* data = Resources::Blur::Data.Map(); + memcpy(data,&bd,sizeof(Definitions::BlurrData)); + Resources::Blur::Data.Unmap(); + + Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass); + Core::deviceContext->Dispatch((UINT)((Core::resolution.x/2 + 127U) / 128U), (UINT)(Core::resolution.y/2), 1); + + Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass); + Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1); + } + + void BlurSSAO() + { + Definitions::BlurrData bd; + bd.BlurMask = Math::Float4(0,0,0,1); + bd.StopX = Core::resolution.x/2; + bd.StopY = Core::resolution.y/2; + bd.StartX = 0; + bd.StartY = 0; + + void* data = Resources::Blur::Data.Map(); + memcpy(data,&bd,sizeof(Definitions::BlurrData)); + Resources::Blur::Data.Unmap(); + + Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass); + Core::deviceContext->Dispatch((UINT)((Core::resolution.x/2 + 127U) / 128U), (UINT)(Core::resolution.y/2), 1); + + Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass); + Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1); + } + void DefaultRenderer::EndFrame() { @@ -169,11 +209,9 @@ namespace Oyster Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); - //Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass); - //Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); + BlurGlow(); - //Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass); - //Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); + BlurSSAO(); Core::PipelineManager::SetRenderPass(Resources::Post::Pass); diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index 77988417..450a075b 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -23,8 +23,8 @@ namespace Oyster { namespace Render { - - ID3D11RenderTargetView* Resources::GBufferRTV[Resources::GBufferSize] = {0}; + #pragma region Declare Static + ID3D11RenderTargetView* Resources::GBufferRTV[Resources::GBufferSize] = {0}; ID3D11ShaderResourceView* Resources::GBufferSRV[Resources::GBufferSize] = {0}; ID3D11UnorderedAccessView* Resources::LBufferUAV[Resources::LBufferSize] = {0}; @@ -48,6 +48,7 @@ namespace Oyster Buffer Resources::Color = Buffer(); Buffer Resources::Gui::Text::Vertex = Buffer(); Buffer Resources::Post::Data = Buffer(); + Buffer Resources::Blur::Data = Buffer(); Buffer Resources::Light::PointLightsData = Buffer(); ID3D11ShaderResourceView* Resources::Light::PointLightView = NULL; @@ -61,6 +62,7 @@ namespace Oyster ID3D11BlendState* Resources::RenderStates::bs = NULL; ID3D11ShaderResourceView* Resources::Gui::Text::Font = NULL; +#pragma endregion Core::Init::State Resources::InitShaders() @@ -135,6 +137,9 @@ namespace Oyster desc.ElementSize = sizeof(Definitions::LightConstants); Light::LightConstantsData.Init(desc); + desc.ElementSize = sizeof(Definitions::BlurrData); + Blur::Data.Init(desc); + desc.ElementSize = sizeof(Definitions::Pointlight); desc.NumElements = MaxLightSize; desc.Type = Buffer::STRUCTURED_BUFFER; @@ -235,6 +240,9 @@ namespace Oyster Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&LBufferSRV[i],&LBufferUAV[i]); } + //Blur + Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&Blur::BufferSRV,&Blur::BufferUAV); + Buffer* b = &Light::PointLightsData; Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&Light::PointLightView,NULL); @@ -377,6 +385,8 @@ namespace Oyster } Post::Pass.UAV.Compute.push_back(Core::backBufferUAV); Post::Pass.CBuffers.Compute.push_back(Post::Data); + Post::Pass.RenderStates.SampleCount = 1; + Post::Pass.RenderStates.SampleState = RenderStates::ss; ////---------------- GUI Pass Setup ---------------------------- Gui::Pass.Shaders.Vertex = GetShader::Vertex(L"2D"); @@ -412,6 +422,9 @@ namespace Oyster //And the Ambient UAV is now the output texture Blur::VertPass.UAV.Compute.push_back(LBufferUAV[2]); + Blur::HorPass.CBuffers.Compute.push_back(Blur::Data); + Blur::VertPass.CBuffers.Compute.push_back(Blur::Data); + ////---------------- 2DText Pass Setup ---------------------------- Gui::Text::Pass.Shaders.Vertex = GetShader::Vertex(L"2DText"); Gui::Text::Pass.Shaders.Geometry = GetShader::Geometry(L"2DText"); @@ -459,6 +472,7 @@ namespace Oyster Color.~Buffer(); Gui::Text::Vertex.~Buffer(); Post::Data.~Buffer(); + Blur::Data.~Buffer(); SAFE_RELEASE(Light::PointLightView); SAFE_RELEASE(Light::SSAOKernel); SAFE_RELEASE(Light::SSAORandom); diff --git a/Code/OysterGraphics/Render/Resources.h b/Code/OysterGraphics/Render/Resources.h index 684762fd..6b4e140e 100644 --- a/Code/OysterGraphics/Render/Resources.h +++ b/Code/OysterGraphics/Render/Resources.h @@ -81,6 +81,8 @@ namespace Oyster //Blur UAV and SRV static ID3D11UnorderedAccessView* BufferUAV; static ID3D11ShaderResourceView* BufferSRV; + + static Core::Buffer Data; }; struct Post diff --git a/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl b/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl index 7489cd41..1383514a 100644 --- a/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl @@ -7,14 +7,14 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID if(gThreadID.x < blurRadius) { int x = max(ThreadID.x-blurRadius,0); - gCache[gThreadID.x] = inTex[int2(x,ThreadID.y)]; + gCache[gThreadID.x] = inTex[min(int2(x,ThreadID.y) + Start, Stop-1)]; } if(gThreadID.x >= N-blurRadius) { - int x = min(ThreadID.x+blurRadius,inTex.Length.x-1); - gCache[gThreadID.x+2*blurRadius] = inTex[int2(x,ThreadID.y)]; + int x = min(ThreadID.x+blurRadius,Stop.x-1); + gCache[gThreadID.x+2*blurRadius] = inTex[int2(x,ThreadID.y) + Start]; } - gCache[gThreadID.x+blurRadius] = inTex[min(ThreadID.xy,inTex.Length.xy-1)]; + gCache[gThreadID.x+blurRadius] = inTex[min(ThreadID.xy + Start, Stop-1)]; GroupMemoryBarrierWithGroupSync(); @@ -27,7 +27,6 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID blurCol +=Weights[i + blurRadius] * gCache[k]; } - outTex[ThreadID.xy] = blurCol; - //Output[ThreadID.xy] = Diffuse[((ThreadID.xy))]; + outTex[ThreadID.xy + Start] = blurCol * BlurMask + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask); } diff --git a/Code/OysterGraphics/Shader/Passes/Blur/BlurSharedData.hlsli b/Code/OysterGraphics/Shader/Passes/Blur/BlurSharedData.hlsli index 8a7b5fd1..a9377560 100644 --- a/Code/OysterGraphics/Shader/Passes/Blur/BlurSharedData.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Blur/BlurSharedData.hlsli @@ -3,12 +3,26 @@ -static const float Weights[9] = +cbuffer BlurrData : register(b1) { - 0.05f, 0.05f, 0.1f, 0.15f, 0.3f, 0.15f, 0.1f, 0.05f, 0.05f + //static const int blurRadius = 0; + //static const float Weights[1] = + //{ + // 1.0f + //}; + /*static const int blurRadius = 4; + static const float Weights[9] = + { + 0.05f, 0.05f, 0.1f, 0.15f, 0.3f, 0.15f, 0.1f, 0.05f, 0.05f + };*/ + static const int blurRadius = 5; + static const float Weights[11] = + { + 0.05f,0.05f,0.1f,0.1f,0.1f,0.2f,0.1f,0.1f,0.1f,0.05f,0.05f + }; }; -static const int blurRadius = 4; + #define N 128 #define gSize (N+2*blurRadius) @@ -17,14 +31,13 @@ groupshared float4 gCache[gSize]; Texture2D inTex : register(t0); RWTexture2D outTex : register(u0); -//cbuffer BlurrData : register(c0) -//{ -// static const int blurRadius = 5; -// static const float Weights[11] = -// { -// 0.05f,0.05f,0.1f,0.1f,0.1f,0.2f,0.1f,0.1f,0.1f,0.05f,0.05f -// }; -//}; +cbuffer BlurrData : register(b0) +{ + uint2 Start; + uint2 Stop; + float4 BlurMask; +}; + //[numthreads(16,16,1)] //void TryCompute(uint3 ThreadID : SV_DispatchThreadID) diff --git a/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl b/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl index aa5e4a27..3d6afae9 100644 --- a/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl @@ -7,14 +7,14 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID if(gThreadID.y < blurRadius) { int y = max(ThreadID.y-blurRadius,0); - gCache[gThreadID.y] = inTex[int2(ThreadID.x,y)]; + gCache[gThreadID.y] = inTex[min(int2(ThreadID.x,y) + Start, Stop-1)]; } if(gThreadID.y >= N-blurRadius) { - int y = min(ThreadID.y+blurRadius,inTex.Length.y-1); - gCache[gThreadID.y+2*blurRadius] = inTex[int2(ThreadID.x,y)]; + int y = min(ThreadID.y+blurRadius, Stop.y-1); + gCache[gThreadID.y+2*blurRadius] = inTex[int2(ThreadID.x,y) + Start]; } - gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy,inTex.Length.xy-1)]; + gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy + Start, Stop.xy-1)]; GroupMemoryBarrierWithGroupSync(); @@ -27,6 +27,6 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID blurCol +=Weights[i + blurRadius] * gCache[k]; } - outTex[ThreadID.xy] = blurCol; - //Output[ThreadID.xy] = inTex[((ThreadID.xy))]; + outTex[ThreadID.xy + Start] = blurCol + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask);; + //outTex[ThreadID.xy] = inTex[ThreadID.xy]; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl index 542d8c54..2a6f3972 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl @@ -45,6 +45,7 @@ PixelOut main(VertexOut input) normal = perturb_normal( normal, normalize(-input.ViewPos), input.UV ); - output.NormalSpec = float4(normal, Normal.Sample(S1, input.UV).w*255); + //output.NormalSpec = float4(normal, Normal.Sample(S1, input.UV).w*255); + output.NormalSpec = float4(normal, Normal.Sample(S1, input.UV).w*0); return output; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl index dc54187e..8e303455 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl @@ -36,7 +36,7 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID ) float AmbValue = GetSSAO(ViewPos, UV, DTid.xy, GTid.xy/2); Ambient[DTid.xy/2] = float4(DiffuseGlow[DTid.xy].xyz, AmbValue); Ambient[DTid.xy/2 + float2(Pixels.x/2, 0)] = GUI[DTid.xy]; - //Ambient[DTid.xy] = GUI[DTid.xy]; + Ambient[DTid.xy/2 + float2(0, Pixels.y/2)] = float4(DiffuseGlow[DTid.xy].xyz * DiffuseGlow[DTid.xy].w*10,1); } } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl index 53cfabb2..85c74fb7 100644 --- a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl @@ -4,23 +4,49 @@ Texture2D Ambient : register(t2); RWTexture2D Output; +SamplerState S1 : register(s0); + cbuffer Size : register(b0) { int2 Pixels; } -#define AmbFactor 0.3f; +#define AmbFactor 0.1f; + +float4 SuperSample(float4 Glow, uint3 DTid) +{ + // Line X + float2 index = (float2)(DTid.xy/2); + index += float2(0,Output.Length.y/2); + index = index / Output.Length; + Glow = Ambient.SampleLevel(S1, index,1); + //Line Y+1 + //Glow += Ambient[DTid.xy/2 + uint2(1,(Output.Length.y/2)+1)] + Ambient[DTid.xy/2 + uint2(0,(Output.Length.y/2)+1)] + Ambient[DTid.xy/2 + uint2(-1,(Output.Length.y/2)+1)]; + //Line Y-1 + //Glow += Ambient[DTid.xy/2 + uint2(1,(Output.Length.y/2)-1)] + Ambient[DTid.xy/2 + uint2(0,(Output.Length.y/2)-1)] + Ambient[DTid.xy/2 + uint2(-1,(Output.Length.y/2)-1)]; + + //Glow = Glow/9; + + return Glow; +} [numthreads(16, 16, 1)] void main( uint3 DTid : SV_DispatchThreadID ) { float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]); float4 Amb = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w, 0); + //float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)]; + float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)]; + + Glow = SuperSample(Glow,DTid); + float4 GUI; uint2 index = DTid.xy/2 + uint2((uint)Pixels.x/(uint)2,0); float3 PostLight = Amb.xyz * AmbFactor; - PostLight = PostLight + Light.xyz; + PostLight = PostLight + Light.xyz + Glow; GUI = float4(Ambient[index]); PostLight = PostLight * (1 - GUI.w); Output[DTid.xy] = float4((GUI.xyz * GUI.w) + PostLight, 1); + + //Output[DTid.xy] = Glow; } \ No newline at end of file diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index 2915d62e..f0d440d6 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -171,11 +171,11 @@ HRESULT InitDirect3D() } 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; + //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->Tint = Oyster::Math::Float3(0.8f,0.8f,1); + m2->Tint = Oyster::Math::Float3(0.1f,0.1f,1); m3 = 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); Oyster::Graphics::API::PlayAnimation(m2, L"movement", true); @@ -193,21 +193,21 @@ HRESULT InitDirect3D() pl.Color = Oyster::Math::Float3(1,1,1); - pl.Bright = 1; + pl.Bright = 0.5f; pl.Pos = Oyster::Math::Float3(-20,0,0); pl.Radius = 90; Oyster::Graphics::API::AddLight(pl); pl.Color = Oyster::Math::Float3(1,1,1); - pl.Bright = 1; + pl.Bright = 0.5f; pl.Pos = Oyster::Math::Float3(0,20,0); pl.Radius = 90; Oyster::Graphics::API::AddLight(pl); pl.Color = Oyster::Math::Float3(1,1,1); - pl.Bright = 1; + pl.Bright = 0.5f; pl.Pos = Oyster::Math::Float3(0,0,20); pl.Radius = 90; @@ -220,6 +220,7 @@ float angle = 0; HRESULT Update(float deltaTime) { //angle += Oyster::Math::pi/16 * deltaTime; + m->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0) * angle,Oyster::Math::Float3(0,0,0),Oyster::Math::Float3::null); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * angle,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null); m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * -angle,Oyster::Math::Float3(-4,0,0),Oyster::Math::Float3::null); //Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity; @@ -233,10 +234,10 @@ HRESULT Render(float deltaTime) Oyster::Graphics::API::SetView(V); Oyster::Graphics::API::NewFrame(); - //Oyster::Graphics::API::RenderModel(m); + Oyster::Graphics::API::RenderModel(m); Oyster::Graphics::API::RenderModel(m2); Oyster::Graphics::API::RenderModel(m3); - //Oyster::Graphics::API::StartGuiRender(); + Oyster::Graphics::API::StartGuiRender(); //Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1), Oyster::Math::Float3(0,0,1)); //Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1),Oyster::Math::Float3(1,0,0)); Oyster::Graphics::API::StartTextRender(); From e71264b8062fd46dbc52d6ecd9a5252d1e6cb3b9 Mon Sep 17 00:00:00 2001 From: lanariel Date: Thu, 13 Feb 2014 16:27:53 +0100 Subject: [PATCH 5/5] New text render --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 6 ++-- Code/OysterGraphics/DllInterfaces/GFXAPI.h | 4 +-- Code/OysterGraphics/Render/GuiRenderer.cpp | 31 ++++++++++++-------- Code/OysterGraphics/Render/GuiRenderer.h | 4 +-- Code/Tester/MainTest.cpp | 2 +- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 8cb80fe2..381b12cf 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -159,7 +159,7 @@ namespace Oyster Render::Gui::Begin2DRender(); } - void API::RenderGuiElement(API::Texture tex, Math::Float2 pos, Math::Float2 size, Math::Float3 color) + void API::RenderGuiElement(API::Texture tex, Math::Float3 pos, Math::Float2 size, Math::Float3 color) { Render::Gui::Render((ID3D11ShaderResourceView*)tex,pos,size,color); } @@ -192,9 +192,9 @@ namespace Oyster Render::Gui::Begin2DTextRender(); } - void API::RenderText(std::wstring text, Math::Float2 Pos, Math::Float2 Size, Math::Float3 color) + void API::RenderText(std::wstring text, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 color) { - Render::Gui::RenderText(text,Pos,Size,color); + Render::Gui::RenderText(text, Pos, Size, FontSize, color); } } } \ No newline at end of file diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index bdf70072..e2cea318 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -57,13 +57,13 @@ namespace Oyster static void StartGuiRender(); //! @brief Renders a single GUI element using the texture provided and the Pos in the center, %based system - static void RenderGuiElement(Texture, Math::Float2 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1)); + static void RenderGuiElement(Texture, Math::Float3 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1)); //! @brief Configures Renderer to process 2D Text, data will be passed in to EndFrame() static void StartTextRender(); //! @brief Renders a single GUI string using the texture provided and the Pos in the center, %based system - static void RenderText(std::wstring, Math::Float2 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1)); + static void RenderText(std::wstring, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 Color = Math::Float3(1,1,1)); //! @brief Performs light calculations, post effects and presents the scene static void EndFrame(); diff --git a/Code/OysterGraphics/Render/GuiRenderer.cpp b/Code/OysterGraphics/Render/GuiRenderer.cpp index 7f3285e1..78b2f771 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.cpp +++ b/Code/OysterGraphics/Render/GuiRenderer.cpp @@ -16,7 +16,7 @@ namespace Oyster Core::PipelineManager::SetRenderPass(Render::Resources::Gui::Pass); } - void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float2 pos, Math::Float2 size, Math::Float3 color) + void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float3 pos, Math::Float2 size, Math::Float3 color) { Core::deviceContext->PSSetShaderResources(0,1,&tex); @@ -28,6 +28,7 @@ namespace Oyster gd.Translation = Math::Matrix::identity; gd.Translation.m41 = pos.x; gd.Translation.m42 = pos.y; + gd.Translation.m43 = pos.z; gd.Translation.m11 = size.x; gd.Translation.m22 = size.y; @@ -49,10 +50,10 @@ namespace Oyster Core::PipelineManager::SetRenderPass(Resources::Gui::Text::Pass); } - void Gui::RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size, Math::Float3 color) + void Gui::RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float3 color) { - size.x = size.x / (text.length() * TEXT_SPACING /2); + //size.x = size.x / (text.length() * TEXT_SPACING /2); pos *= 2; @@ -60,15 +61,18 @@ namespace Oyster pos.y *= -1; - pos.x = pos.x - (size.x * (text.length()-1) * TEXT_SPACING /2); + //pos.x = pos.x - (size.x * (text.length()-1) * TEXT_SPACING /2); + pos.x = pos.x + size.x/ (text.length() * TEXT_SPACING/2); + pos.y = pos.y - size.y/2; Definitions::GuiData gd; gd.Translation = Math::Matrix::identity; gd.Translation.m41 = pos.x; gd.Translation.m42 = pos.y; - gd.Translation.m11 = size.x; - gd.Translation.m22 = size.y; + gd.Translation.m43 = pos.z; + gd.Translation.m11 = FontSize * 0.8f; + gd.Translation.m22 = FontSize; void* data = Render::Resources::Gui::Data.Map(); @@ -82,19 +86,20 @@ namespace Oyster void* dest = Resources::Gui::Text::Vertex.Map(); Definitions::Text2D* dataView = reinterpret_cast(dest); - //tmpInst.charOffset=_pos; + for (unsigned int i=0; i size.x) + { + text = text.substr(0,i-1); + break; + } dataView[i]=tmpInst; } - //TextInstances[_id].NumLetters=instances; + Resources::Gui::Text::Vertex.Unmap(); diff --git a/Code/OysterGraphics/Render/GuiRenderer.h b/Code/OysterGraphics/Render/GuiRenderer.h index f5513d2f..3e4a8de0 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.h +++ b/Code/OysterGraphics/Render/GuiRenderer.h @@ -12,9 +12,9 @@ namespace Oyster { public: static void Begin2DRender(); - static void Render(ID3D11ShaderResourceView* tex, Math::Float2 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1)); + static void Render(ID3D11ShaderResourceView* tex, Math::Float3 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1)); static void Begin2DTextRender(); - static void RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1)); + static void RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float3 tint = Math::Float3(1,1,1)); }; } } diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index f0d440d6..ad71dabb 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -246,7 +246,7 @@ HRESULT Render(float 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::Math::Float3(0,1,0)); + Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float3(0.5f,0.1f,1.0f),Oyster::Math::Float2(0.5f,0.1f), 0.08f, Oyster::Math::Float3(0,1,0)); Oyster::Graphics::API::EndFrame(); return S_OK;