From d4f1d99bd7098964a174aab84182f50289769151 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Tue, 22 Mar 2022 20:46:44 +0100 Subject: [PATCH] Some work on GPU Skinning and Vulkan debugging --- neo/renderer/NVRHI/RenderBackend_NVRHI.cpp | 35 ++-- neo/renderer/NVRHI/RenderProgs_NVRHI.cpp | 2 +- neo/renderer/RenderCommon.h | 7 +- neo/renderer/RenderProgs.cpp | 14 +- neo/renderer/RenderSystem_init.cpp | 1 + neo/shaders/builtin/gbuffer.ps.hlsl | 7 +- neo/shaders/builtin/gui.ps.hlsl | 6 +- .../builtin/lighting/interaction.vs.hlsl | 1 + .../lighting/interactionAmbient.ps.hlsl | 80 ++++---- .../lighting/interactionAmbient.vs.hlsl | 157 ++++++++++++---- .../interactionAmbient_skinned.ps.hlsl | 104 ----------- .../interactionAmbient_skinned.vs.hlsl | 176 ------------------ neo/shaders/builtin/lighting/shadow.ps.hlsl | 5 +- .../builtin/lighting/shadow_skinned.ps.hlsl | 43 ----- .../builtin/lighting/shadow_skinned.vs.hlsl | 96 ---------- neo/shaders/builtin/texture_color.ps.hlsl | 4 +- neo/sys/win32/DeviceManager_DX12.cpp | 4 - neo/sys/win32/DeviceManager_VK.cpp | 26 ++- 18 files changed, 230 insertions(+), 538 deletions(-) delete mode 100644 neo/shaders/builtin/lighting/interactionAmbient_skinned.ps.hlsl delete mode 100644 neo/shaders/builtin/lighting/interactionAmbient_skinned.vs.hlsl delete mode 100644 neo/shaders/builtin/lighting/shadow_skinned.ps.hlsl delete mode 100644 neo/shaders/builtin/lighting/shadow_skinned.vs.hlsl diff --git a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp index 53e0891b..8213fc12 100644 --- a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp +++ b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp @@ -239,7 +239,6 @@ void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf ) changeState = true; } - // RB: for debugging int bindingLayoutType = renderProgManager.BindingLayoutType(); idStaticList* layouts @@ -297,7 +296,6 @@ void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf ) } nvrhi::DrawArguments args; - // FIXME idDrawShadowVert args.startVertexLocation = currentVertexOffset / sizeof( idDrawVert ); args.startIndexLocation = currentIndexOffset / sizeof( triIndex_t ); args.vertexCount = surf->numIndexes; @@ -306,8 +304,6 @@ void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf ) // RB: added stats pc.c_drawElements++; pc.c_drawIndexes += surf->numIndexes; - - //renderLog.CloseBlock(); } void idRenderBackend::GetCurrentBindingLayout( int type ) @@ -453,13 +449,13 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) desc[1].bindings[0] = nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_PointWrapSampler ); } } - else if( type == BINDING_LAYOUT_DRAW_SHADOW ) + else if( type == BINDING_LAYOUT_DRAW_SHADOWVOLUME ) { if( desc[0].bindings.empty() ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), // blue noise + nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), }; } else @@ -1148,7 +1144,7 @@ extern idCVar r_useStencilShadowPreload; void idRenderBackend::DrawStencilShadowPass( const drawSurf_t* drawSurf, const bool renderZPass ) { -#if 0 +#if 1 if( renderZPass ) { // Z-pass @@ -1238,24 +1234,25 @@ void idRenderBackend::DrawStencilShadowPass( const drawSurf_t* drawSurf, const b changeState = true; } - GetCurrentBindingLayout(); - - // RB: for debugging - int program = renderProgManager.CurrentProgram(); int bindingLayoutType = renderProgManager.BindingLayoutType(); - auto& info = renderProgManager.GetProgramInfo( program ); - for( int i = 0; i < info.bindingLayouts->Num(); i++ ) + idStaticList* layouts + = renderProgManager.GetBindingLayout( bindingLayoutType ); + + GetCurrentBindingLayout( bindingLayoutType ); + + for( int i = 0; i < layouts->Num(); i++ ) { - if( !currentBindingSets[i] || *currentBindingSets[i]->getDesc() != pendingBindingSetDescs[i] ) + if( !currentBindingSets[i] || *currentBindingSets[i]->getDesc() != pendingBindingSetDescs[bindingLayoutType][i] ) { - currentBindingSets[i] = bindingCache.GetOrCreateBindingSet( pendingBindingSetDescs[i], ( *info.bindingLayouts )[i] ); + currentBindingSets[i] = bindingCache.GetOrCreateBindingSet( pendingBindingSetDescs[bindingLayoutType][i], ( *layouts )[i] ); changeState = true; } } renderProgManager.CommitConstantBuffer( commandList ); + int program = renderProgManager.CurrentProgram(); PipelineKey key{ glStateBits, program, depthBias, slopeScaleBias, currentFrameBuffer }; auto pipeline = pipelineCache.GetOrCreatePipeline( key ); @@ -1269,7 +1266,7 @@ void idRenderBackend::DrawStencilShadowPass( const drawSurf_t* drawSurf, const b { nvrhi::GraphicsState state; - for( int i = 0; i < info.bindingLayouts->Num(); i++ ) + for( int i = 0; i < layouts->Num(); i++ ) { state.bindings.push_back( currentBindingSets[i] ); } @@ -1304,7 +1301,7 @@ void idRenderBackend::DrawStencilShadowPass( const drawSurf_t* drawSurf, const b { args.startVertexLocation = currentVertexOffset / sizeof( idShadowVert ); } - args.startIndexLocation = currentIndexOffset / sizeof( uint16 ); + args.startIndexLocation = currentIndexOffset / sizeof( triIndex_t ); args.vertexCount = drawSurf->numIndexes; commandList->drawIndexed( args ); @@ -1323,6 +1320,10 @@ idRenderBackend::idRenderBackend() { hiZGenPass = nullptr; ssaoPass = nullptr; + + memset( &glConfig, 0, sizeof( glConfig ) ); + + //glConfig.gpuSkinningAvailable = true; } /* diff --git a/neo/renderer/NVRHI/RenderProgs_NVRHI.cpp b/neo/renderer/NVRHI/RenderProgs_NVRHI.cpp index 10251def..b1ae4b58 100644 --- a/neo/renderer/NVRHI/RenderProgs_NVRHI.cpp +++ b/neo/renderer/NVRHI/RenderProgs_NVRHI.cpp @@ -195,7 +195,7 @@ void idRenderProgManager::LoadProgram( const int programIndex, const int vertexS renderProg_t& prog = renderProgs[programIndex]; prog.fragmentShaderIndex = fragmentShaderIndex; prog.vertexShaderIndex = vertexShaderIndex; - if( prog.vertexLayout > 0 ) + if( prog.vertexLayout != LAYOUT_UNKNOWN ) { prog.inputLayout = device->createInputLayout( &vertexLayoutDescs[prog.vertexLayout][0], diff --git a/neo/renderer/RenderCommon.h b/neo/renderer/RenderCommon.h index cb61877c..1851a84f 100644 --- a/neo/renderer/RenderCommon.h +++ b/neo/renderer/RenderCommon.h @@ -845,7 +845,7 @@ enum bindingLayoutType_t BINDING_LAYOUT_BLIT, BINDING_LAYOUT_DRAW_AO, BINDING_LAYOUT_DRAW_AO1, - BINDING_LAYOUT_DRAW_SHADOW, + BINDING_LAYOUT_DRAW_SHADOWVOLUME, BINDING_LAYOUT_DRAW_INTERACTION, BINDING_LAYOUT_DRAW_INTERACTION_SM, BINDING_LAYOUT_DRAW_FOG, @@ -1066,9 +1066,10 @@ extern idCVar r_windowHeight; extern idCVar r_debugContext; // enable various levels of context debug extern idCVar r_glDriver; // "opengl32", etc -// SRS - Added cvar to control workarounds for AMD OSX driver bugs when shadow mapping enabled +#if defined(USE_NVRHI) + extern idCVar r_useValidationLayers; +#endif extern idCVar r_skipAMDWorkarounds; // skip work arounds for AMD driver bugs -// SRS end extern idCVar r_skipIntelWorkarounds; // skip work arounds for Intel driver bugs extern idCVar r_vidMode; // video mode number extern idCVar r_displayRefresh; // optional display refresh rate option for vid mode diff --git a/neo/renderer/RenderProgs.cpp b/neo/renderer/RenderProgs.cpp index b91f4a7e..94741737 100644 --- a/neo/renderer/RenderProgs.cpp +++ b/neo/renderer/RenderProgs.cpp @@ -240,7 +240,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) { nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) }; - bindingLayouts[BINDING_LAYOUT_DRAW_SHADOW] = { device->createBindingLayout( shadowLayout ) }; + bindingLayouts[BINDING_LAYOUT_DRAW_SHADOWVOLUME] = { device->createBindingLayout( shadowLayout ) }; auto interactionBindingLayout = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) @@ -342,7 +342,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) rpStage_t stages; vertexLayoutType_t layout; bindingLayoutType_t bindingLayout; - bindingLayoutType_t bindingLayout2; + //bindingLayoutType_t bindingLayout2; } builtins[] = { { BUILTIN_GUI, "builtin/gui", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT }, @@ -378,10 +378,10 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) { BUILTIN_INTERACTION_AMBIENT_SKINNED, "builtin/lighting/interactionAmbient", "_skinned", { {"USE_GPU_SKINNING", "1" }, { "USE_PBR", "0" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION }, { BUILTIN_INTERACTION_SHADOW_MAPPING_SPOT, "builtin/lighting/interactionSM", "_spot", { {"USE_GPU_SKINNING", "0" }, { "LIGHT_POINT", "0" }, { "LIGHT_PARALLEL", "0" }, { "USE_PBR", "0" }, { "USE_NORMAL_FMT_RGB8", "0" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION_SM }, - { BUILTIN_INTERACTION_SHADOW_MAPPING_SPOT_SKINNED, "builtin/lighting/interactionSM", "_spot_skinned", { {"USE_GPU_SKINNING", "1" }, { "LIGHT_POINT", "0" }, { "LIGHT_PARALLEL", 0 }, { "USE_PBR", "0" }, { "USE_NORMAL_FMT_RGB8", "0" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION_SM }, + { BUILTIN_INTERACTION_SHADOW_MAPPING_SPOT_SKINNED, "builtin/lighting/interactionSM", "_spot_skinned", { {"USE_GPU_SKINNING", "1" }, { "LIGHT_POINT", "0" }, { "LIGHT_PARALLEL", "0" }, { "USE_PBR", "0" }, { "USE_NORMAL_FMT_RGB8", "0" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION_SM }, { BUILTIN_INTERACTION_SHADOW_MAPPING_POINT, "builtin/lighting/interactionSM", "_point", { {"USE_GPU_SKINNING", "0" }, { "LIGHT_POINT", "1" }, { "LIGHT_PARALLEL", "0" }, { "USE_PBR", "0" }, { "USE_NORMAL_FMT_RGB8", "0" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION_SM }, - { BUILTIN_INTERACTION_SHADOW_MAPPING_POINT_SKINNED, "builtin/lighting/interactionSM", "_point_skinned", { {"USE_GPU_SKINNING", "1" }, { "LIGHT_POINT", "1" }, { "LIGHT_PARALLEL", 0 }, { "USE_PBR", "0" }, { "USE_NORMAL_FMT_RGB8", "0" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION_SM }, + { BUILTIN_INTERACTION_SHADOW_MAPPING_POINT_SKINNED, "builtin/lighting/interactionSM", "_point_skinned", { {"USE_GPU_SKINNING", "1" }, { "LIGHT_POINT", "1" }, { "LIGHT_PARALLEL", "0" }, { "USE_PBR", "0" }, { "USE_NORMAL_FMT_RGB8", "0" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION_SM }, { BUILTIN_INTERACTION_SHADOW_MAPPING_PARALLEL, "builtin/lighting/interactionSM", "_parallel", { {"USE_GPU_SKINNING", "0" }, { "LIGHT_POINT", "0" }, { "LIGHT_PARALLEL", "1" }, { "USE_PBR", "0" }, { "USE_NORMAL_FMT_RGB8", "0" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION_SM }, { BUILTIN_INTERACTION_SHADOW_MAPPING_PARALLEL_SKINNED, "builtin/lighting/interactionSM", "_parallel_skinned", { {"USE_GPU_SKINNING", "1" }, { "LIGHT_POINT", "0" }, { "LIGHT_PARALLEL", "1" }, { "USE_PBR", "0" }, { "USE_NORMAL_FMT_RGB8", "0" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION_SM }, @@ -391,7 +391,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) { BUILTIN_PBR_INTERACTION_SKINNED, "builtin/lighting/interaction", "_skinned_PBR", { {"USE_GPU_SKINNING", "1" }, { "USE_PBR", "1" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION }, { BUILTIN_PBR_INTERACTION_AMBIENT, "builtin/lighting/interactionAmbient", "_PBR", { {"USE_GPU_SKINNING", "0" }, { "USE_PBR", "1" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION }, - { BUILTIN_PBR_INTERACTION_AMBIENT_SKINNED, "builtin/lighting/interactionAmbient_skinned", "_PBR", { {"USE_GPU_SKINNING", "1" }, { "USE_PBR", "1" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION }, + { BUILTIN_PBR_INTERACTION_AMBIENT_SKINNED, "builtin/lighting/interactionAmbient", "_skinned_PBR", { {"USE_GPU_SKINNING", "1" }, { "USE_PBR", "1" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION }, { BUILTIN_PBR_INTERACTION_SHADOW_MAPPING_SPOT, "builtin/lighting/interactionSM", "_spot_PBR", { {"USE_GPU_SKINNING", "0" }, { "LIGHT_POINT", "0" }, { "LIGHT_PARALLEL", "0" }, { "USE_PBR", "1" }, { "USE_NORMAL_FMT_RGB8", "0" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION_SM }, { BUILTIN_PBR_INTERACTION_SHADOW_MAPPING_SPOT_SKINNED, "builtin/lighting/interactionSM", "_spot_skinned_PBR", { {"USE_GPU_SKINNING", "1" }, { "LIGHT_POINT", "0" }, { "LIGHT_PARALLEL", "0" }, { "USE_PBR", "1" }, { "USE_NORMAL_FMT_RGB8", "0" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_INTERACTION_SM }, @@ -418,8 +418,8 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) { BUILTIN_DEPTH, "builtin/depth", "", { {"USE_GPU_SKINNING", "0" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_CONSTANT_BUFFER_ONLY }, { BUILTIN_DEPTH_SKINNED, "builtin/depth", "_skinned", { {"USE_GPU_SKINNING", "1" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_CONSTANT_BUFFER_ONLY }, - { BUILTIN_SHADOW, "builtin/lighting/shadow", "", { {"USE_GPU_SKINNING", "0" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_SHADOW_VERT, BINDING_LAYOUT_DRAW_SHADOW }, - { BUILTIN_SHADOW_SKINNED, "builtin/lighting/shadow", "_skinned", { {"USE_GPU_SKINNING", "1" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_SHADOW_VERT_SKINNED, BINDING_LAYOUT_DRAW_SHADOW }, + { BUILTIN_SHADOW, "builtin/lighting/shadow", "", { {"USE_GPU_SKINNING", "0" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_SHADOW_VERT, BINDING_LAYOUT_CONSTANT_BUFFER_ONLY }, + { BUILTIN_SHADOW_SKINNED, "builtin/lighting/shadow", "_skinned", { {"USE_GPU_SKINNING", "1" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_SHADOW_VERT_SKINNED, BINDING_LAYOUT_CONSTANT_BUFFER_ONLY }, { BUILTIN_SHADOW_DEBUG, "builtin/debug/shadowDebug", "", { {"USE_GPU_SKINNING", "0" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT }, { BUILTIN_SHADOW_DEBUG_SKINNED, "builtin/debug/shadowDebug", "_skinned", { {"USE_GPU_SKINNING", "1" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT }, diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 4266afff..951d5292 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -68,6 +68,7 @@ idCVar r_debugContext( "r_debugContext", "0", CVAR_RENDERER, "Enable various lev idCVar r_glDriver( "r_glDriver", "", CVAR_RENDERER, "\"opengl32\", etc." ); #if defined(USE_NVRHI) idCVar r_gapi( "r_gapi", "dx12", CVAR_RENDERER, "Specifies the graphics api to use (dx12, vulkan)" ); + idCVar r_useValidationLayers( "r_useValidationLayers", "0", CVAR_INTEGER | CVAR_INIT, "1 is just the NVRHI and 2 will turn on additional DX12, VK validation layers" ); #endif // SRS - Added workaround for AMD OSX driver bugs caused by GL_EXT_timer_query when shadow mapping enabled; Intel bugs not present on OSX #if defined(__APPLE__) diff --git a/neo/shaders/builtin/gbuffer.ps.hlsl b/neo/shaders/builtin/gbuffer.ps.hlsl index c0013f5a..96c93400 100644 --- a/neo/shaders/builtin/gbuffer.ps.hlsl +++ b/neo/shaders/builtin/gbuffer.ps.hlsl @@ -31,9 +31,8 @@ If you have questions concerning this license or the applicable additional terms // *INDENT-OFF* -Texture2D t_NormalMap : register( t0 ); - -SamplerState samp0 : register( s0 ); // normal map +Texture2D t_NormalMap : register( t0 VK_DESCRIPTOR_SET( 0 ) ); +SamplerState s_Sampler : register( s0 VK_DESCRIPTOR_SET( 1 ) ); struct PS_IN { @@ -54,7 +53,7 @@ struct PS_OUT void main( PS_IN fragment, out PS_OUT result ) { - float4 bump = t_NormalMap.Sample( samp0, fragment.texcoord0 ) * 2.0f - 1.0f; + float4 bump = t_NormalMap.Sample( s_Sampler, fragment.texcoord0 ) * 2.0f - 1.0f; // RB begin float3 localNormal; diff --git a/neo/shaders/builtin/gui.ps.hlsl b/neo/shaders/builtin/gui.ps.hlsl index 529e8f3f..50bd43af 100644 --- a/neo/shaders/builtin/gui.ps.hlsl +++ b/neo/shaders/builtin/gui.ps.hlsl @@ -26,11 +26,11 @@ If you have questions concerning this license or the applicable additional terms =========================================================================== */ -#include "../global_inc.hlsl" +#include "global_inc.hlsl" // *INDENT-OFF* -Texture2D texGui : register( t0 ); -SamplerState samp0 : register( s0 ); +Texture2D texGui : register( t0 VK_DESCRIPTOR_SET( 0 ) ); +SamplerState samp0 : register( s0 VK_DESCRIPTOR_SET( 1 ) ); struct PS_IN { float4 position : SV_POSITION; diff --git a/neo/shaders/builtin/lighting/interaction.vs.hlsl b/neo/shaders/builtin/lighting/interaction.vs.hlsl index 15259057..cf31dfb8 100644 --- a/neo/shaders/builtin/lighting/interaction.vs.hlsl +++ b/neo/shaders/builtin/lighting/interaction.vs.hlsl @@ -58,6 +58,7 @@ struct VS_OUT { float4 texcoord6 : TEXCOORD6_centroid; float4 color : COLOR0; }; + // *INDENT-ON* void main( VS_IN vertex, out VS_OUT result ) diff --git a/neo/shaders/builtin/lighting/interactionAmbient.ps.hlsl b/neo/shaders/builtin/lighting/interactionAmbient.ps.hlsl index 7b66612c..84859e99 100644 --- a/neo/shaders/builtin/lighting/interactionAmbient.ps.hlsl +++ b/neo/shaders/builtin/lighting/interactionAmbient.ps.hlsl @@ -31,48 +31,48 @@ If you have questions concerning this license or the applicable additional terms // *INDENT-OFF* -Texture2D t_Normal : register( t0 VK_DESCRIPTOR_SET( 0 ) ); -Texture2D t_Specular : register( t1 VK_DESCRIPTOR_SET( 0 ) ); -Texture2D t_BaseColor : register( t2 VK_DESCRIPTOR_SET( 0 ) ); -Texture2D t_LightFalloff : register( t3 VK_DESCRIPTOR_SET( 0 ) ); -Texture2D t_LightProjection : register( t4 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_Normal : register( t0 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_Specular : register( t1 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_BaseColor : register( t2 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_LightFalloff : register( t3 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_LightProjection : register( t4 VK_DESCRIPTOR_SET( 0 ) ); -SamplerState samp0 : register( s0 VK_DESCRIPTOR_SET( 1 ) ); // texture 1 is the per-surface normal map -SamplerState samp1 : register( s1 VK_DESCRIPTOR_SET( 1 ) ); // texture 3 is the per-surface specular or roughness/metallic/AO mixer map -SamplerState samp2 : register( s2 VK_DESCRIPTOR_SET( 1 ) ); // texture 2 is the per-surface baseColor map -SamplerState samp3 : register( s3 VK_DESCRIPTOR_SET( 1 ) ); // texture 4 is the light falloff texture -SamplerState samp4 : register( s4 VK_DESCRIPTOR_SET( 1 ) ); // texture 5 is the light projection texture +SamplerState s_Material : register( s0 VK_DESCRIPTOR_SET( 1 ) ); // for the normal/specular/basecolor +SamplerState s_Lighting : register( s1 VK_DESCRIPTOR_SET( 1 ) ); // for sampling the jitter -struct PS_IN { - half4 position : SV_Position; - half4 texcoord1 : TEXCOORD1_centroid; - half4 texcoord2 : TEXCOORD2_centroid; - half4 texcoord3 : TEXCOORD3_centroid; - half4 texcoord4 : TEXCOORD4_centroid; - half4 texcoord5 : TEXCOORD5_centroid; - half4 texcoord6 : TEXCOORD6_centroid; - half4 color : COLOR0; +struct PS_IN +{ + float4 position : SV_Position; +// float4 texcoord0 : TEXCOORD0_centroid; + float4 texcoord1 : TEXCOORD1_centroid; + float4 texcoord2 : TEXCOORD2_centroid; + float4 texcoord3 : TEXCOORD3_centroid; + float4 texcoord4 : TEXCOORD4_centroid; + float4 texcoord5 : TEXCOORD5_centroid; + float4 texcoord6 : TEXCOORD6_centroid; + float4 color : COLOR0; }; -struct PS_OUT { +struct PS_OUT +{ half4 color : SV_Target0; }; // *INDENT-ON* void main( PS_IN fragment, out PS_OUT result ) { - half4 bumpMap = t_Normal.Sample( samp0, fragment.texcoord1.xy ); - half4 lightFalloff = idtex2Dproj( samp3, t_LightFalloff, fragment.texcoord2 ); - half4 lightProj = idtex2Dproj( samp4, t_LightProjection, fragment.texcoord3 ); - half4 YCoCG = t_BaseColor.Sample( samp2, fragment.texcoord4.xy ); - half4 specMapSRGB = t_Specular.Sample( samp1, fragment.texcoord5.xy ); - half4 specMap = sRGBAToLinearRGBA( specMapSRGB ); + float4 bumpMap = t_Normal.Sample( s_Material, fragment.texcoord1.xy ); + float4 lightFalloff = idtex2Dproj( s_Lighting, t_LightFalloff, fragment.texcoord2 ); + float4 lightProj = idtex2Dproj( s_Lighting, t_LightProjection, fragment.texcoord3 ); + float4 YCoCG = t_BaseColor.Sample( s_Material, fragment.texcoord4.xy ); + float4 specMapSRGB = t_Specular.Sample( s_Material, fragment.texcoord5.xy ); + float4 specMap = sRGBAToLinearRGBA( specMapSRGB ); - const half3 ambientLightVector = half3( 0.5f, 9.5f - 0.385f, 0.8925f ); - half3 lightVector = normalize( ambientLightVector ); - half3 diffuseMap = sRGBToLinearRGB( ConvertYCoCgToRGB( YCoCG ) ); + const float3 ambientLightVector = half3( 0.5f, 9.5f - 0.385f, 0.8925f ); + float3 lightVector = normalize( ambientLightVector ); + float3 diffuseMap = sRGBToLinearRGB( ConvertYCoCgToRGB( YCoCG ) ); - half3 localNormal; + float3 localNormal; // RB begin #if defined(USE_NORMAL_FMT_RGB8) localNormal.xy = bumpMap.rg - 0.5; @@ -84,25 +84,25 @@ void main( PS_IN fragment, out PS_OUT result ) localNormal = normalize( localNormal ); // traditional very dark Lambert light model used in Doom 3 - half ldotN = saturate( dot3( localNormal, lightVector ) ); + float ldotN = saturate( dot3( localNormal, lightVector ) ); #if defined(USE_HALF_LAMBERT) // RB: http://developer.valvesoftware.com/wiki/Half_Lambert - half halfLdotN = dot3( localNormal, lightVector ) * 0.5 + 0.5; + float halfLdotN = dot3( localNormal, lightVector ) * 0.5 + 0.5; halfLdotN *= halfLdotN; - half lambert = halfLdotN; + float lambert = halfLdotN; #else - half lambert = ldotN; + float lambert = ldotN; #endif - const half specularPower = 10.0f; - half hDotN = dot3( normalize( fragment.texcoord6.xyz ), localNormal ); + const float specularPower = 10.0f; + float hDotN = dot3( normalize( fragment.texcoord6.xyz ), localNormal ); // RB: added abs - half3 specularContribution = _half3( pow( abs( hDotN ), specularPower ) ); + float3 specularContribution = _float3( pow( abs( hDotN ), specularPower ) ); - half3 diffuseColor = diffuseMap * ( rpDiffuseModifier.xyz ); - half3 specularColor = specMap.xyz * specularContribution * ( rpSpecularModifier.xyz ); - half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz ); + float3 diffuseColor = diffuseMap * ( rpDiffuseModifier.xyz ); + float3 specularColor = specMap.xyz * specularContribution * ( rpSpecularModifier.xyz ); + float3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz ); result.color.xyz = ( diffuseColor + specularColor ) * lightColor * fragment.color.xyz; result.color.w = 1.0; diff --git a/neo/shaders/builtin/lighting/interactionAmbient.vs.hlsl b/neo/shaders/builtin/lighting/interactionAmbient.vs.hlsl index 1414743c..c85bdab8 100644 --- a/neo/shaders/builtin/lighting/interactionAmbient.vs.hlsl +++ b/neo/shaders/builtin/lighting/interactionAmbient.vs.hlsl @@ -28,49 +28,131 @@ If you have questions concerning this license or the applicable additional terms #include "global_inc.hlsl" - -// *INDENT-OFF* - #if USE_GPU_SKINNING -cbuffer CB : register( b1 ) { float4 matrices[408]; }; +cbuffer CB : +register( b1 ) +{ + float4 matrices[408]; +}; #endif -struct VS_IN { - float4 position : POSITION; - float2 texcoord : TEXCOORD0; - float4 normal : NORMAL; - float4 tangent : TANGENT; - float4 color : COLOR0; +struct VS_IN +{ +float4 position : + POSITION; +float2 texcoord : + TEXCOORD0; +float4 normal : + NORMAL; +float4 tangent : + TANGENT; +float4 color : + COLOR0; +float4 color2 : + COLOR1; }; -struct VS_OUT { - float4 position : SV_Position; - float4 texcoord1 : TEXCOORD1_centroid; - float4 texcoord2 : TEXCOORD2_centroid; - float4 texcoord3 : TEXCOORD3_centroid; - float4 texcoord4 : TEXCOORD4_centroid; - float4 texcoord5 : TEXCOORD5_centroid; - float4 texcoord6 : TEXCOORD6_centroid; - float4 color : COLOR0; +struct VS_OUT +{ +float4 position : + SV_Position; + //float4 texcoord0 : TEXCOORD0_centroid; +float4 texcoord1 : + TEXCOORD1_centroid; +float4 texcoord2 : + TEXCOORD2_centroid; +float4 texcoord3 : + TEXCOORD3_centroid; +float4 texcoord4 : + TEXCOORD4_centroid; +float4 texcoord5 : + TEXCOORD5_centroid; +float4 texcoord6 : + TEXCOORD6_centroid; +float4 color : + COLOR0; }; // *INDENT-ON* void main( VS_IN vertex, out VS_OUT result ) { - float4 normal = vertex.normal * 2.0 - 1.0; - float4 tangent = vertex.tangent * 2.0 - 1.0; - float3 binormal = cross( normal.xyz, tangent.xyz ) * tangent.w; + float4 vNormal = vertex.normal * 2.0 - 1.0; + float4 vTangent = vertex.tangent * 2.0 - 1.0; + float3 vBitangent = cross( vNormal.xyz, vTangent.xyz ) * vTangent.w; - result.position.x = dot4( vertex.position, rpMVPmatrixX ); - result.position.y = dot4( vertex.position, rpMVPmatrixY ); - result.position.z = dot4( vertex.position, rpMVPmatrixZ ); - result.position.w = dot4( vertex.position, rpMVPmatrixW ); +#if USE_GPU_SKINNING + //-------------------------------------------------------------- + // GPU transformation of the normal / tangent / bitangent + // + // multiplying with 255.1 give us the same result and is faster than floor( w * 255 + 0.5 ) + //-------------------------------------------------------------- + const float w0 = vertex.color2.x; + const float w1 = vertex.color2.y; + const float w2 = vertex.color2.z; + const float w3 = vertex.color2.w; + + float4 matX, matY, matZ; // must be float4 for vec4 + int joint = int( vertex.color.x * 255.1 * 3.0 ); + matX = matrices[int( joint + 0 )] * w0; + matY = matrices[int( joint + 1 )] * w0; + matZ = matrices[int( joint + 2 )] * w0; + + joint = int( vertex.color.y * 255.1 * 3.0 ); + matX += matrices[int( joint + 0 )] * w1; + matY += matrices[int( joint + 1 )] * w1; + matZ += matrices[int( joint + 2 )] * w1; + + joint = int( vertex.color.z * 255.1 * 3.0 ); + matX += matrices[int( joint + 0 )] * w2; + matY += matrices[int( joint + 1 )] * w2; + matZ += matrices[int( joint + 2 )] * w2; + + joint = int( vertex.color.w * 255.1 * 3.0 ); + matX += matrices[int( joint + 0 )] * w3; + matY += matrices[int( joint + 1 )] * w3; + matZ += matrices[int( joint + 2 )] * w3; + + float3 normal; + normal.x = dot3( matX, vNormal ); + normal.y = dot3( matY, vNormal ); + normal.z = dot3( matZ, vNormal ); + normal = normalize( normal ); + + float3 tangent; + tangent.x = dot3( matX, vTangent ); + tangent.y = dot3( matY, vTangent ); + tangent.z = dot3( matZ, vTangent ); + tangent = normalize( tangent ); + + float3 bitangent; + bitangent.x = dot3( matX, vBitangent ); + bitangent.y = dot3( matY, vBitangent ); + bitangent.z = dot3( matZ, vBitangent ); + bitangent = normalize( bitangent ); + + float4 modelPosition; + modelPosition.x = dot4( matX, vertex.position ); + modelPosition.y = dot4( matY, vertex.position ); + modelPosition.z = dot4( matZ, vertex.position ); + modelPosition.w = 1.0; + +#else + float4 modelPosition = vertex.position; + float3 normal = vNormal.xyz; + float3 tangent = vTangent.xyz; + float3 bitangent = vBitangent.xyz; +#endif + + result.position.x = dot4( modelPosition, rpMVPmatrixX ); + result.position.y = dot4( modelPosition, rpMVPmatrixY ); + result.position.z = dot4( modelPosition, rpMVPmatrixZ ); + result.position.w = dot4( modelPosition, rpMVPmatrixW ); float4 defaultTexCoord = float4( 0.0f, 0.5f, 0.0f, 1.0f ); - //calculate vector to light in R0 - float4 toLight = rpLocalLightOrigin - vertex.position; + //calculate vector to light + float4 toLight = rpLocalLightOrigin - modelPosition; //textures 1 takes the base coordinates by the texture matrix result.texcoord1 = defaultTexCoord; @@ -79,13 +161,13 @@ void main( VS_IN vertex, out VS_OUT result ) //# texture 2 has one texgen result.texcoord2 = defaultTexCoord; - result.texcoord2.x = dot4( vertex.position, rpLightFalloffS ); + result.texcoord2.x = dot4( modelPosition, rpLightFalloffS ); //# texture 3 has three texgens - result.texcoord3.x = dot4( vertex.position, rpLightProjectionS ); - result.texcoord3.y = dot4( vertex.position, rpLightProjectionT ); + result.texcoord3.x = dot4( modelPosition, rpLightProjectionS ); + result.texcoord3.y = dot4( modelPosition, rpLightProjectionT ); result.texcoord3.z = 0.0f; - result.texcoord3.w = dot4( vertex.position, rpLightProjectionQ ); + result.texcoord3.w = dot4( modelPosition, rpLightProjectionQ ); //# textures 4 takes the base coordinates by the texture matrix result.texcoord4 = defaultTexCoord; @@ -103,20 +185,27 @@ void main( VS_IN vertex, out VS_OUT result ) toLight = normalize( toLight ); //# calculate normalized vector to viewer in R1 - float4 toView = normalize( rpLocalViewOrigin - vertex.position ); + float4 toView = normalize( rpLocalViewOrigin - modelPosition ); //# add together to become the half angle vector in object space (non-normalized) float4 halfAngleVector = toLight + toView; //# put into texture space result.texcoord6.x = dot3( tangent, halfAngleVector ); - result.texcoord6.y = dot3( binormal, halfAngleVector ); + result.texcoord6.y = dot3( bitangent, halfAngleVector ); result.texcoord6.z = dot3( normal, halfAngleVector ); result.texcoord6.w = 1.0f; +#if USE_GPU_SKINNING + // for joint transformation of the tangent space, we use color and + // color2 for weighting information, so hopefully there aren't any + // effects that need vertex color... + result.color = float4( 1.0f, 1.0f, 1.0f, 1.0f ); +#else //# generate the vertex color, which can be 1.0, color, or 1.0 - color //# for 1.0 : env[16] = 0, env[17] = 1 //# for color : env[16] = 1, env[17] = 0 //# for 1.0-color : env[16] = -1, env[17] = 1 result.color = ( swizzleColor( vertex.color ) * rpVertexColorModulate ) + rpVertexColorAdd; +#endif } \ No newline at end of file diff --git a/neo/shaders/builtin/lighting/interactionAmbient_skinned.ps.hlsl b/neo/shaders/builtin/lighting/interactionAmbient_skinned.ps.hlsl deleted file mode 100644 index 53eca4ea..00000000 --- a/neo/shaders/builtin/lighting/interactionAmbient_skinned.ps.hlsl +++ /dev/null @@ -1,104 +0,0 @@ -/* -=========================================================================== - -Doom 3 BFG Edition GPL Source Code -Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. -Copyright (C) 2013-2020 Robert Beckebans - -This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). - -Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Doom 3 BFG Edition Source Code. If not, see . - -In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. - -If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. - -=========================================================================== -*/ - -#include "global_inc.hlsl" - - -// *INDENT-OFF* -uniform sampler2D samp0 : register(s0); // texture 1 is the per-surface normal map -uniform sampler2D samp1 : register(s1); // texture 3 is the per-surface specular or roughness/metallic/AO mixer map -uniform sampler2D samp2 : register(s2); // texture 2 is the per-surface baseColor map -uniform sampler2D samp3 : register(s3); // texture 4 is the light falloff texture -uniform sampler2D samp4 : register(s4); // texture 5 is the light projection texture - -struct PS_IN { - half4 position : VPOS; - half4 texcoord1 : TEXCOORD1_centroid; - half4 texcoord2 : TEXCOORD2_centroid; - half4 texcoord3 : TEXCOORD3_centroid; - half4 texcoord4 : TEXCOORD4_centroid; - half4 texcoord5 : TEXCOORD5_centroid; - half4 texcoord6 : TEXCOORD6_centroid; - half4 color : COLOR0; -}; - -struct PS_OUT { - half4 color : COLOR; -}; -// *INDENT-ON* - -void main( PS_IN fragment, out PS_OUT result ) -{ - half4 bumpMap = tex2D( samp0, fragment.texcoord1.xy ); - half4 lightFalloff = idtex2Dproj( samp3, fragment.texcoord2 ); - half4 lightProj = idtex2Dproj( samp4, fragment.texcoord3 ); - half4 YCoCG = tex2D( samp2, fragment.texcoord4.xy ); - half4 specMapSRGB = tex2D( samp1, fragment.texcoord5.xy ); - half4 specMap = sRGBAToLinearRGBA( specMapSRGB ); - - const half3 ambientLightVector = half3( 0.5f, 9.5f - 0.385f, 0.8925f ); - half3 lightVector = normalize( ambientLightVector ); - half3 diffuseMap = sRGBToLinearRGB( ConvertYCoCgToRGB( YCoCG ) ); - - half3 localNormal; - // RB begin -#if defined(USE_NORMAL_FMT_RGB8) - localNormal.xy = bumpMap.rg - 0.5; -#else - localNormal.xy = bumpMap.wy - 0.5; -#endif - // RB end - localNormal.z = sqrt( abs( dot( localNormal.xy, localNormal.xy ) - 0.25 ) ); - localNormal = normalize( localNormal ); - - // traditional very dark Lambert light model used in Doom 3 - half ldotN = saturate( dot3( localNormal, lightVector ) ); - -#if defined(USE_HALF_LAMBERT) - // RB: http://developer.valvesoftware.com/wiki/Half_Lambert - half halfLdotN = dot3( localNormal, lightVector ) * 0.5 + 0.5; - halfLdotN *= halfLdotN; - - half lambert = halfLdotN; -#else - half lambert = ldotN; -#endif - - const half specularPower = 10.0f; - half hDotN = dot3( normalize( fragment.texcoord6.xyz ), localNormal ); - // RB: added abs - half3 specularContribution = _half3( pow( abs( hDotN ), specularPower ) ); - - half3 diffuseColor = diffuseMap * ( rpDiffuseModifier.xyz ); - half3 specularColor = specMap.xyz * specularContribution * ( rpSpecularModifier.xyz ); - half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz ); - - result.color.xyz = ( diffuseColor + specularColor ) * lightColor * fragment.color.xyz; - result.color.w = 1.0; -} diff --git a/neo/shaders/builtin/lighting/interactionAmbient_skinned.vs.hlsl b/neo/shaders/builtin/lighting/interactionAmbient_skinned.vs.hlsl deleted file mode 100644 index a179ac61..00000000 --- a/neo/shaders/builtin/lighting/interactionAmbient_skinned.vs.hlsl +++ /dev/null @@ -1,176 +0,0 @@ -/* -=========================================================================== - -Doom 3 BFG Edition GPL Source Code -Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. -Copyright (C) 2014 Robert Beckebans - -This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). - -Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Doom 3 BFG Edition Source Code. If not, see . - -In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. - -If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. - -=========================================================================== -*/ - -#include "global_inc.hlsl" - - -uniform matrices_ubo { float4 matrices[408]; }; - -// *INDENT-OFF* -struct VS_IN { - float4 position : POSITION; - float2 texcoord : TEXCOORD0; - float4 normal : NORMAL; - float4 tangent : TANGENT; - float4 color : COLOR0; - float4 color2 : COLOR1; -}; - -struct VS_OUT { - float4 position : POSITION; - float4 texcoord1 : TEXCOORD1; - float4 texcoord2 : TEXCOORD2; - float4 texcoord3 : TEXCOORD3; - float4 texcoord4 : TEXCOORD4; - float4 texcoord5 : TEXCOORD5; - float4 texcoord6 : TEXCOORD6; - float4 color : COLOR0; -}; -// *INDENT-ON* - -void main( VS_IN vertex, out VS_OUT result ) -{ - - float4 vNormal = vertex.normal * 2.0 - 1.0; - float4 vTangent = vertex.tangent * 2.0 - 1.0; - float3 vBinormal = cross( vNormal.xyz, vTangent.xyz ) * vTangent.w; - - //-------------------------------------------------------------- - // GPU transformation of the normal / binormal / bitangent - // - // multiplying with 255.1 give us the same result and is faster than floor( w * 255 + 0.5 ) - //-------------------------------------------------------------- - const float w0 = vertex.color2.x; - const float w1 = vertex.color2.y; - const float w2 = vertex.color2.z; - const float w3 = vertex.color2.w; - - float4 matX, matY, matZ; // must be float4 for vec4 - int joint = int( vertex.color.x * 255.1 * 3.0 ); - matX = matrices[int( joint + 0 )] * w0; - matY = matrices[int( joint + 1 )] * w0; - matZ = matrices[int( joint + 2 )] * w0; - - joint = int( vertex.color.y * 255.1 * 3.0 ); - matX += matrices[int( joint + 0 )] * w1; - matY += matrices[int( joint + 1 )] * w1; - matZ += matrices[int( joint + 2 )] * w1; - - joint = int( vertex.color.z * 255.1 * 3.0 ); - matX += matrices[int( joint + 0 )] * w2; - matY += matrices[int( joint + 1 )] * w2; - matZ += matrices[int( joint + 2 )] * w2; - - joint = int( vertex.color.w * 255.1 * 3.0 ); - matX += matrices[int( joint + 0 )] * w3; - matY += matrices[int( joint + 1 )] * w3; - matZ += matrices[int( joint + 2 )] * w3; - - float3 normal; - normal.x = dot3( matX, vNormal ); - normal.y = dot3( matY, vNormal ); - normal.z = dot3( matZ, vNormal ); - normal = normalize( normal ); - - float3 tangent; - tangent.x = dot3( matX, vTangent ); - tangent.y = dot3( matY, vTangent ); - tangent.z = dot3( matZ, vTangent ); - tangent = normalize( tangent ); - - float3 binormal; - binormal.x = dot3( matX, vBinormal ); - binormal.y = dot3( matY, vBinormal ); - binormal.z = dot3( matZ, vBinormal ); - binormal = normalize( binormal ); - - float4 modelPosition; - modelPosition.x = dot4( matX, vertex.position ); - modelPosition.y = dot4( matY, vertex.position ); - modelPosition.z = dot4( matZ, vertex.position ); - modelPosition.w = 1.0; - - result.position.x = dot4( modelPosition, rpMVPmatrixX ); - result.position.y = dot4( modelPosition, rpMVPmatrixY ); - result.position.z = dot4( modelPosition, rpMVPmatrixZ ); - result.position.w = dot4( modelPosition, rpMVPmatrixW ); - - float4 defaultTexCoord = float4( 0.0f, 0.5f, 0.0f, 1.0f ); - - //calculate vector to light in R0 - float4 toLight = rpLocalLightOrigin - modelPosition; - - //textures 1 takes the base coordinates by the texture matrix - result.texcoord1 = defaultTexCoord; - result.texcoord1.x = dot4( vertex.texcoord.xy, rpBumpMatrixS ); - result.texcoord1.y = dot4( vertex.texcoord.xy, rpBumpMatrixT ); - - //# texture 2 has one texgen - result.texcoord2 = defaultTexCoord; - result.texcoord2.x = dot4( modelPosition, rpLightFalloffS ); - - //# texture 3 has three texgens - result.texcoord3.x = dot4( modelPosition, rpLightProjectionS ); - result.texcoord3.y = dot4( modelPosition, rpLightProjectionT ); - result.texcoord3.z = 0.0f; - result.texcoord3.w = dot4( modelPosition, rpLightProjectionQ ); - - //# textures 4 takes the base coordinates by the texture matrix - result.texcoord4 = defaultTexCoord; - result.texcoord4.x = dot4( vertex.texcoord.xy, rpDiffuseMatrixS ); - result.texcoord4.y = dot4( vertex.texcoord.xy, rpDiffuseMatrixT ); - - //# textures 5 takes the base coordinates by the texture matrix - result.texcoord5 = defaultTexCoord; - result.texcoord5.x = dot4( vertex.texcoord.xy, rpSpecularMatrixS ); - result.texcoord5.y = dot4( vertex.texcoord.xy, rpSpecularMatrixT ); - - //# texture 6's texcoords will be the halfangle in texture space - - //# calculate normalized vector to light in R0 - toLight = normalize( toLight ); - - //# calculate normalized vector to viewer in R1 - float4 toView = normalize( rpLocalViewOrigin - modelPosition ); - - //# add together to become the half angle vector in object space (non-normalized) - float4 halfAngleVector = toLight + toView; - - //# put into texture space - result.texcoord6.x = dot3( tangent, halfAngleVector ); - result.texcoord6.y = dot3( binormal, halfAngleVector ); - result.texcoord6.z = dot3( normal, halfAngleVector ); - result.texcoord6.w = 1.0f; - - //# generate the vertex color, which can be 1.0, color, or 1.0 - color - //# for 1.0 : env[16] = 0, env[17] = 1 - //# for color : env[16] = 1, env[17] = 0 - //# for 1.0-color : env[16] = -1, env[17] = 1 - result.color = ( swizzleColor( vertex.color ) * rpVertexColorModulate ) + rpVertexColorAdd; -} \ No newline at end of file diff --git a/neo/shaders/builtin/lighting/shadow.ps.hlsl b/neo/shaders/builtin/lighting/shadow.ps.hlsl index 12f97f54..e3762cd1 100644 --- a/neo/shaders/builtin/lighting/shadow.ps.hlsl +++ b/neo/shaders/builtin/lighting/shadow.ps.hlsl @@ -30,9 +30,8 @@ If you have questions concerning this license or the applicable additional terms // *INDENT-OFF* -SamplerState samp0 : register(s0); - -struct PS_OUT { +struct PS_OUT +{ float4 color : SV_Target0; }; // *INDENT-ON* diff --git a/neo/shaders/builtin/lighting/shadow_skinned.ps.hlsl b/neo/shaders/builtin/lighting/shadow_skinned.ps.hlsl deleted file mode 100644 index f8dba170..00000000 --- a/neo/shaders/builtin/lighting/shadow_skinned.ps.hlsl +++ /dev/null @@ -1,43 +0,0 @@ -/* -=========================================================================== - -Doom 3 BFG Edition GPL Source Code -Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. - -This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). - -Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Doom 3 BFG Edition Source Code. If not, see . - -In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. - -If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. - -=========================================================================== -*/ - -#include "global_inc.hlsl" - - -// *INDENT-OFF* -SamplerState samp0 : register(s0); - -struct PS_OUT { - float4 color : COLOR; -}; -// *INDENT-ON* - -void main( out PS_OUT result ) -{ - result.color = rpColor; -} \ No newline at end of file diff --git a/neo/shaders/builtin/lighting/shadow_skinned.vs.hlsl b/neo/shaders/builtin/lighting/shadow_skinned.vs.hlsl deleted file mode 100644 index 4600dde3..00000000 --- a/neo/shaders/builtin/lighting/shadow_skinned.vs.hlsl +++ /dev/null @@ -1,96 +0,0 @@ -/* -=========================================================================== - -Doom 3 BFG Edition GPL Source Code -Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. -Coypright (C) 2014 Robert Beckebans - -This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). - -Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Doom 3 BFG Edition Source Code. If not, see . - -In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. - -If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. - -=========================================================================== -*/ - -#include "global_inc.hlsl" - - -// *INDENT-OFF* -uniform matrices_ubo { float4 matrices[408]; }; - -struct VS_IN { - float4 position : POSITION; - float4 color : COLOR0; - float4 color2 : COLOR1; -}; - -struct VS_OUT { - float4 position : POSITION; -}; -// *INDENT-ON* - -void main( VS_IN vertex, out VS_OUT result ) -{ - //-------------------------------------------------------------- - // GPU transformation of the normal / binormal / bitangent - // - // multiplying with 255.1 give us the same result and is faster than floor( w * 255 + 0.5 ) - //-------------------------------------------------------------- - const float w0 = vertex.color2.x; - const float w1 = vertex.color2.y; - const float w2 = vertex.color2.z; - const float w3 = vertex.color2.w; - - float4 matX, matY, matZ; // must be float4 for vec4 - int joint = int( vertex.color.x * 255.1 * 3.0 ); - matX = matrices[int( joint + 0 )] * w0; - matY = matrices[int( joint + 1 )] * w0; - matZ = matrices[int( joint + 2 )] * w0; - - joint = int( vertex.color.y * 255.1 * 3.0 ); - matX += matrices[int( joint + 0 )] * w1; - matY += matrices[int( joint + 1 )] * w1; - matZ += matrices[int( joint + 2 )] * w1; - - joint = int( vertex.color.z * 255.1 * 3.0 ); - matX += matrices[int( joint + 0 )] * w2; - matY += matrices[int( joint + 1 )] * w2; - matZ += matrices[int( joint + 2 )] * w2; - - joint = int( vertex.color.w * 255.1 * 3.0 ); - matX += matrices[int( joint + 0 )] * w3; - matY += matrices[int( joint + 1 )] * w3; - matZ += matrices[int( joint + 2 )] * w3; - - float4 vertexPosition = vertex.position; - vertexPosition.w = 1.0; - - float4 modelPosition; - modelPosition.x = dot4( matX, vertexPosition ); - modelPosition.y = dot4( matY, vertexPosition ); - modelPosition.z = dot4( matZ, vertexPosition ); - modelPosition.w = vertex.position.w; - - float4 vPos = modelPosition - rpLocalLightOrigin; - vPos = ( vPos.wwww * rpLocalLightOrigin ) + vPos; - - result.position.x = dot4( vPos, rpMVPmatrixX ); - result.position.y = dot4( vPos, rpMVPmatrixY ); - result.position.z = dot4( vPos, rpMVPmatrixZ ); - result.position.w = dot4( vPos, rpMVPmatrixW ); -} \ No newline at end of file diff --git a/neo/shaders/builtin/texture_color.ps.hlsl b/neo/shaders/builtin/texture_color.ps.hlsl index daee8be5..fab0c9dc 100644 --- a/neo/shaders/builtin/texture_color.ps.hlsl +++ b/neo/shaders/builtin/texture_color.ps.hlsl @@ -30,8 +30,8 @@ If you have questions concerning this license or the applicable additional terms // *INDENT-OFF* -Texture2D t_BaseColor : register( t0 ); -SamplerState s_Sampler : register( s0 ); +Texture2D t_BaseColor : register( t0 VK_DESCRIPTOR_SET( 0 ) ); +SamplerState s_Sampler : register( s0 VK_DESCRIPTOR_SET( 1 ) ); struct PS_IN { float4 position : SV_POSITION; diff --git a/neo/sys/win32/DeviceManager_DX12.cpp b/neo/sys/win32/DeviceManager_DX12.cpp index cccb510b..7fbf9b62 100644 --- a/neo/sys/win32/DeviceManager_DX12.cpp +++ b/neo/sys/win32/DeviceManager_DX12.cpp @@ -39,8 +39,6 @@ #pragma comment(lib, "d3d12.lib") #pragma comment(lib, "dxgi.lib") -idCVar r_useValidationLayers( "r_useValidationLayers", "0", CVAR_INTEGER | CVAR_INIT, "1 is just the NVRHI and 2 will turn on additional DX12, VK validation layers" ); - using nvrhi::RefCountPtr; #define HR_RETURN(hr) if(FAILED(hr)) return false @@ -100,8 +98,6 @@ protected: private: bool CreateRenderTargets(); void ReleaseRenderTargets(); - - glconfig_t config; }; static bool IsNvDeviceID( UINT id ) diff --git a/neo/sys/win32/DeviceManager_VK.cpp b/neo/sys/win32/DeviceManager_VK.cpp index b791c53c..a75d34ec 100644 --- a/neo/sys/win32/DeviceManager_VK.cpp +++ b/neo/sys/win32/DeviceManager_VK.cpp @@ -260,7 +260,27 @@ private: } } - common->Warning( "[Vulkan: location=0x%zx code=%d, layerPrefix='%s'] %s", location, code, layerPrefix, msg ); + if( flags & VK_DEBUG_REPORT_ERROR_BIT_EXT ) + { + idLib::Printf( "[Vulkan] ERROR location=0x%zx code=%d, layerPrefix='%s'] %s", location, code, layerPrefix, msg ); + } + else if( flags & VK_DEBUG_REPORT_WARNING_BIT_EXT ) + { + idLib::Printf( "[Vulkan] WARNING location=0x%zx code=%d, layerPrefix='%s'] %s", location, code, layerPrefix, msg ); + } + else if( flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT ) + { + idLib::Printf( "[Vulkan] PERFORMANCE WARNING location=0x%zx code=%d, layerPrefix='%s'] %s", location, code, layerPrefix, msg ); + } + else if( flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT ) + { + idLib::Printf( "[Vulkan] INFO location=0x%zx code=%d, layerPrefix='%s'] %s", location, code, layerPrefix, msg ); + } + else if( flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT ) + { + idLib::Printf( "[Vulkan] DEBUG location=0x%zx code=%d, layerPrefix='%s'] %s", location, code, layerPrefix, msg ); + } + return VK_FALSE; } @@ -992,6 +1012,10 @@ bool DeviceManager_VK::createSwapChain() bool DeviceManager_VK::CreateDeviceAndSwapChain() { + // RB: control these through the cmdline + deviceParms.enableNvrhiValidationLayer = r_useValidationLayers.GetInteger() > 0; + deviceParms.enableDebugRuntime = r_useValidationLayers.GetInteger() > 1; + if( deviceParms.enableDebugRuntime ) { enabledExtensions.instance.insert( "VK_EXT_debug_report" );