Working SSAO + Read Animated .dan

This commit is contained in:
lanariel 2014-01-22 16:31:33 +01:00
parent 893934dcf4
commit 6b1dd34a72
10 changed files with 387 additions and 228 deletions

View File

@ -102,18 +102,25 @@ struct MaterialHeader
/// ///
struct SkeletonHeader struct SkeletonHeader
{ {
// do this... unsigned int numBones;
///
SkeletonHeader(char* data)
{
memcpy(&numBones, data, sizeof(unsigned int));
}
}; };
/// ///
struct AnimationHeader struct AnimationHeader
{ {
// do this... unsigned int numAnims;
};
struct Frame
{ AnimationHeader(char* data)
// do this... {
memcpy(&numAnims, data, sizeof(unsigned int));
}
}; };
/// ///
@ -134,14 +141,22 @@ void Oyster::Graphics::Loading::UnloadDAN(void* data)
static wchar_t* charToWChar(const char* text) static wchar_t* charToWChar(const char* text)
{ {
// Convert to a wchar_t* // Convert to a wchar_t*
size_t origsize = strlen(text) + 1; size_t origsize = strlen(text) + 1;
size_t convertedChars = 0; size_t convertedChars = 0;
wchar_t* wcstring = new wchar_t[origsize]; wchar_t* wcstring = new wchar_t[origsize];
mbstowcs_s(&convertedChars, wcstring, origsize, text, _TRUNCATE); mbstowcs_s(&convertedChars, wcstring, origsize, text, _TRUNCATE);
return wcstring; return wcstring;
} }
static void ReadData(void* Destination, std::ifstream& file, int size)
{
char* buffer = new char[size];
file.read(buffer,size);
memcpy(Destination,buffer,size);
delete[] buffer;
}
/// ///
void Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[], Oyster::Resource::CustomData& out) void Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[], Oyster::Resource::CustomData& out)
{ {
@ -172,10 +187,7 @@ void Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[], Oyster::Resour
{ {
// read header type // read header type
unsigned int headerType; unsigned int headerType;
buffer = new char[4]; ReadData(&headerType,danFile,4);
danFile.read(buffer, 4);
memcpy(&headerType, buffer, 4);
//delete[] buffer; // ( note: may crash here.)
// handle header type // handle header type
switch ((HeaderType)headerType) switch ((HeaderType)headerType)
@ -190,18 +202,15 @@ void Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[], Oyster::Resour
delete[] buffer; // ( note: may crash here.) delete[] buffer; // ( note: may crash here.)
// Fetch all vertices // Fetch all vertices
Vertex* vertices = new Vertex[vertexHeader.numVertices];
unsigned int bufferSize = VERTEXSIZE * vertexHeader.numVertices; unsigned int bufferSize = VERTEXSIZE * vertexHeader.numVertices;
buffer = new char[bufferSize]; buffer = new char[bufferSize];
danFile.read(buffer, bufferSize); danFile.read(buffer, bufferSize);
memcpy(vertices, buffer, bufferSize);
delete[] buffer; // ( note: may crash here.)
// Do the deed // Do the deed
Oyster::Graphics::Core::Buffer* vertexBuffer = new Oyster::Graphics::Core::Buffer(); Oyster::Graphics::Core::Buffer* vertexBuffer = new Oyster::Graphics::Core::Buffer();
Oyster::Graphics::Core::Buffer::BUFFER_INIT_DESC bufferInitDesc; Oyster::Graphics::Core::Buffer::BUFFER_INIT_DESC bufferInitDesc;
bufferInitDesc.ElementSize = sizeof(Vertex); bufferInitDesc.ElementSize = sizeof(Vertex);
bufferInitDesc.InitData = vertices; bufferInitDesc.InitData = buffer;
bufferInitDesc.NumElements = vertexHeader.numVertices; bufferInitDesc.NumElements = vertexHeader.numVertices;
bufferInitDesc.Type = Oyster::Graphics::Core::Buffer::BUFFER_TYPE::VERTEX_BUFFER; bufferInitDesc.Type = Oyster::Graphics::Core::Buffer::BUFFER_TYPE::VERTEX_BUFFER;
bufferInitDesc.Usage = Oyster::Graphics::Core::Buffer::BUFFER_USAGE::BUFFER_DEFAULT; bufferInitDesc.Usage = Oyster::Graphics::Core::Buffer::BUFFER_USAGE::BUFFER_DEFAULT;
@ -209,7 +218,8 @@ void Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[], Oyster::Resour
modelInfo->VertexCount = vertexHeader.numVertices; modelInfo->VertexCount = vertexHeader.numVertices;
modelInfo->Vertices = vertexBuffer; modelInfo->Vertices = vertexBuffer;
delete[] vertices; // ( note: may crash here.)
delete[] buffer; // ( note: may crash here.)
break; break;
} }
@ -224,10 +234,9 @@ void Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[], Oyster::Resour
// Fetch all indices // Fetch all indices
unsigned int* indices = new unsigned int[indexHeader.numIndices]; unsigned int* indices = new unsigned int[indexHeader.numIndices];
unsigned int bufferSize = sizeof(unsigned int) * indexHeader.numIndices; unsigned int bufferSize = sizeof(unsigned int) * indexHeader.numIndices;
buffer = new char[bufferSize];
danFile.read(buffer, bufferSize);
memcpy(indices, buffer, bufferSize); ReadData(indices,danFile,bufferSize);
delete[] buffer; // ( note: may crash here.)
// Do the deed // Do the deed
Oyster::Graphics::Core::Buffer* indexBuffer = new Oyster::Graphics::Core::Buffer(); Oyster::Graphics::Core::Buffer* indexBuffer = new Oyster::Graphics::Core::Buffer();
@ -251,48 +260,153 @@ void Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[], Oyster::Resour
{ {
// Fetch material header, 2 texture path strings // Fetch material header, 2 texture path strings
MaterialHeader materialHeader; MaterialHeader materialHeader;
buffer = new char[4];
danFile.read(buffer, 4);
memcpy(&materialHeader.diffuseMapPathLength, buffer, 4);
delete[] buffer; // ( note: may crash here.)
buffer = new char[materialHeader.diffuseMapPathLength]; //read difuse map name length
danFile.read(buffer, materialHeader.diffuseMapPathLength); ReadData(&materialHeader.diffuseMapPathLength,danFile,4);
//read diffuse map name
materialHeader.diffuseMapPath = new char[materialHeader.diffuseMapPathLength+1]; materialHeader.diffuseMapPath = new char[materialHeader.diffuseMapPathLength+1];
memcpy(materialHeader.diffuseMapPath, buffer, materialHeader.diffuseMapPathLength); ReadData(materialHeader.diffuseMapPath,danFile,materialHeader.diffuseMapPathLength);
//null terminate
materialHeader.diffuseMapPath[materialHeader.diffuseMapPathLength] = 0; materialHeader.diffuseMapPath[materialHeader.diffuseMapPathLength] = 0;
delete[] buffer; // ( note: may crash here.)
buffer = new char[4]; //read normal map name length
danFile.read(buffer, 4); ReadData(&materialHeader.normalMapPathLength,danFile,4);
memcpy(&materialHeader.normalMapPathLength, buffer, 4);
delete[] buffer; // ( note: may crash here.)
buffer = new char[materialHeader.normalMapPathLength]; //read difuse map name
danFile.read(buffer, materialHeader.normalMapPathLength);
materialHeader.normalMapPath = new char[materialHeader.normalMapPathLength + 1]; materialHeader.normalMapPath = new char[materialHeader.normalMapPathLength + 1];
memcpy(materialHeader.normalMapPath, buffer, materialHeader.normalMapPathLength); ReadData(materialHeader.normalMapPath,danFile,materialHeader.normalMapPathLength);
materialHeader.normalMapPath[materialHeader.normalMapPathLength] = 0; materialHeader.normalMapPath[materialHeader.normalMapPathLength] = 0;
delete[] buffer; // ( note: may crash here.)
// //load diffuse map
ID3D11ShaderResourceView* diffuseMap = (ID3D11ShaderResourceView*)Oyster::Resource::OysterResource::LoadResource(charToWChar(materialHeader.diffuseMapPath), Oyster::Graphics::Loading::LoadTexture); wchar_t* path = charToWChar(materialHeader.diffuseMapPath);
ID3D11ShaderResourceView* normalMap = (ID3D11ShaderResourceView*)Oyster::Resource::OysterResource::LoadResource(charToWChar(materialHeader.normalMapPath), Oyster::Graphics::Loading::LoadTexture); ID3D11ShaderResourceView* diffuseMap = (ID3D11ShaderResourceView*)Oyster::Resource::OysterResource::LoadResource(path, Oyster::Graphics::Loading::LoadTexture);
delete[] path;
//load normal map
path = charToWChar(materialHeader.normalMapPath);
ID3D11ShaderResourceView* normalMap = (ID3D11ShaderResourceView*)Oyster::Resource::OysterResource::LoadResource(path, Oyster::Graphics::Loading::LoadTexture);
delete[] path;
//add to model
modelInfo->Material.push_back(diffuseMap); modelInfo->Material.push_back(diffuseMap);
modelInfo->Material.push_back(normalMap); modelInfo->Material.push_back(normalMap);
//clean up
delete[] materialHeader.diffuseMapPath;
delete[] materialHeader.normalMapPath;
break; break;
} }
// skeleton header // skeleton header
case HeaderType::SKELETONHEADER: case HeaderType::SKELETONHEADER:
{ {
// not implemented... // Fetch Skeleton header, number of Bones
buffer = new char[4];
danFile.read(buffer, 4);
SkeletonHeader skeletonHeader(buffer);
delete[] buffer; // ( note: may crash here.)
//array for bone data
Oyster::Math::Matrix* bones = new Oyster::Math::Matrix[skeletonHeader.numBones*2];
//read bones
ReadData(bones,danFile,skeletonHeader.numBones * 2 * sizeof(Oyster::Math::Matrix));
//init Graphics data
Oyster::Graphics::Core::Buffer* skeleton = new Oyster::Graphics::Core::Buffer();
Oyster::Graphics::Core::Buffer::BUFFER_INIT_DESC initDesc;
initDesc.ElementSize = sizeof(Oyster::Math::Matrix);
initDesc.InitData = bones;
initDesc.NumElements = skeletonHeader.numBones * 2;
initDesc.Type = Oyster::Graphics::Core::Buffer::BUFFER_TYPE::CONSTANT_BUFFER_VS;
initDesc.Usage = Oyster::Graphics::Core::Buffer::BUFFER_USAGE::BUFFER_USAGE_IMMUTABLE;
skeleton->Init(initDesc);
modelInfo->Skeleton = skeleton;
//read skeleton Hiarchy
int* parents = new int[skeletonHeader.numBones];
ReadData(parents,danFile,skeletonHeader.numBones * sizeof(int));
//store hiarchy
Oyster::Graphics::Model::Bone* Bones = new Oyster::Graphics::Model::Bone[skeletonHeader.numBones];
for(int i = 0; i < skeletonHeader.numBones; ++i)
{
Bones[i].Parent = parents[i];
Bones[i].Transform = bones[i];
}
modelInfo->BoneCount = skeletonHeader.numBones;
modelInfo->bones = Bones;
break; break;
} }
// animation header // animation header
case HeaderType::ANIMATIONHEADER: case HeaderType::ANIMATIONHEADER:
{ {
// not implemented... //get num anims
buffer = new char[4];
danFile.read(buffer, 4);
AnimationHeader animationHeader(buffer);
delete[] buffer;
Oyster::Graphics::Model::Animation* anims = new Oyster::Graphics::Model::Animation[animationHeader.numAnims];
for(int a = 0; a < animationHeader.numAnims; ++a)
{
//read name of animation
int nameLength;
ReadData(&nameLength,danFile,4);
char* name = new char[nameLength + 1];
ReadData(name,danFile,nameLength);
name[nameLength] = 0;
wchar_t* wName = charToWChar(name);
anims[a].name = std::wstring(wName);
delete[] wName;
Oyster::Graphics::Model::Animation A = anims[a];
//read nr of bones in animation
ReadData(&A.Bones,danFile,4);
//create Frame array and Bone part of KeyFrameArray;
A.Frames = new int[A.Bones];
A.Keyframes = new Oyster::Graphics::Model::Frame*[A.Bones];
//loop per bone and gather data
for(int b = 0; b < A.Bones; ++b)
{
//read nr of frames per bone
ReadData(&A.Frames[b],danFile,4);
//create frame matrix
A.Keyframes[b] = new Oyster::Graphics::Model::Frame[A.Frames[b]];
//read bone index
int boneIndex;
ReadData(&boneIndex,danFile,4);
for(int f = 0; f < A.Frames[b]; ++f)
{
//write index of bone
A.Keyframes[b][f].bone.Parent = boneIndex;
//read bone transform
ReadData(&A.Keyframes[b][f].bone.Transform,danFile,sizeof(Oyster::Math::Matrix));
ReadData(&A.Keyframes[b][f].time,danFile,sizeof(double));
}
}
}
break; break;
} }
} }

