Stable Graphics, hard coded texture read in ObjReader.ToModel

This commit is contained in:
lanariel 2013-11-28 14:34:52 +01:00
parent 8f6ca79e6b
commit 9bf84cdc65
17 changed files with 106 additions and 61 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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);
}

View File

@ -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[]);
}
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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[]);
}
}
}

View File

@ -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)

View File

@ -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

View File

@ -0,0 +1,7 @@
struct PointLight
{
float3 Pos;
float Radius;
float3 Color;
}

View File

@ -0,0 +1,11 @@
//todo
//LightCulling
//Calc Diff + Spec
//Calc Ambience
//Write Glow
[numthreads(1, 1, 1)]
void main( uint3 DTid : SV_DispatchThreadID )
{
}

View File

@ -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;
};
};
struct VertexIn
{
float3 pos : POSITION;
float2 UV : TEXCOORD;
float3 normal : NORMAL;
};

View File

@ -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;
}

View File

@ -1,4 +1,4 @@
#include "Debug.hlsli"
//#include "Debug.hlsli"
float4 main() : SV_TARGET
{

View File

@ -1,4 +1,4 @@
#include "Debug.hlsli"
#include "Debug.hlsl"
Texture2D tex : register(t0);
SamplerState S1 : register(s0);

View File

@ -53,7 +53,6 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL
params.lpCmdLine="";
params.lpCmdShow="";
params.lpEnvAddress="";
LoadModule("OysterGraphics_x86D.dll",&params);
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;
}