Commit 16d0b6b1 authored by D-AIRY's avatar D-AIRY

New material system (finish?); some minor bugfixes

parent 92852964
[sky_hdr_hl2]
shader = Sky
tex.txBase = sky_hdr_hl2.dds
/*
skybox.vs
Скайбокс
*/
#include "../struct.h"
#include "../const.h"
//##########################################################################
VSO_SkyBox main(VSI_SkyBox IN)
{
VSO_SkyBox OUT = (VSO_SkyBox)0;
OUT.vPosition = mul(half4(IN.vPosition + g_vPosCam.xyz, 1.f), g_mVP);
OUT.vTexUV = IN.vTexUV;
return OUT;
}
......@@ -39,7 +39,7 @@ cbuffer CDataMaterial: register(b0)
#ifdef XMATERIAL_HAS_CONSTANTS
cbuffer XMaterialConstants: register(b6)
cbuffer XMaterialConstants: register(b7)
{
struct
{
......
#ifdef COMPILE_MainGBuffer
XMaterial MainGBuffer(PSI_XMaterial IN)
{
XMaterial OUT = XMATERIAL_LOAD_DEFAULTS();
float4 fColor = g_txBase.Sample(g_sScene, IN.vTexUV);
// float4 fColor = IN.vPos;
#ifdef HAS_ALPHATEST
clip(fColor.a - g_xMaterialConstants.pbr_alphatest_threshold);
#endif
OUT.vBaseColor = fColor.xyz;
OUT.vBaseColor = fColor.xyz/* * g_xMaterialConstants.vColor.xyz*/;
#ifdef HAS_PARAMMAP
float4 vParams = g_txParameters.Sample(g_sScene, IN.vTexUV);
......@@ -39,22 +40,54 @@ XMaterial MainGBuffer(PSI_XMaterial IN)
return(OUT);
}
#endif
#ifdef COMPILE_MainIllimination
XMaterial MainIllimination(PSI_XMaterial IN)
{
XMaterial OUT = XMATERIAL_LOAD_DEFAULTS();
float4 fColor = g_txBase.Sample(g_sScene, IN.vTexUV);
// float4 fColor = IN.vPos;
#ifdef HAS_ALPHATEST
clip(fColor.a - g_xMaterialConstants.pbr_alphatest_threshold);
#endif
OUT.vEmissiveColor = fColor.xyz;
#ifdef HAS_NORMALMAP
OUT.vNormal = MixNormalMicro(IN.vNormal,
Color2Normal(g_txNormals.Sample(g_sScene, IN.vTexUV).xyz) * g_xMaterialConstants.nm_weight
);
#else
OUT.vNormal = IN.vNormal;
#endif
return(OUT);
}
#endif
#ifdef COMPILE_MainShadow
XMaterial MainShadow(PSI_XMaterial IN)
{
XMaterial OUT = XMATERIAL_LOAD_DEFAULTS();
float4 fColor = g_txBase.Sample(g_sScene, IN.vTexUV);
// float4 fColor = IN.vPos;
#ifdef HAS_ALPHATEST
clip(fColor.a - g_xMaterialConstants.pbr_alphatest_threshold);
#endif
OUT.vBaseColor = fColor;
// #ifdef HAS_NORMALMAP
// OUT.vNormal = MixNormalMicro(IN.vNormal,
// Color2Normal(g_txNormals.Sample(g_sScene, IN.vTexUV).xyz) * g_xMaterialConstants.nm_weight
// );
// #else
OUT.vNormal = IN.vNormal;
// #endif
return(OUT);
}
#endif
XMaterial MainPostprocess(PSI_XMaterial IN)
{
XMaterial OUT = XMATERIAL_LOAD_DEFAULTS();
XMaterial OUT = XMATERIAL_LOAD_DEFAULTS(IN);
......
#ifdef COMPILE_MainGBuffer
XMaterial MainGBuffer(PSI_XMaterial IN)
{
XMaterial OUT = XMATERIAL_LOAD_DEFAULTS();
float4 vColor = g_txBase.Sample(g_sScene, IN.vTexUV);
// float4 vColor = g_txCurrent.Sample(g_sScene, IN.vTexUV);
vColor.xyz *= vColor.w * 25.0f;
vColor.w = 1.0f;
OUT.vBaseColor = vColor.xyz;
OUT.fLightCoeff = 0.0f;
OUT.vNormal = -IN.vTexUV;
OUT.fDepth = g_vNearFarInvWinSize.y - g_vNearFarInvWinSize.x;
return(OUT);
}
#endif
#ifdef COMPILE_MainIllimination
XMaterial MainIllimination(PSI_XMaterial IN)
{
XMaterial OUT = XMATERIAL_LOAD_DEFAULTS();
float4 fColor = g_txBase.Sample(g_sScene, IN.vTexUV);
OUT.vEmissiveColor = fColor.xyz;
return(OUT);
}
#endif
#ifdef COMPILE_MainTransparency
XMaterial MainTransparency(PSI_XMaterial IN)
{
XMaterial OUT = XMATERIAL_LOAD_DEFAULTS();
float4 vColor = g_txBase.Sample(g_sScene, IN.vTexUV);
// float4 fColor = IN.vPos;
#ifdef HAS_ALPHATEST
clip(vColor.a - g_xMaterialConstants.pbr_alphatest_threshold);
#endif
#ifdef HAS_NORMALMAP
float3 vNormal = Color2Normal(g_txNormals.Sample(g_sScene, IN.vTexUV).xyz) * g_xMaterialConstants.nm_weight;
OUT.vNormal = MixNormalMicro(IN.vNormal, vNormal);
// float2 vDuDv = vNormal.xy;
#ifdef HAS_REFRACTION
// float2 vDuDv = OUT.vNormal.xy;
// float2 vDuDv = g_txNormals.Sample(g_sScene, IN.vTexUV).xy;
float3 vPos = IN.vPos.xyz / IN.vPos.w;
// vDuDv = float2(0.3,0.3);
float2 vSceneUV = (vPos.xy * float2(1.0, -1.0) + g_vNearFarInvWinSize.zw * 0.5) * 0.5 + 0.5;
float2 vSceneUVrefract = vSceneUV + vNormal.xy; // (vDuDv - 0.5) * 0.3; // 0.035
float3 vSceneColor;
if(g_txGBufferD1.Sample(g_sPointClamp, vSceneUVrefract).x < ComDepthByPos(IN.vPos, g_vNearFarInvWinSize.xy))
{
vSceneUVrefract = vSceneUV;
}
vSceneColor = g_txScene.Sample(g_sPointClamp, vSceneUVrefract).xyz;
// vSceneColor = float3(0,1,0);
vColor = float4(float3(vSceneColor * (1.0 - vColor.w) + vColor.xyz * vColor.w), 1.0);
#endif
#else
OUT.vNormal = IN.vNormal;
#endif
OUT.vBaseColor = vColor;
#ifdef HAS_PARAMMAP
float4 vParams = g_txParameters.Sample(g_sScene, IN.vTexUV);
OUT.fRoughness = vParams.x;
OUT.fMetallic = vParams.y;
OUT.fThickness = vParams.z;
OUT.fAO = vParams.w;
#else
OUT.fRoughness = g_xMaterialConstants.pbr_roughness;
OUT.fMetallic = g_xMaterialConstants.pbr_metallic;
OUT.fThickness = g_xMaterialConstants.pbr_thickness;
OUT.fAO = g_xMaterialConstants.pbr_ao;
#endif
/* #ifdef HAS_F0MAP
OUT.f0 = g_txF0.Sample(g_sScene, IN.vTexUV).x;
#else
OUT.f0 = g_xMaterialConstants.pbr_f0;
#endif */
return(OUT);
}
#endif
#ifdef COMPILE_MainIllimination
XMaterial MainIllimination(PSI_XMaterial IN)
{
XMaterial OUT = XMATERIAL_LOAD_DEFAULTS();
float4 fColor = g_txBase.Sample(g_sScene, IN.vTexUV);
// float4 fColor = IN.vPos;
#ifdef HAS_ALPHATEST
clip(fColor.a - g_xMaterialConstants.pbr_alphatest_threshold);
#endif
OUT.vEmissiveColor = fColor.xyz;
#ifdef HAS_NORMALMAP
OUT.vNormal = MixNormalMicro(IN.vNormal,
Color2Normal(g_txNormals.Sample(g_sScene, IN.vTexUV).xyz) * g_xMaterialConstants.nm_weight
);
#else
OUT.vNormal = IN.vNormal;
#endif
return(OUT);
}
#endif
#ifdef COMPILE_MainShadow
XMaterial MainShadow(PSI_XMaterial IN)
{
XMaterial OUT = XMATERIAL_LOAD_DEFAULTS();
float4 fColor = g_txBase.Sample(g_sScene, IN.vTexUV);
// float4 fColor = IN.vPos;
#ifdef HAS_ALPHATEST
clip(fColor.a - g_xMaterialConstants.pbr_alphatest_threshold);
#endif
OUT.vBaseColor = fColor;
// #ifdef HAS_NORMALMAP
// OUT.vNormal = MixNormalMicro(IN.vNormal,
// Color2Normal(g_txNormals.Sample(g_sScene, IN.vTexUV).xyz) * g_xMaterialConstants.nm_weight
// );
// #else
OUT.vNormal = IN.vNormal;
// #endif
return(OUT);
}
#endif
/*
gbuffer.ps
*/
#include "../struct.h"
#include "../mtrl.h"
#include "../const.h"
#include "../xmat.h"
//##########################################################################
PSO_Gbuffer main(PSI_XMaterial IN)
{
// ClipFar(IN.vPos.z, g_vNearFarLayers.y);
IN.vNormal = normalize(IN.vNormal);
XMaterial mtrl = XMATERIAL_MAIN(IN);
PSO_Gbuffer OUT;
OUT.vColor.xyz = mtrl.vBaseColor.xyz;
OUT.vColor.w = mtrl.fLightCoeff;
OUT.vNormal.xyz = NormalEncode(normalize(mtrl.vNormal));
OUT.vNormal.w = mtrl.f0;
OUT.vParam = float4(
mtrl.fRoughness,
mtrl.fMetallic,
mtrl.fThickness,
mtrl.fAO
);
float fDepth = (
#ifdef WANT_WRITE_DEPTH
mtrl.fDepth
#else
IN.vPos.z
#endif
+ g_vNearFarInvWinSize.x) / g_vNearFarInvWinSize.y;
OUT.vDepth = float4(fDepth, fDepth, fDepth, 1.0f);
return(OUT);
}
/*
gbuffer.ps
*/
#include "../struct.h"
#include "../mtrl.h"
#include "../const.h"
#include "../xmat.h"
//##########################################################################
float4 main(PSI_XMaterial IN):COLOR0
{
// ClipFar(IN.vPos.z, g_vNearFarLayers.y);
IN.vNormal = normalize(IN.vNormal);
XMaterial mtrl = XMATERIAL_MAIN(IN);
return(float4(mtrl.vEmissiveColor, 1.0));
}
/*
gbuffer.ps
*/
#include "../struct.h"
#include "../mtrl.h"
#include "../shadow.h"
#include "../const.h"
#include "../xmat.h"
//##########################################################################
PSO_RSMbuffer main(PSI_XMaterial IN)
{
// ClipFar(IN.vPos.z, g_vNearFarLayers.y);
IN.vNormal = normalize(IN.vNormal);
XMaterial mtrl = XMATERIAL_MAIN(IN);
PSO_RSMbuffer OUT;
#ifdef IS_CUBEMAP
OUT.vDepth = dot(IN.vPos.xyz, IN.vPos.xyz);
#else
float fDepth = IN.vPos.z / IN.vPos.w;
float fBias = ShadowSlopeBias(fDepth);
OUT.vDepth = fDepth/* + fBias */;
#endif
OUT.vNormal = float4(NormalEncode(normalize(mtrl.vNormal)), 1.0);
OUT.vFlux = mtrl.vBaseColor;
return(OUT);
}
......@@ -4,50 +4,35 @@ gbuffer.ps
*/
#include "../../struct.h"
#include "../../mtrl.h"
#include "../../const.h"
#include "../struct.h"
#include "../mtrl.h"
#include "../const.h"
#include "../xmat.h"
//##########################################################################
// SamplerState g_sScene: register(s0);
// Texture2D g_txColor: register(t0); // basetexture
// Texture2D g_txParameters: register(t10);
XMAT_MS_TEXTURES();
XMAT_MS_SAMPLERS();
struct XMaterial
cbuffer CDataClipPlanes: register(b6)
{
XMATERIAL_OUTPUT_STRUCT();
float4 g_vClipPlanes[4];
};
XMATERIAL_DEFAULT_LOADER();
struct PSI_XMaterial
{
XMAT_PS_STRUCT();
};
//##########################################################################
#include XMATERIAL_SHADER
//##########################################################################
PSO_Gbuffer main(PSI_XMaterial IN)
float4 main(PSI_XMaterial IN):COLOR0
{
float3 vPos = IN.vPos.xyz / IN.vPos.w;
[unroll]for(uint i = 0; i < 4; ++i)
{
float4 vPlane = g_vClipPlanes[i];
clip(dot(vPlane.xyz, vPos) + vPlane.w);
}
// return(float4(1.0, 0.0, 0.0, 0.5));
// ClipFar(IN.vPos.z, g_vNearFarLayers.y);
IN.vNormal = normalize(IN.vNormal);
XMaterial mtrl = XMATERIAL_MAIN(IN);
return(CreateGbuffer(
float4(mtrl.vBaseColor, 0.0),
mtrl.vNormal,
float4(mtrl.fRoughness,
mtrl.fMetallic,
mtrl.fThickness,
mtrl.fAO),
IN.vPos,
g_vNearFarLayers
));
return(mtrl.vBaseColor);
}
#ifndef __XMAT_H
#define __XMAT_H
XMAT_MS_TEXTURES();
XMAT_MS_SAMPLERS();
struct XMaterial
{
XMATERIAL_OUTPUT_STRUCT();
#ifdef WANT_WRITE_DEPTH
float fDepth;
#endif
};
struct PSI_XMaterial
{
XMAT_PS_STRUCT();
};
XMATERIAL_DEFAULT_LOADER();
//##########################################################################
#include XMATERIAL_SHADER
#endif
......@@ -107,6 +107,7 @@
<ClInclude Include="..\..\..\source\xcommon\IAsyncTaskRunner.h" />
<ClInclude Include="..\..\..\source\xcommon\IFileSystem.h" />
<ClInclude Include="..\..\..\source\xcommon\IPluginManager.h" />
<ClInclude Include="..\..\..\source\xcommon\IXConfig.h" />
<ClInclude Include="..\..\..\source\xcommon\IXCore.h" />
<ClInclude Include="..\..\..\source\xcommon\IXModelLoader.h" />
<ClInclude Include="..\..\..\source\xcommon\IXPlugin.h" />
......
......@@ -269,5 +269,8 @@
<ClInclude Include="..\..\..\source\xcommon\IXTextureProxy.h">
<Filter>Header\xcommon</Filter>
</ClInclude>
<ClInclude Include="..\..\..\source\xcommon\IXConfig.h">
<Filter>Header\xcommon</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -198,6 +198,8 @@
<ClInclude Include="..\..\..\source\mtrl\reflection.h" />
<ClInclude Include="..\..\..\source\mtrl\ShaderVariant.h" />
<ClInclude Include="..\..\..\source\mtrl\sxmtrl.h" />
<ClInclude Include="..\..\..\source\xcommon\IXMaterialLoader.h" />
<ClInclude Include="..\..\..\source\xcommon\IXMaterialProxy.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
......@@ -92,5 +92,11 @@
<ClInclude Include="..\..\..\source\mtrl\LogicExpression.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\source\xcommon\IXMaterialLoader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\source\xcommon\IXMaterialProxy.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -20,10 +20,14 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\source\xSpecs\dllmain.cpp" />
<ClCompile Include="..\..\..\source\xSpecs\MaterialLoader.cpp" />
<ClCompile Include="..\..\..\source\xSpecs\MaterialProxy.cpp" />
<ClCompile Include="..\..\..\source\xSpecs\plugin_main.cpp" />
<ClCompile Include="..\..\..\source\xSpecs\TextureProxy.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\source\xSpecs\MaterialLoader.h" />
<ClInclude Include="..\..\..\source\xSpecs\MaterialProxy.h" />
<ClInclude Include="..\..\..\source\xSpecs\TextureProxy.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
......
......@@ -22,10 +22,22 @@
<ClCompile Include="..\..\..\source\xSpecs\TextureProxy.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\source\xSpecs\MaterialProxy.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\source\xSpecs\MaterialLoader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\source\xSpecs\TextureProxy.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\source\xSpecs\MaterialProxy.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\source\xSpecs\MaterialLoader.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -6,6 +6,9 @@ See the license in LICENSE
#include "SkyBox.h"
CSkyBox::CSkyBox()
{
}
void CSkyBox::setDevice(IGXDevice *pDevice)
{
......@@ -82,6 +85,8 @@ void CSkyBox::setDevice(IGXDevice *pDevice)
void CSkyBox::setMaterialSystem(IXMaterialSystem *pMaterialSystem)
{
m_pMaterialSystem = pMaterialSystem;
XVertexFormatHandler *pFormat = m_pMaterialSystem->getVertexFormat("xSky");
m_pVertexShaderHandler = m_pMaterialSystem->registerVertexShader(pFormat, "base/skybox.vs");
}
......@@ -166,7 +171,7 @@ void CSkyBox::render()
}
float4x4 World = SMMatrixTranspose(m_mMatRotation/* * SMMatrixTranslation(pos->x, pos->y, pos->z)*/);
m_pMaterialSystem->bindVS(m_pVertexShaderHandler);
m_pMaterialSystem->bindMaterial(m_pSky1);
#if 0
if (/*m_isChangingMainTex*/m_isChanging)
......
......@@ -38,6 +38,8 @@ class CSkyBox
public:
SX_ALIGNED_OP_MEM2();
CSkyBox();
void setDevice(IGXDevice *pDevice);
void setMaterialSystem(IXMaterialSystem *pMaterialSystem);
......@@ -101,6 +103,8 @@ protected:
IGXDevice *m_pDevice = NULL;
IXMaterialSystem *m_pMaterialSystem = NULL;
XVertexShaderHandler* m_pVertexShaderHandler = NULL;
};
#if 0
......
......@@ -34,7 +34,7 @@ public:
levelProgress.type = XEventLevelProgress::TYPE_PROGRESS_BEGIN;
pProgressChannel->broadcastEvent(&levelProgress);
m_pSkyBox->setTexture("sky_hdr_hl2.dds");
m_pSkyBox->setTexture("sky_hdr_hl2");
levelProgress.fProgress = 1.0f;
levelProgress.type = XEventLevelProgress::TYPE_PROGRESS_END;
......
......@@ -83,10 +83,16 @@ bool XMETHODCALLTYPE CAnimatedModelProvider::createModel(UINT uResourceCount, IX
return(false);
}
}
else
{
pShared->AddRef();
}
CAnimatedModel *pModel = new CAnimatedModel(this, pShared);
m_apModels.push_back(pModel);
pShared->Release();
*ppModel = pModel;
return(true);
}
......