View File

@ -11,12 +11,31 @@ namespace Oyster
{ {
namespace Model namespace Model
{ {
struct Bone
{
Math::Float4x4 Transform;
int Parent;
};
struct Frame
{
Bone bone;
double time;
};
struct Animation
{
std::wstring name;
int Bones;
int* Frames; //! Bone as index
Frame** Keyframes; //! @brief [Bone][Frame]
};
struct ModelInfo struct ModelInfo
{ {
std::vector<ID3D11ShaderResourceView*> Material; std::vector<ID3D11ShaderResourceView*> Material;
Core::Buffer *Vertices,*Indecies; Core::Buffer *Vertices,*Indecies,*Skeleton;
bool Indexed; bool Indexed;
int VertexCount, IndexCount; int VertexCount, IndexCount, BoneCount, AnimationCount;
Bone* bones;
Animation* Animations;
}; };
} }
} }

View File

@ -18,7 +18,7 @@ namespace Oyster
void Basic::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights) void Basic::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::Deffered::GBufferRTV,Resources::Deffered::GBufferSize,Math::Float4(1,0,0,1)); Preparations::Basic::ClearRTV(Resources::Deffered::GBufferRTV,Resources::Deffered::GBufferSize,Math::Float4(0,0,0,1));
Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Deffered::GeometryPass); Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Deffered::GeometryPass);
Definitions::VP vp; Definitions::VP vp;

