diff --git a/Code/Misc/Resource/Loaders/CustomLoader.cpp b/Code/Misc/Resource/Loaders/CustomLoader.cpp index 312c4c53..b7949ba1 100644 --- a/Code/Misc/Resource/Loaders/CustomLoader.cpp +++ b/Code/Misc/Resource/Loaders/CustomLoader.cpp @@ -12,16 +12,16 @@ using namespace Oyster::Resource; OResource* OResource::CustomLoader(const wchar_t filename[], CustomLoadFunction fnc) { - const CustomData &data = fnc(filename); + CustomData &data = fnc(filename); if(!data.loadedData) return 0; if(!data.resourceUnloadFnc) return 0; - - OResource *resource = new OResource((OHRESOURCE)data.loadedData, ResourceType_UNKNOWN, 0, 0, filename); + OHRESOURCE n = (OHRESOURCE)data.loadedData; + OResource *resource = new OResource(n, ResourceType_UNKNOWN, 0, 0, filename); resource->customData = new CustomResourceData(); resource->customData->unloadingFunction = data.resourceUnloadFnc; - resource->resourceData = (OHRESOURCE)data.loadedData; + //resource->resourceData = (OHRESOURCE)data.loadedData; resource->customData->loadingFunction = fnc; return resource; diff --git a/Code/Misc/Resource/OysterResource.h b/Code/Misc/Resource/OysterResource.h index 16d5122d..0c334421 100644 --- a/Code/Misc/Resource/OysterResource.h +++ b/Code/Misc/Resource/OysterResource.h @@ -16,7 +16,7 @@ namespace Oyster /** Typedef on a fuction required for custom unloading */ typedef void(*CustomUnloadFunction)(void* loadedData); /** Typedef on a fuction required for custom loading */ - typedef const CustomData&(*CustomLoadFunction)(const wchar_t filename[]); + typedef CustomData&(*CustomLoadFunction)(const wchar_t filename[]); /** An enum class representing all avalible resources that is supported. */ enum ResourceType diff --git a/Code/OysterGraphics/Core/Init.cpp b/Code/OysterGraphics/Core/Init.cpp index 48abd444..c69b80b4 100644 --- a/Code/OysterGraphics/Core/Init.cpp +++ b/Code/OysterGraphics/Core/Init.cpp @@ -175,7 +175,7 @@ namespace Oyster D3D11_TEXTURE2D_DESC desc; desc.MipLevels=1; desc.ArraySize=1; - desc.Format = DXGI_FORMAT_D32_FLOAT; + desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; desc.Usage = D3D11_USAGE_DEFAULT; desc.BindFlags = D3D11_BIND_DEPTH_STENCIL; desc.CPUAccessFlags=0; diff --git a/Code/OysterGraphics/Core/ShaderManager.cpp b/Code/OysterGraphics/Core/ShaderManager.cpp index 9789e199..c2ad8565 100644 --- a/Code/OysterGraphics/Core/ShaderManager.cpp +++ b/Code/OysterGraphics/Core/ShaderManager.cpp @@ -144,7 +144,7 @@ namespace Oyster ID3D11PixelShader* pixel; - if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,NULL,ShaderFunction,"ps_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error))) + if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,ShaderFunction,"ps_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error))) { std::string fel = (char*)Error->GetBufferPointer(); Error->Release(); @@ -171,7 +171,7 @@ namespace Oyster ID3D11GeometryShader* geometry; - if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,NULL,ShaderFunction,"gs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error))) + if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,ShaderFunction,"gs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error))) { std::string fel = (char*)Error->GetBufferPointer(); Error->Release(); @@ -198,7 +198,7 @@ namespace Oyster ID3D11VertexShader* vertex; - if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,NULL,ShaderFunction,"vs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error))) + if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,ShaderFunction,"vs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error))) { std::string fel = (char*)Error->GetBufferPointer(); Error->Release(); @@ -344,6 +344,7 @@ namespace Oyster se.CBuffers.Pixel[i]->Apply(i); Core::deviceContext->RSSetState(se.RenderStates.Rasterizer); Core::deviceContext->PSSetSamplers(0,se.RenderStates.SampleCount,se.RenderStates.SampleState); + Core::deviceContext->OMSetDepthStencilState(se.RenderStates.DepthStencil,0); float test[4] = {0}; Core::deviceContext->OMSetBlendState(se.RenderStates.BlendState,test,-1); } diff --git a/Code/OysterGraphics/FileLoader/GeneralLoader.h b/Code/OysterGraphics/FileLoader/GeneralLoader.h new file mode 100644 index 00000000..bf634911 --- /dev/null +++ b/Code/OysterGraphics/FileLoader/GeneralLoader.h @@ -0,0 +1,16 @@ +#pragma once +#include "..\..\Misc\Resource\OysterResource.h" +namespace Oyster +{ + namespace Graphics + { + namespace Loading + { + void UnloadTexture(void* loadedData); + Oyster::Resource::CustomData& LoadTexture(const wchar_t filename[]); + + void UnloadShader(void* loadedData); + Oyster::Resource::CustomData& LoadShader(const wchar_t filename[]); + } + } +} \ No newline at end of file diff --git a/Code/OysterGraphics/FileLoader/ObjReader.cpp b/Code/OysterGraphics/FileLoader/ObjReader.cpp index 116c8245..902ec505 100644 --- a/Code/OysterGraphics/FileLoader/ObjReader.cpp +++ b/Code/OysterGraphics/FileLoader/ObjReader.cpp @@ -119,9 +119,10 @@ Oyster::Graphics::Model::ModelInfo* OBJReader::toModel() modelInfo->Vertices = b; - Oyster::Resource::OHRESOURCE diffuse = Oyster::Resource::OysterResource::LoadResource(L"bth.png",Oyster::Graphics::Loading::LoadTexture); + Oyster::Resource::OHRESOURCE diffuse = Oyster::Resource::OysterResource::LoadResource(L"orca_tex.jpg",Oyster::Graphics::Loading::LoadTexture); //Oyster::Resource::OysterResource::LoadResource(L"Normal.png",(Oyster::Resource::CustomLoadFunction)Oyster::Graphics::Loading::LoadTexture); - modelInfo->Material.push_back((ID3D11ShaderResourceView*)diffuse); + void* v = (void*)diffuse; + modelInfo->Material.push_back((ID3D11ShaderResourceView*)v); return modelInfo; } diff --git a/Code/OysterGraphics/FileLoader/TextureLoader.cpp b/Code/OysterGraphics/FileLoader/TextureLoader.cpp index 0937a706..4afd1f7d 100644 --- a/Code/OysterGraphics/FileLoader/TextureLoader.cpp +++ b/Code/OysterGraphics/FileLoader/TextureLoader.cpp @@ -14,9 +14,9 @@ HRESULT CreateWICTextureFromFileEx( ID3D11Device* d3dDevice, ID3D11Resource** texture, ID3D11ShaderResourceView** textureView ); -const Oyster::Resource::CustomData& Oyster::Graphics::Loading::LoadTexture(const wchar_t filename[]) +Oyster::Resource::CustomData& Oyster::Graphics::Loading::LoadTexture(const wchar_t filename[]) { - ID3D11ShaderResourceView* srv; + ID3D11ShaderResourceView* srv = NULL; Oyster::Resource::CustomData Ret; HRESULT hr = CreateWICTextureFromFileEx(Core::device,Core::deviceContext,filename,0,D3D11_USAGE_DEFAULT,D3D11_BIND_SHADER_RESOURCE,0,0,false,NULL,&srv); if(hr!=S_OK) @@ -25,7 +25,7 @@ const Oyster::Resource::CustomData& Oyster::Graphics::Loading::LoadTexture(const } else { - Ret.loadedData = srv; + Ret.loadedData = (void*)srv; Ret.resourceUnloadFnc = Loading::UnloadTexture; } diff --git a/Code/OysterGraphics/FileLoader/TextureLoader.h b/Code/OysterGraphics/FileLoader/TextureLoader.h deleted file mode 100644 index bb096fec..00000000 --- a/Code/OysterGraphics/FileLoader/TextureLoader.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include "..\..\Misc\Resource\OysterResource.h" -namespace Oyster -{ - namespace Graphics - { - namespace Loading - { - void UnloadTexture(void* loadedData); - const Oyster::Resource::CustomData& LoadTexture(const wchar_t filename[]); - } - } -} \ No newline at end of file diff --git a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp index 5e1fbb48..50e7f9f1 100644 --- a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp +++ b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp @@ -14,9 +14,9 @@ namespace Oyster void Basic::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection) { - Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,1)); + Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(1,0,0,1)); Core::ShaderManager::SetShaderEffect(Graphics::Render::Resources::obj); - Preparations::Basic::BindBackBufferRTV(nullptr); + Preparations::Basic::BindBackBufferRTV(); Definitions::VP vp; vp.V = View; @@ -39,10 +39,11 @@ namespace Oyster memcpy(data,&(models[i].WorldMatrix),sizeof(Math::Float4x4)); Resources::ModelData.Unmap(); - //Set Materials :: NONE + + Model::ModelInfo* info = (Model::ModelInfo*)models[i].info; + + Core::deviceContext->PSSetShaderResources(0,info->Material.size(),&(info->Material[0])); - Model - ::ModelInfo* info = (Model::ModelInfo*)models[i].info; info->Vertices->Apply(); if(info->Indexed) diff --git a/Code/OysterGraphics/Render/Resources/Resources.cpp b/Code/OysterGraphics/Render/Resources/Resources.cpp index d06145fa..2658149c 100644 --- a/Code/OysterGraphics/Render/Resources/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources/Resources.cpp @@ -65,9 +65,9 @@ namespace Oyster /** @todo Create DX States */ D3D11_RASTERIZER_DESC rdesc; - rdesc.CullMode = D3D11_CULL_NONE; + rdesc.CullMode = D3D11_CULL_BACK; rdesc.FillMode = D3D11_FILL_SOLID; - rdesc.FrontCounterClockwise = false; + rdesc.FrontCounterClockwise = true; rdesc.DepthBias = 0; rdesc.DepthBiasClamp = 0; rdesc.DepthClipEnable = true; @@ -82,19 +82,41 @@ namespace Oyster D3D11_SAMPLER_DESC sdesc; sdesc.Filter = D3D11_FILTER_ANISOTROPIC; /// @todo parata med fredrik om wraping - sdesc.AddressU = D3D11_TEXTURE_ADDRESS_MIRROR_ONCE; - sdesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; - sdesc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER; + sdesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; + sdesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; + sdesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; sdesc.MipLODBias = 0; sdesc.MaxAnisotropy =4; - sdesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; - *sdesc.BorderColor = *Oyster::Math::Float4(0,0,0,1).element; + sdesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL; + *sdesc.BorderColor = *Oyster::Math::Float4(1,1,1,1).element; sdesc.MinLOD = 0; sdesc.MaxLOD = D3D11_FLOAT32_MAX; ID3D11SamplerState** ss = new ID3D11SamplerState*[1]; Oyster::Graphics::Core::device->CreateSamplerState(&sdesc,ss); + D3D11_DEPTH_STENCIL_DESC ddesc; + ddesc.DepthEnable = true; + ddesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; + ddesc.DepthFunc = D3D11_COMPARISON_LESS; + + ddesc.StencilEnable = true; + ddesc.StencilReadMask = 0xFF; + ddesc.StencilWriteMask = 0xFF; + + ddesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; + ddesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR; + ddesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; + ddesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; + + ddesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; + ddesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR; + ddesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; + ddesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; + + ID3D11DepthStencilState* dsState; + Core::device->CreateDepthStencilState(&ddesc,&dsState); + #pragma endregion #pragma region Setup Views @@ -103,8 +125,8 @@ namespace Oyster #pragma region Create Shader Effects /** @todo Create ShaderEffects */ - obj.Shaders.Pixel = GetShader::Pixel(PixelRed); - obj.Shaders.Vertex = GetShader::Vertex(VertexDebug); + obj.Shaders.Pixel = GetShader::Pixel(PixelTexture); + obj.Shaders.Vertex = GetShader::Vertex(VertexTransformDebug); D3D11_INPUT_ELEMENT_DESC indesc[] = { @@ -120,6 +142,7 @@ namespace Oyster obj.RenderStates.Rasterizer = rs; obj.RenderStates.SampleCount = 1; obj.RenderStates.SampleState = ss; + obj.RenderStates.DepthStencil = dsState; ModelData.Apply(1); #pragma endregion diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/Defines.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/Defines.hlsli new file mode 100644 index 00000000..e5a2333f --- /dev/null +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/Defines.hlsli @@ -0,0 +1,7 @@ +struct PointLight +{ + float3 Pos; + float Radius; + + float3 Color; +} \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/LightPass.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/LightPass.hlsl new file mode 100644 index 00000000..8fdac3c8 --- /dev/null +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Render/LightPass.hlsl @@ -0,0 +1,11 @@ + +//todo +//LightCulling +//Calc Diff + Spec +//Calc Ambience +//Write Glow + +[numthreads(1, 1, 1)] +void main( uint3 DTid : SV_DispatchThreadID ) +{ +} \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/SimpleDebug/Debug.hlsli b/Code/OysterGraphics/Shader/HLSL/SimpleDebug/Debug.hlsl similarity index 99% rename from Code/OysterGraphics/Shader/HLSL/SimpleDebug/Debug.hlsli rename to Code/OysterGraphics/Shader/HLSL/SimpleDebug/Debug.hlsl index 9e66825e..d1ff1089 100644 --- a/Code/OysterGraphics/Shader/HLSL/SimpleDebug/Debug.hlsli +++ b/Code/OysterGraphics/Shader/HLSL/SimpleDebug/Debug.hlsl @@ -9,17 +9,17 @@ cbuffer PerModel : register(b1) matrix World; } -struct VertexIn -{ - float3 pos : POSITION; - float2 UV : TEXCOORD; - float3 normal : NORMAL; -}; - struct VertexOut { float4 Pos : SV_POSITION; float2 UV : TEXCOORD; float3 Normal : NORMAL; float4 Wpos : POSITION; -}; \ No newline at end of file +}; + +struct VertexIn +{ + float3 pos : POSITION; + float2 UV : TEXCOORD; + float3 normal : NORMAL; +}; diff --git a/Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugCameraVertex.hlsl b/Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugCameraVertex.hlsl index 93145d1c..6095911d 100644 --- a/Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugCameraVertex.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugCameraVertex.hlsl @@ -1,5 +1,4 @@ -#include "Debug.hlsli" - +#include "Debug.hlsl" VertexOut main( VertexIn input ) { @@ -9,5 +8,6 @@ VertexOut main( VertexIn input ) outp.Pos = mul(VP, outp.Wpos ); outp.UV = input.UV; outp.Normal = input.normal; + return outp; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugPixel.hlsl b/Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugPixel.hlsl index 49bc7450..ebca8dde 100644 --- a/Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugPixel.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugPixel.hlsl @@ -1,4 +1,4 @@ -#include "Debug.hlsli" +//#include "Debug.hlsli" float4 main() : SV_TARGET { diff --git a/Code/OysterGraphics/Shader/HLSL/SimpleDebug/TextureDebug.hlsl b/Code/OysterGraphics/Shader/HLSL/SimpleDebug/TextureDebug.hlsl index a489adbe..d52debf3 100644 --- a/Code/OysterGraphics/Shader/HLSL/SimpleDebug/TextureDebug.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/SimpleDebug/TextureDebug.hlsl @@ -1,4 +1,4 @@ -#include "Debug.hlsli" +#include "Debug.hlsl" Texture2D tex : register(t0); SamplerState S1 : register(s0); diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index dde166d7..50656974 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -53,7 +53,6 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL params.lpCmdLine=""; params.lpCmdShow=""; params.lpEnvAddress=""; - LoadModule("OysterGraphics_x86D.dll",¶ms); if( FAILED( InitWindow( hInstance, nCmdShow ) ) ) return 0; @@ -184,24 +183,23 @@ HRESULT InitDirect3D() #pragma endregion #pragma region Obj - m = Oyster::Graphics::API::CreateModel(L"bth.obj"); - m->WorldMatrix *= 0.1f; - m->WorldMatrix.m44 = 1; + m = Oyster::Graphics::API::CreateModel(L"orca_dummy.obj"); #pragma endregion - P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,100); + P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000); - V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,-1.5f,10.4f)); + V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f)); V = Oyster::Math3D::InverseOrientationMatrix(V); return S_OK; } - +float angle = 0; HRESULT Update(float deltaTime) { - m->WorldMatrix.m14 += 0.0001f; + angle += Oyster::Math::pi/30000; + m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle); return S_OK; }