big refactor in shader - application interop

This commit is contained in:
Turanszki Janos
2017-10-15 20:16:36 +01:00
parent 5a341bdd48
commit d0ddcf87ac
19 changed files with 157 additions and 278 deletions
-24
View File
@@ -33,28 +33,4 @@
///////////////////////////
// Helpers:
///////////////////////////
// CPP:
/////////
#define CONSTANTBUFFER_BINDSLOT __ConstantBuffer_BindSlot__
// Add this to a struct to match that with a bind slot:
#define CB_SETBINDSLOT(slot) static const int CONSTANTBUFFER_BINDSLOT = (slot);
// Get bindslot from a struct which is matched with a bind slot:
#define CB_GETBINDSLOT(structname) structname::CONSTANTBUFFER_BINDSLOT
// Shader:
//////////
// Automatically binds constantbuffers on the shader side:
// Needs macro expansion
#define CBUFFER_X(name, slot) cbuffer name : register(b ## slot)
#define CBUFFER(name, slot) CBUFFER_X(name, slot)
#endif // _CONSTANTBUFFER_MAPPING_H_
-49
View File
@@ -75,53 +75,4 @@
#define SKINNINGSLOT_OUT_VERTEX_PRE 2
///////////////////////////
// Helpers:
///////////////////////////
// CPP:
/////////
#define STRUCTUREDBUFFER_BINDSLOT __StructuredBuffer_BindSlot__
// Add this to a struct to match that with a bind slot:
#define STRUCTUREDBUFFER_SETBINDSLOT(slot) static const int STRUCTUREDBUFFER_BINDSLOT = (slot);
// Get bindslot from a struct which is matched with a bind slot:
#define STRUCTUREDBUFFER_GETBINDSLOT(structname) structname::STRUCTUREDBUFFER_BINDSLOT
// Shader:
//////////
// Automatically binds resources on the shader side:
#define RAWBUFFER(name,slot) ByteAddressBuffer name : register(t ## slot)
#define RWRAWBUFFER(name,slot) RWByteAddressBuffer name : register(u ## slot)
#define TYPEDBUFFER(name, type, slot) Buffer< type > name : register(t ## slot)
#define RWTYPEDBUFFER(name, type, slot) RWBuffer< type > name : register(u ## slot)
#define STRUCTUREDBUFFER(name, type, slot) StructuredBuffer< type > name : register(t ## slot)
#define RWSTRUCTUREDBUFFER(name, type, slot) RWStructuredBuffer< type > name : register(u ## slot)
#define ROVSTRUCTUREDBUFFER(name, type, slot) RasterizerOrderedStructuredBuffer< type > name : register(u ## slot)
#define TEXTURE1D(name, type, slot) Texture1D< type > name : register(t ## slot);
#define TEXTURE1DARRAY(name, type, slot) Texture1DArray< type > name : register(t ## slot);
#define RWTEXTURE1D(name, type, slot) RWTexture1D< type > name : register(u ## slot);
#define TEXTURE2D(name, type, slot) Texture2D< type > name : register(t ## slot);
#define TEXTURE2DMS(name, type, slot) Texture2DMS< type > name : register(t ## slot);
#define TEXTURE2DARRAY(name, type, slot) Texture2DArray< type > name : register(t ## slot);
#define RWTEXTURE2D(name, type, slot) RWTexture2D< type > name : register(u ## slot);
#define ROVTEXTURE2D(name, type, slot) RasterizerOrderedTexture2D< type > name : register(u ## slot);
#define TEXTURECUBE(name, type, slot) TextureCube< type > name : register(t ## slot);
#define TEXTURECUBEARRAY(name, type, slot) TextureCubeArray< type > name : register(t ## slot);
#define TEXTURE3D(name, type, slot) Texture3D< type > name : register(t ## slot);
#define RWTEXTURE3D(name, type, slot) RWTexture3D< type > name : register(u ## slot);
#define ROVTEXTURE3D(name, type, slot) RasterizerOrderedTexture3D< type > name : register(u ## slot);
#endif // _RESOURCEBUFFER_MAPPING_H_
-12
View File
@@ -30,16 +30,4 @@
#define SSLOT_COUNT (SSLOT_COUNT_PERSISTENT + SSLOT_COUNT_ONDEMAND)
///////////////////////////
// Helpers:
///////////////////////////
// Shader:
//////////
// Automatically binds samplers on the shader side:
// Needs macro expansion
#define SAMPLERSTATE(name, slot) SamplerState name : register(s ## slot);
#define SAMPLERCOMPARISONSTATE(name, slot) SamplerComparisonState name : register(s ## slot);
#endif // _SAMPLER_MAPPING_H_
+92
View File
@@ -1,6 +1,98 @@
#ifndef _WICKEDENGINE_SHADERINTEROP_H_
#define _WICKEDENGINE_SHADERINTEROP_H_
#include "ConstantBufferMapping.h"
#include "SamplerMapping.h"
#include "ResourceMapping.h"
#ifdef __cplusplus
// Application-side types:
#define matrix XMMATRIX
#define float4x4 XMFLOAT4X4
#define float2 XMFLOAT2
#define float3 XMFLOAT3
#define float4 XMFLOAT4
#define uint uint32_t
#define uint2 XMUINT2
#define uint3 XMUINT3
#define uint4 XMUINT4
#define CB_GETBINDSLOT(name) __CBUFFERBINDSLOT__##name##__
#define CBUFFER(name, slot) static const int CB_GETBINDSLOT(name) = slot; struct alignas(16) name
#else
// Shader - side types:
#define CBUFFER(name, slot) cbuffer name : register(b ## slot)
#define RAWBUFFER(name,slot) ByteAddressBuffer name : register(t ## slot)
#define RWRAWBUFFER(name,slot) RWByteAddressBuffer name : register(u ## slot)
#define TYPEDBUFFER(name, type, slot) Buffer< type > name : register(t ## slot)
#define RWTYPEDBUFFER(name, type, slot) RWBuffer< type > name : register(u ## slot)
#define STRUCTUREDBUFFER(name, type, slot) StructuredBuffer< type > name : register(t ## slot)
#define RWSTRUCTUREDBUFFER(name, type, slot) RWStructuredBuffer< type > name : register(u ## slot)
#define ROVSTRUCTUREDBUFFER(name, type, slot) RasterizerOrderedStructuredBuffer< type > name : register(u ## slot)
#define TEXTURE1D(name, type, slot) Texture1D< type > name : register(t ## slot);
#define TEXTURE1DARRAY(name, type, slot) Texture1DArray< type > name : register(t ## slot);
#define RWTEXTURE1D(name, type, slot) RWTexture1D< type > name : register(u ## slot);
#define TEXTURE2D(name, type, slot) Texture2D< type > name : register(t ## slot);
#define TEXTURE2DMS(name, type, slot) Texture2DMS< type > name : register(t ## slot);
#define TEXTURE2DARRAY(name, type, slot) Texture2DArray< type > name : register(t ## slot);
#define RWTEXTURE2D(name, type, slot) RWTexture2D< type > name : register(u ## slot);
#define ROVTEXTURE2D(name, type, slot) RasterizerOrderedTexture2D< type > name : register(u ## slot);
#define TEXTURECUBE(name, type, slot) TextureCube< type > name : register(t ## slot);
#define TEXTURECUBEARRAY(name, type, slot) TextureCubeArray< type > name : register(t ## slot);
#define TEXTURE3D(name, type, slot) Texture3D< type > name : register(t ## slot);
#define RWTEXTURE3D(name, type, slot) RWTexture3D< type > name : register(u ## slot);
#define ROVTEXTURE3D(name, type, slot) RasterizerOrderedTexture3D< type > name : register(u ## slot);
#define SAMPLERSTATE(name, slot) SamplerState name : register(s ## slot);
#define SAMPLERCOMPARISONSTATE(name, slot) SamplerComparisonState name : register(s ## slot);
#endif // __cplusplus
struct LightArrayType
{
float3 positionVS; // View Space!
float range;
// --
float4 color;
// --
float3 positionWS;
float energy;
// --
float3 directionVS;
float shadowKernel;
// --
float3 directionWS;
uint type;
// --
float shadowBias;
int shadowMap_index;
float coneAngle;
float coneAngleCos;
// --
float4 texMulAdd;
// --
matrix shadowMatrix[3];
};
// Tiled rendering params:
#define TILED_CULLING_BLOCKSIZE 16
#define MAX_LIGHTS 1024
-3
View File
@@ -1,9 +1,6 @@
#ifndef _SHADER_GLOBALS_
#define _SHADER_GLOBALS_
#include "ShaderInterop.h"
#include "ConstantBufferMapping.h"
#include "SamplerMapping.h"
#include "ResourceMapping.h"
TEXTURE2D(texture_depth, float, TEXSLOT_DEPTH)
TEXTURE2D(texture_lineardepth, float, TEXSLOT_LINEARDEPTH)
+1 -1
View File
@@ -356,7 +356,7 @@ void main(ComputeShaderInput IN)
// frustum AABB in world space transformed into the space of the probe/decal OBB:
AABB b = GroupAABB_WS;
b.transform(light.shadowMat[0]); // shadowMat[0] : decal inverse box matrix!
b.transform(light.shadowMatrix[0]); // shadowMatrix[0] : decal inverse box matrix!
if (IntersectAABB(a, b))
{
+4 -30
View File
@@ -4,32 +4,6 @@
#include "brdf.hlsli"
#include "voxelConeTracingHF.hlsli"
struct LightArrayType
{
float3 positionVS; // View Space!
float range;
// --
float4 color;
// --
float3 positionWS;
float energy;
// --
float3 directionVS;
float shadowKernel;
// --
float3 directionWS;
uint type;
// --
float shadowBias;
int shadowMap_index;
float coneAngle;
float coneAngleCos;
// --
float4 texMulAdd;
// --
float4x4 shadowMat[3];
};
TEXTURE2D(LightGrid, uint2, TEXSLOT_LIGHTGRID);
STRUCTUREDBUFFER(LightIndexList, uint, SBSLOT_LIGHTINDEXLIST);
STRUCTUREDBUFFER(LightArray, LightArrayType, SBSLOT_LIGHTARRAY);
@@ -90,9 +64,9 @@ inline LightingResult DirectionalLight(in LightArrayType light, in float3 N, in
{
// calculate shadow map texcoords:
float4 ShPos[3];
ShPos[0] = mul(float4(P, 1), light.shadowMat[0]);
ShPos[1] = mul(float4(P, 1), light.shadowMat[1]);
ShPos[2] = mul(float4(P, 1), light.shadowMat[2]);
ShPos[0] = mul(float4(P, 1), light.shadowMatrix[0]);
ShPos[1] = mul(float4(P, 1), light.shadowMatrix[1]);
ShPos[2] = mul(float4(P, 1), light.shadowMatrix[2]);
ShPos[0].xyz /= ShPos[0].w;
ShPos[1].xyz /= ShPos[1].w;
ShPos[2].xyz /= ShPos[2].w;
@@ -212,7 +186,7 @@ inline LightingResult SpotLight(in LightArrayType light, in float3 N, in float3
[branch]
if (light.shadowMap_index >= 0)
{
float4 ShPos = mul(float4(P, 1), light.shadowMat[0]);
float4 ShPos = mul(float4(P, 1), light.shadowMatrix[0]);
ShPos.xyz /= ShPos.w;
float2 ShTex = ShPos.xy * float2(0.5f, -0.5f) + float2(0.5f, 0.5f);
[branch]
+1 -1
View File
@@ -189,7 +189,7 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
{
LightArrayType decal = LightArray[LightIndexList[startOffset + iterator]];
float4x4 decalProjection = decal.shadowMat[0];
float4x4 decalProjection = decal.shadowMatrix[0];
float3 clipSpace = mul(float4(P, 1), decalProjection).xyz;
float3 uvw = clipSpace.xyz*float3(0.5f, -0.5f, 0.5f) + 0.5f;
[branch]
+2 -2
View File
@@ -41,7 +41,7 @@ void main(float4 pos : SV_POSITION, float3 N : NORMAL, float2 tex : TEXCOORD, fl
[branch]
if (light.shadowMap_index >= 0)
{
float4 ShPos = mul(float4(P, 1), light.shadowMat[0]);
float4 ShPos = mul(float4(P, 1), light.shadowMatrix[0]);
ShPos.xyz /= ShPos.w;
float3 ShTex = ShPos.xyz*float3(1, -1, 1) / 2.0f + 0.5f;
@@ -103,7 +103,7 @@ void main(float4 pos : SV_POSITION, float3 N : NORMAL, float2 tex : TEXCOORD, fl
[branch]
if (light.shadowMap_index >= 0)
{
float4 ShPos = mul(float4(P, 1), light.shadowMat[0]);
float4 ShPos = mul(float4(P, 1), light.shadowMatrix[0]);
ShPos.xyz /= ShPos.w;
float2 ShTex = ShPos.xy * float2(0.5f, -0.5f) + float2(0.5f, 0.5f);
[branch]
+2 -6
View File
@@ -1,6 +1,6 @@
#pragma once
#include "wiParticle.h"
#include "ConstantBufferMapping.h"
#include "ShaderInterop.h"
#include "wiIntersectables.h"
#include <set>
@@ -45,15 +45,11 @@ private:
};
std::deque<Point> points;
GFX_STRUCT ConstantBuffer
CBUFFER(ConstantBuffer, CBSLOT_OTHER_EMITTEDPARTICLE)
{
XMFLOAT2 mAdd;
float mMotionBlurAmount;
float padding;
CB_SETBINDSLOT(CBSLOT_OTHER_EMITTEDPARTICLE)
ALIGN_16
};
wiGraphicsTypes::GPUBuffer *vertexBuffer;
static wiGraphicsTypes::VertexLayout *vertexLayout;
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once
#include "CommonInclude.h"
#include "wiGraphicsAPI.h"
#include "ConstantBufferMapping.h"
#include "ShaderInterop.h"
#include "wiColor.h"
+2 -8
View File
@@ -19,7 +19,7 @@ public:
UINT tangent;
};
private:
GFX_STRUCT ConstantBuffer
CBUFFER(ConstantBuffer, CBSLOT_OTHER_HAIRPARTICLE)
{
XMMATRIX mWorld;
XMFLOAT3 color; float __pad0;
@@ -27,19 +27,13 @@ private:
float LOD1;
float LOD2;
float __pad1;
CB_SETBINDSLOT(CBSLOT_OTHER_HAIRPARTICLE)
ALIGN_16
};
GFX_STRUCT BitonicSortConstantBuffer
CBUFFER(BitonicSortConstantBuffer, 0)
{
UINT iLevel;
UINT iLevelMask;
UINT iWidth;
UINT iHeight;
ALIGN_16
};
static wiGraphicsTypes::VertexLayout *il;
static wiGraphicsTypes::VertexShader *vs;
+3 -11
View File
@@ -1,7 +1,7 @@
#pragma once
#include "CommonInclude.h"
#include "wiGraphicsAPI.h"
#include "ConstantBufferMapping.h"
#include "ShaderInterop.h"
class wiImageEffects;
enum BLENDMODE;
@@ -11,7 +11,7 @@ class wiImage
private:
//static mutex MUTEX;
protected:
GFX_STRUCT ImageCB
CBUFFER(ImageCB, CBSLOT_IMAGE_IMAGE)
{
XMMATRIX mTransform;
XMFLOAT4 mTexMulAdd;
@@ -28,19 +28,11 @@ protected:
float pad0;
float pad1;
float pad2;
CB_SETBINDSLOT(CBSLOT_IMAGE_IMAGE)
ALIGN_16
};
GFX_STRUCT PostProcessCB
CBUFFER(PostProcessCB, CBSLOT_IMAGE_POSTPROCESS)
{
float params0[4];
float params1[4];
CB_SETBINDSLOT(CBSLOT_IMAGE_POSTPROCESS)
ALIGN_16
};
static wiGraphicsTypes::BlendState *blendState, *blendStateAdd, *blendStateNoBlend, *blendStateAvg, *blendStateDisable;
+2 -6
View File
@@ -2,7 +2,7 @@
#define LENSFLARE
#include "CommonInclude.h"
#include "wiGraphicsAPI.h"
#include "ConstantBufferMapping.h"
#include "ShaderInterop.h"
class wiLensFlare
{
@@ -16,14 +16,10 @@ private:
static wiGraphicsTypes::DepthStencilState *depthStencilState;
static wiGraphicsTypes::BlendState *blendState;
GFX_STRUCT ConstantBuffer
CBUFFER(ConstantBuffer, CBSLOT_OTHER_LENSFLARE)
{
XMVECTOR mSunPos;
XMFLOAT4 mScreen;
CB_SETBINDSLOT(CBSLOT_OTHER_LENSFLARE)
ALIGN_16
};
public:
+1 -1
View File
@@ -1595,7 +1595,7 @@ void Material::CreateImpostorMaterialCB()
}
}
void Material::MaterialCB::Create(const Material& mat)
void MaterialCB::Create(const Material& mat)
{
baseColor = XMFLOAT4(mat.baseColor.x, mat.baseColor.y, mat.baseColor.z, mat.alpha);
texMulAdd = mat.texMulAdd;
+17 -25
View File
@@ -8,8 +8,6 @@
#include "wiFrustum.h"
#include "wiTransform.h"
#include "wiIntersectables.h"
#include "ConstantBufferMapping.h"
#include "ResourceMapping.h"
#include "ShaderInterop.h"
#include <vector>
@@ -82,6 +80,23 @@ GFX_STRUCT InstancePrev
ALIGN_16
};
CBUFFER(MaterialCB, CBSLOT_RENDERER_MATERIAL)
{
XMFLOAT4 baseColor; // + alpha (.w)
XMFLOAT4 texMulAdd;
float roughness;
float reflectance;
float metalness;
float emissive;
float refractionIndex;
float subsurfaceScattering;
float normalMapStrength;
float parallaxOcclusionMapping;
MaterialCB() {};
MaterialCB(const Material& mat) { Create(mat); };
void Create(const Material& mat);
};
struct Material
{
std::string name;
@@ -104,27 +119,6 @@ struct Material
std::string specularMapName;
wiGraphicsTypes::Texture2D* specularMap;
GFX_STRUCT MaterialCB
{
XMFLOAT4 baseColor; // + alpha (.w)
XMFLOAT4 texMulAdd;
float roughness;
float reflectance;
float metalness;
float emissive;
float refractionIndex;
float subsurfaceScattering;
float normalMapStrength;
float parallaxOcclusionMapping;
CB_SETBINDSLOT(CBSLOT_RENDERER_MATERIAL)
MaterialCB() {};
MaterialCB(const Material& mat) { Create(mat); };
void Create(const Material& mat);
ALIGN_16
};
MaterialCB gpuData;
wiGraphicsTypes::GPUBuffer constantBuffer;
static wiGraphicsTypes::GPUBuffer* constantBuffer_Impostor;
@@ -729,8 +723,6 @@ public:
pose2 = XMFLOAT4A(matIn._13, matIn._23, matIn._33, matIn._43);
}
STRUCTUREDBUFFER_SETBINDSLOT(SKINNINGSLOT_IN_BONEBUFFER)
ALIGN_16
};
std::vector<ShaderBoneType> boneData;
+17 -19
View File
@@ -1,5 +1,4 @@
#include "wiRenderer.h"
#include "ShaderInterop.h"
#include "wiFrameRate.h"
#include "wiHairParticle.h"
#include "wiEmittedParticle.h"
@@ -20,7 +19,6 @@
#include "wiEnums.h"
#include "wiRandom.h"
#include "wiFont.h"
#include "ResourceMapping.h"
#include "wiGraphicsDevice_DX11.h"
#include "wiTranslator.h"
#include "wiRectPacker.h"
@@ -1430,8 +1428,8 @@ void wiRenderer::BindPersistentState(GRAPHICSTHREAD threadID)
GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID);
GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID);
GetDevice()->BindResourcePS(resourceBuffers[RBTYPE_LIGHTARRAY], STRUCTUREDBUFFER_GETBINDSLOT(LightArrayType), threadID);
GetDevice()->BindResourceCS(resourceBuffers[RBTYPE_LIGHTARRAY], STRUCTUREDBUFFER_GETBINDSLOT(LightArrayType), threadID);
GetDevice()->BindResourcePS(resourceBuffers[RBTYPE_LIGHTARRAY], SBSLOT_LIGHTARRAY, threadID);
GetDevice()->BindResourceCS(resourceBuffers[RBTYPE_LIGHTARRAY], SBSLOT_LIGHTARRAY, threadID);
}
Transform* wiRenderer::getTransformByName(const std::string& get)
@@ -1839,13 +1837,13 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID)
for (Model* model : GetScene().models)
{
// Update material constant buffers:
Material::MaterialCB materialGPUData;
MaterialCB materialGPUData;
for (auto& it : model->materials)
{
Material* material = it.second;
materialGPUData.Create(*material);
// These will probably not change every time so only issue a GPU memory update if it is necessary:
if (memcmp(&material->gpuData, &materialGPUData, sizeof(Material::MaterialCB)) != 0)
if (memcmp(&material->gpuData, &materialGPUData, sizeof(MaterialCB)) != 0)
{
material->gpuData = materialGPUData;
GetDevice()->UpdateBuffer(&material->constantBuffer, &materialGPUData, threadID);
@@ -1883,7 +1881,7 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID)
armature->boneData[k].Create(armature->boneCollection[k]->boneRelativity);
}
GetDevice()->UpdateBuffer(&armature->boneBuffer, armature->boneData.data(), threadID, (int)(sizeof(Armature::ShaderBoneType) * armature->boneCollection.size()));
GetDevice()->BindResourceCS(&armature->boneBuffer, STRUCTUREDBUFFER_GETBINDSLOT(Armature::ShaderBoneType), threadID);
GetDevice()->BindResourceCS(&armature->boneBuffer, SKINNINGSLOT_IN_BONEBUFFER, threadID);
// Do the skinning
const GPUResource* vbs[] = {
@@ -1969,10 +1967,10 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID)
continue;
}
lightArray[lightCounter].posWS = l->translation;
XMStoreFloat3(&lightArray[lightCounter].posVS, XMVector3TransformCoord(XMLoadFloat3(&lightArray[lightCounter].posWS), viewMatrix));
lightArray[lightCounter].distance = l->enerDis.y;
lightArray[lightCounter].col = l->color;
lightArray[lightCounter].positionWS = l->translation;
XMStoreFloat3(&lightArray[lightCounter].positionVS, XMVector3TransformCoord(XMLoadFloat3(&lightArray[lightCounter].positionWS), viewMatrix));
lightArray[lightCounter].range = l->enerDis.y;
lightArray[lightCounter].color = l->color;
lightArray[lightCounter].energy = l->enerDis.x;
lightArray[lightCounter].type = l->GetType();
lightArray[lightCounter].shadowBias = l->shadowBias;
@@ -2014,7 +2012,7 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID)
XMMATRIX lightMat = XMLoadFloat4x4(&l->world);
XMStoreFloat3(&lightArray[lightCounter].directionWS, XMVector3TransformNormal(XMVectorSet(-1, 0, 0, 0), lightMat)); // left dir
XMStoreFloat3(&lightArray[lightCounter].directionVS, XMVector3TransformNormal(XMVectorSet(0, 1, 0, 0), lightMat)); // up dir
XMStoreFloat3(&lightArray[lightCounter].posVS, XMVector3TransformNormal(XMVectorSet(0, 0, -1, 0), lightMat)); // front dir
XMStoreFloat3(&lightArray[lightCounter].positionVS, XMVector3TransformNormal(XMVectorSet(0, 0, -1, 0), lightMat)); // front dir
lightArray[lightCounter].texMulAdd = XMFLOAT4(l->radius, l->width, l->height, 0);
}
break;
@@ -2030,12 +2028,12 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID)
lightCounter--;
break;
}
lightArray[lightCounter].posWS = decal->translation;
XMStoreFloat3(&lightArray[lightCounter].posVS, XMVector3TransformCoord(XMLoadFloat3(&decal->translation), viewMatrix));
lightArray[lightCounter].distance = max(decal->scale.x, max(decal->scale.y, decal->scale.z)) * 2;
lightArray[lightCounter].positionWS = decal->translation;
XMStoreFloat3(&lightArray[lightCounter].positionVS, XMVector3TransformCoord(XMLoadFloat3(&decal->translation), viewMatrix));
lightArray[lightCounter].range = max(decal->scale.x, max(decal->scale.y, decal->scale.z)) * 2;
lightArray[lightCounter].shadowMatrix[0] = XMMatrixTranspose(XMMatrixInverse(nullptr, XMLoadFloat4x4(&decal->world)));
lightArray[lightCounter].texMulAdd = decal->atlasMulAdd;
lightArray[lightCounter].col = XMFLOAT4(decal->color.x, decal->color.y, decal->color.z, decal->GetOpacity());
lightArray[lightCounter].color = XMFLOAT4(decal->color.x, decal->color.y, decal->color.z, decal->GetOpacity());
lightArray[lightCounter].energy = decal->emissive;
lightArray[lightCounter].type = 100;
@@ -3967,7 +3965,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
{
// Bind the static impostor params once:
impostorRenderSetup = true;
device->BindConstantBufferPS(Material::constantBuffer_Impostor, CB_GETBINDSLOT(Material::MaterialCB), threadID);
device->BindConstantBufferPS(Material::constantBuffer_Impostor, CB_GETBINDSLOT(MaterialCB), threadID);
device->BindPrimitiveTopology(TRIANGLELIST, threadID);
device->BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_FRONT], threadID);
device->BindVertexLayout(vertexLayouts[realVL], threadID);
@@ -4314,7 +4312,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
boundVBType_Prev = boundVBType;
device->BindIndexBuffer(&subset.indexBuffer, subset.GetIndexFormat(), threadID);
device->BindConstantBufferPS(&material->constantBuffer, CB_GETBINDSLOT(Material::MaterialCB), threadID);
device->BindConstantBufferPS(&material->constantBuffer, CB_GETBINDSLOT(MaterialCB), threadID);
UINT realStencilRef = material->GetStencilRef();
// todo: better
@@ -6161,7 +6159,7 @@ void wiRenderer::CreateImpostor(Mesh* mesh)
{
GetDevice()->BindIndexBuffer(&subset.indexBuffer, subset.GetIndexFormat(), threadID);
GetDevice()->BindConstantBufferPS(&subset.material->constantBuffer, CB_GETBINDSLOT(Material::MaterialCB), threadID);
GetDevice()->BindConstantBufferPS(&subset.material->constantBuffer, CB_GETBINDSLOT(MaterialCB), threadID);
GetDevice()->BindResourcePS(subset.material->GetBaseColorMap(), TEXSLOT_ONDEMAND0, threadID);
GetDevice()->BindResourcePS(subset.material->GetNormalMap(), TEXSLOT_ONDEMAND1, threadID);
+11 -78
View File
@@ -1,10 +1,8 @@
#pragma once
#include "CommonInclude.h"
#include "ShaderInterop.h"
#include "wiEnums.h"
#include "wiGraphicsAPI.h"
#include "SamplerMapping.h"
#include "ConstantBufferMapping.h"
#include "ResourceMapping.h"
#include "wiSPTree.h"
#include "wiWindowRegistration.h"
@@ -90,7 +88,7 @@ public:
// Constant Buffers:
// Persistent buffers:
GFX_STRUCT WorldCB
CBUFFER(WorldCB, CBSLOT_RENDERER_WORLD)
{
XMFLOAT2 mScreenWidthHeight;
XMFLOAT2 mInternalResolution;
@@ -106,12 +104,8 @@ public:
float mVoxelRadianceDataFalloff;
XMFLOAT3 mVoxelRadianceDataCenter;
BOOL mAdvancedRefractions;
CB_SETBINDSLOT(CBSLOT_RENDERER_WORLD)
ALIGN_16
};
GFX_STRUCT FrameCB
CBUFFER(FrameCB, CBSLOT_RENDERER_FRAME)
{
float mTime;
float mTimePrev;
@@ -143,118 +137,57 @@ public:
XMFLOAT3 mUp;
float mZFarP;
XMFLOAT4 mFrustumPlanesWS[6];
CB_SETBINDSLOT(CBSLOT_RENDERER_FRAME)
ALIGN_16
};
GFX_STRUCT CameraCB
CBUFFER(CameraCB, CBSLOT_RENDERER_CAMERA)
{
XMMATRIX mVP;
XMMATRIX mView;
XMMATRIX mProj;
XMFLOAT3 mCamPos; float pad0;
CB_SETBINDSLOT(CBSLOT_RENDERER_CAMERA)
ALIGN_16
};
GFX_STRUCT MiscCB
CBUFFER(MiscCB, CBSLOT_RENDERER_MISC)
{
XMMATRIX mTransform;
XMFLOAT4 mColor;
CB_SETBINDSLOT(CBSLOT_RENDERER_MISC)
ALIGN_16
};
// On demand buffers:
GFX_STRUCT VolumeLightCB
CBUFFER(VolumeLightCB, CBSLOT_RENDERER_VOLUMELIGHT)
{
XMMATRIX world;
XMFLOAT4 col;
XMFLOAT4 enerdis;
CB_SETBINDSLOT(CBSLOT_RENDERER_VOLUMELIGHT)
ALIGN_16
};
GFX_STRUCT DecalCB
CBUFFER(DecalCB, CBSLOT_RENDERER_DECAL)
{
XMMATRIX mDecalVP;
int hasTexNor;
XMFLOAT3 eye;
float opacity;
XMFLOAT3 front;
CB_SETBINDSLOT(CBSLOT_RENDERER_DECAL)
ALIGN_16
};
GFX_STRUCT CubeMapRenderCB
CBUFFER(CubeMapRenderCB, CBSLOT_RENDERER_CUBEMAPRENDER)
{
XMMATRIX mViewProjection[6];
CB_SETBINDSLOT(CBSLOT_RENDERER_CUBEMAPRENDER)
ALIGN_16
};
GFX_STRUCT APICB
CBUFFER(APICB, CBSLOT_API)
{
XMFLOAT4 clipPlane;
float alphaRef;
float pad[3];
APICB(const XMFLOAT4& clipPlane = XMFLOAT4(0, 0, 0, 0), float alphaRef = 0.75f) :clipPlane(clipPlane), alphaRef(alphaRef) {}
CB_SETBINDSLOT(CBSLOT_API)
ALIGN_16
};
GFX_STRUCT TessellationCB
CBUFFER(TessellationCB, CBSLOT_RENDERER_TESSELLATION)
{
XMFLOAT4 tessellationFactors;
CB_SETBINDSLOT(CBSLOT_RENDERER_TESSELLATION)
ALIGN_16
};
GFX_STRUCT DispatchParamsCB
CBUFFER(DispatchParamsCB, CBSLOT_RENDERER_DISPATCHPARAMS)
{
UINT numThreadGroups[3];
UINT value0;
UINT numThreads[3];
UINT value1;
CB_SETBINDSLOT(CBSLOT_RENDERER_DISPATCHPARAMS)
ALIGN_16
};
// Resource Buffers:
GFX_STRUCT LightArrayType
{
XMFLOAT3 posVS;
float distance;
XMFLOAT4 col;
XMFLOAT3 posWS;
float energy;
XMFLOAT3 directionVS;
float shadowKernel;
XMFLOAT3 directionWS;
UINT type;
float shadowBias;
int shadowMap_index;
float coneAngle;
float coneAngleCos;
XMFLOAT4 texMulAdd;
XMMATRIX shadowMatrix[3];
STRUCTUREDBUFFER_SETBINDSLOT(SBSLOT_LIGHTARRAY)
ALIGN_16
};
protected:
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 13;
// minor bug fixes, alterations, refactors, updates
const int revision = 30;
const int revision = 31;
long GetVersion()