View File

@ -12,7 +12,7 @@ const std::wstring PathToHLSL = L"..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\De
const std::wstring PathToCSO = L"..\\Content\\Shaders\\"; const std::wstring PathToCSO = L"..\\Content\\Shaders\\";
const int KernelSize = 10; const int KernelSize = 10;
const int SampleSpread = 8; const int SampleSpread = 16;
namespace Oyster namespace Oyster
{ {
@ -156,6 +156,7 @@ namespace Oyster
Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&PointLightView,NULL); Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&PointLightView,NULL);
srand((unsigned int)time(0)); srand((unsigned int)time(0));
//SSAO //SSAO
Math::Vector3 kernel[KernelSize]; Math::Vector3 kernel[KernelSize];
Math::Vector3 random[SampleSpread]; Math::Vector3 random[SampleSpread];
@ -186,13 +187,12 @@ namespace Oyster
{ {
random[i] = Oyster::Math::Vector3( random[i] = Oyster::Math::Vector3(
(float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1, (float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1,
(float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1, /*(float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1,*/
1.0f,
0.0f); 0.0f);
} }
random[i].Normalize(); random[i].Normalize();
} }
//kernel[0] = Math::Vector3(0,1,1);
//kernel[0].Normalize();
D3D11_TEXTURE1D_DESC T1desc; D3D11_TEXTURE1D_DESC T1desc;
T1desc.Width = KernelSize; T1desc.Width = KernelSize;
@ -208,17 +208,32 @@ namespace Oyster
D3D11_SUBRESOURCE_DATA rnd; D3D11_SUBRESOURCE_DATA rnd;
rnd.pSysMem = random; rnd.pSysMem = random;
rnd.SysMemPitch = sqrt(SampleSpread) * sizeof(Oyster::Math::Vector3);
ID3D11Texture1D *pTexture1[2]; ID3D11Texture1D *pTexture1;
Core::device->CreateTexture1D( &T1desc, &sphere, &pTexture1[0] ); Core::device->CreateTexture1D( &T1desc, &sphere, &pTexture1 );
Core::device->CreateShaderResourceView( pTexture1[0], 0, &SSAOKernel ); Core::device->CreateShaderResourceView( pTexture1, 0, &SSAOKernel );
pTexture1[0]->Release(); pTexture1->Release();
T1desc.Width = SampleSpread; D3D11_TEXTURE2D_DESC T2desc;
Core::device->CreateTexture1D( &T1desc, &rnd, &pTexture1[1] ); T2desc.Width = KernelSize;
Core::device->CreateShaderResourceView( (pTexture1[1]), 0, &SSAORandom ); T2desc.MipLevels = T2desc.ArraySize = 1;
pTexture1[1]->Release(); T2desc.Format = DXGI_FORMAT_R32G32B32_FLOAT;
T2desc.Usage = D3D11_USAGE_DEFAULT;
T2desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
T2desc.CPUAccessFlags = 0;
T2desc.MiscFlags = 0;
T2desc.Height = sqrt(SampleSpread);
T2desc.Width = SampleSpread/sqrt(SampleSpread);
T2desc.SampleDesc.Quality = 0;
T2desc.SampleDesc.Count = 1;
ID3D11Texture2D *pTexture2;
Core::device->CreateTexture2D( &T2desc, &rnd, &pTexture2 );
Core::device->CreateShaderResourceView( (pTexture2), 0, &SSAORandom );
pTexture2->Release();
////Create ShaderEffects ////Create ShaderEffects

View File

@ -18,12 +18,15 @@ namespace Oyster
static const int LBufferSize = 3; static const int LBufferSize = 3;
static const int MaxLightSize = 100; static const int MaxLightSize = 100;
//! GBuffers //! GBuffers
//! 0 = Diffuse + SpecKoeff //! 0 = Diffuse + Glow
//! 1 = Normal + Glow //! 1 = Normal + Spec
static ID3D11RenderTargetView* GBufferRTV[GBufferSize]; static ID3D11RenderTargetView* GBufferRTV[GBufferSize];
static ID3D11ShaderResourceView* GBufferSRV[GBufferSize]; static ID3D11ShaderResourceView* GBufferSRV[GBufferSize];
//! LBuffer
//! 0 = Diffuse
//! 1 = Specular
//! 2 = SSAO
static ID3D11UnorderedAccessView* LBufferUAV[LBufferSize]; static ID3D11UnorderedAccessView* LBufferUAV[LBufferSize];
static ID3D11ShaderResourceView* LBufferSRV[LBufferSize]; static ID3D11ShaderResourceView* LBufferSRV[LBufferSize];

View File

@ -32,10 +32,10 @@ Texture2D DepthTexture : register(t2);
StructuredBuffer<PointLight> Points : register(t3); StructuredBuffer<PointLight> Points : register(t3);
Texture1D SSAOKernel : register(t4); Texture1D SSAOKernel : register(t4);
Texture1D SSAORand : register(t5); Texture2D SSAORand : register(t5);
RWTexture2D<float4> Diffuse : register(u0); RWTexture2D<float4> Diffuse : register(u0);
RWTexture2D<float4> Specular : register(u1); RWTexture2D<float4> Specular : register(u1);
RWTexture2D<float> Ambient : register(u2); RWTexture2D<float4> Ambient : register(u2);
#endif #endif

View File

@ -31,10 +31,10 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID )
Specular[DTid.xy] = float4(Shaded.Specular, 1); Specular[DTid.xy] = float4(Shaded.Specular, 1);
if((DTid.x + DTid.y) %4 == 0 ) if(DTid.x & 1 && DTid.y & 1 )
{ {
float AmbValue = GetSSAO(ViewPos, UV, DTid.xy, GTid.xy); float AmbValue = GetSSAO(ViewPos, UV, DTid.xy, GTid.xy/2);
Ambient[DTid.xy/4] = AmbValue; Ambient[DTid.xy/2] = AmbValue;
} }
} }

View File

@ -7,6 +7,7 @@ RWTexture2D<float4> Output;
[numthreads(16, 16, 1)] [numthreads(16, 16, 1)]
void main( uint3 DTid : SV_DispatchThreadID ) void main( uint3 DTid : SV_DispatchThreadID )
{ {
//Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW //Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/2].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW
Output[DTid.xy] = Diffuse[DTid.xy]; Output[DTid.xy] = Ambient[DTid.xy/2];
//Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy];
} }

View File

@ -1,27 +1,30 @@
#include "Defines.hlsli" #include "Defines.hlsli"
#include "PosManipulation.hlsli" #include "PosManipulation.hlsli"
static float Radius =5; static float Radius = 100;
float GetSSAO(float3 pos, float2 uv, int2 texCoord2, uint2 rndID) float GetSSAO(float3 pos, float2 uv, int2 texCoord2, uint2 rndID)
{ {
float occlusion = 0.0f; float occlusion = 0.0f;
//create sample coordinate system //create sample coordinate system
float4 rnd = float4( SSAORand[(rndID.x + rndID.y) % SSAORand.Length.x].xyz, 0.0f ); float4 rnd = float4( SSAORand[int2(rndID.x % (SSAORand.Length.x), rndID.y % (SSAORand.Length.y))].xyz, 0.0f );
rnd = normalize(rnd); rnd = normalize(rnd);
float3 normal = NormalSpec[uv].xyz; float3 normal = NormalSpec[texCoord2].xyz;
float4 tangent = float4( normalize(rnd.xyz - (normal * dot(rnd.xyz, normal))), 0.0f ); float3 tangent = float3( normalize(rnd.xyz - (normal * dot(rnd.xyz, normal))));
float4 biTangent = float4( cross(tangent.xyz, normal), 0.0f ); float3 biTangent = float3( cross(tangent.xyz, normal));
float4x4 tbn = float4x4(tangent, biTangent, float4(normal,0), float4(pos*Radius,1)); float3x3 tbn = float3x3(tangent, biTangent, normal);
for( uint i = 0; i < SSAOKernel.Length.x; ++i ) for( uint i = 0; i < SSAOKernel.Length.x; ++i )
{ {
//int i = 0;
//take sample from localspace to viewspace //take sample from localspace to viewspace
float4 sampled = mul(tbn, float4(SSAOKernel[i].xyz,1));
float3 sampled = mul(tbn, SSAOKernel[i].xyz);
sampled = sampled * Radius + pos;
//project sample to get uv.xy //project sample to get uv.xy
float4 ProjOffset = sampled; float4 ProjOffset = float4(sampled,1);
ProjOffset = mul(Proj, ProjOffset); ProjOffset = mul(Proj, ProjOffset);
float4 offset = ProjOffset; float4 offset = ProjOffset;
float2 UV = offset; float2 UV = offset;
@ -39,7 +42,7 @@ float GetSSAO(float3 pos, float2 uv, int2 texCoord2, uint2 rndID)
//compare to depth from sample //compare to depth from sample
float rangeCheck = (abs(pos.z - sampleDepth) < Radius) ? 1.0f : 0.0f; float rangeCheck = (abs(pos.z - sampleDepth) < Radius) ? 1.0f : 0.0f;
occlusion += (sampleDepth >= sampled.z ? 1.0f : 0.0f) * rangeCheck; occlusion += (sampleDepth <= sampled.z ? 1.0f : 0.0f) * rangeCheck;
} }
occlusion /= (float)(SSAOKernel.Length.x); occlusion /= (float)(SSAOKernel.Length.x);
occlusion = 1.0f - occlusion; occlusion = 1.0f - occlusion;

View File

@ -121,7 +121,7 @@ HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow )
// Adjust and create window // Adjust and create window
g_hInst = hInstance; g_hInst = hInstance;
RECT rc = { 0, 0, 1024, 768 }; RECT rc = { 0, 0, 1280, 720 };
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE ); AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
if(!(g_hWnd = CreateWindow( if(!(g_hWnd = CreateWindow(
@ -159,25 +159,25 @@ HRESULT InitDirect3D()
return E_FAIL; return E_FAIL;
} }
m = Oyster::Graphics::API::CreateModel(L"cube_tri.dan"); m = Oyster::Graphics::API::CreateModel(L"untitled.dan");
m2 = Oyster::Graphics::API::CreateModel(L"cube_tri.dan"); m2 = Oyster::Graphics::API::CreateModel(L"knee_noAnimation.dan");
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null);
m3 = Oyster::Graphics::API::CreateModel(L"cube_tri.dan"); m3 = Oyster::Graphics::API::CreateModel(L"box_2.dan");
m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null); m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null);
P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,100); 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);
V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,15.4f)); V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,200,500.4f));
V = V.GetInverse(); V = V.GetInverse();
Oyster::Graphics::Definitions::Pointlight pl; Oyster::Graphics::Definitions::Pointlight pl;
pl.Color = Oyster::Math::Float3(1,1,1); pl.Color = Oyster::Math::Float3(1,1,1);
pl.Bright = 1; pl.Bright = 1;
pl.Pos = Oyster::Math::Float3(0,5,5.4f); pl.Pos = Oyster::Math::Float3(0,-20.0f,30.4f);
pl.Radius = 15; pl.Radius = 90;
Oyster::Graphics::API::AddLight(pl); Oyster::Graphics::API::AddLight(pl);
@ -188,9 +188,13 @@ float angle = 0;
HRESULT Update(float deltaTime) HRESULT Update(float deltaTime)
{ {
angle += Oyster::Math::pi/8 * deltaTime; angle += Oyster::Math::pi/16 * deltaTime;
m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle); m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle) * Oyster::Math3D::RotationMatrix_AxisX(-Oyster::Math::pi/2);
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-angle,Oyster::Math::Float3(0,-4,0),Oyster::Math::Float3::null); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-angle,Oyster::Math::Float3(0,-4,0),Oyster::Math::Float3::null);
//Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity;
//ma *= 5;
//ma.m44 = 1;
//m2->WorldMatrix = m2->WorldMatrix *ma;
m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-0,Oyster::Math::Float3(3,4,-1*angle),Oyster::Math::Float3::null); m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-0,Oyster::Math::Float3(3,4,-1*angle),Oyster::Math::Float3::null);
return S_OK; return S_OK;
} }