First time Vulkan can render a map without light interactions

This commit is contained in:
Robert Beckebans 2018-11-03 12:01:03 +01:00
parent 2f8413b2ee
commit 49eb54d1ad
12 changed files with 167 additions and 134 deletions

View file

@ -29,11 +29,11 @@ If you have questions concerning this license or the applicable additional terms
#include "global.inc.hlsl"
uniform sampler2D samp0 : register(s0); // texture 1 is the per-surface bump map
uniform sampler2D samp1 : register(s1); // texture 2 is the light falloff texture
uniform sampler2D samp2 : register(s2); // texture 3 is the light projection texture
uniform sampler2D samp3 : register(s3); // texture 4 is the per-surface diffuse map
uniform sampler2D samp4 : register(s4); // texture 5 is the per-surface specular map
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;
@ -55,8 +55,8 @@ void main( PS_IN fragment, out PS_OUT result ) {
half4 bumpMap = tex2D( samp0, fragment.texcoord1.xy );
// half4 lightFalloff = idtex2Dproj( samp1, fragment.texcoord2 );
// half4 lightProj = idtex2Dproj( samp2, fragment.texcoord3 );
half4 YCoCG = tex2D( samp3, fragment.texcoord4.xy );
half4 specMap = sRGBAToLinearRGBA( tex2D( samp4, fragment.texcoord5.xy ) );
half4 YCoCG = tex2D( samp2, fragment.texcoord4.xy );
half4 specMap = sRGBAToLinearRGBA( tex2D( samp1, fragment.texcoord5.xy ) );
half3 lightVector = normalize( fragment.texcoord0.xyz );
half3 diffuseMap = sRGBToLinearRGB( ConvertYCoCgToRGB( YCoCG ) );

View file

@ -30,11 +30,11 @@ If you have questions concerning this license or the applicable additional terms
#include "global.inc.hlsl"
#include "BRDF.inc.hlsl"
uniform sampler2D samp0 : register(s0); // texture 1 is the per-surface bump map
uniform sampler2D samp1 : register(s1); // texture 2 is the light falloff texture
uniform sampler2D samp2 : register(s2); // texture 3 is the light projection texture
uniform sampler2D samp3 : register(s3); // texture 4 is the per-surface diffuse map
uniform sampler2D samp4 : register(s4); // texture 5 is the per-surface specular map
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
{
@ -57,10 +57,10 @@ struct PS_OUT
void main( PS_IN fragment, out PS_OUT result )
{
half4 bumpMap = tex2D( samp0, fragment.texcoord1.xy );
half4 lightFalloff = ( idtex2Dproj( samp1, fragment.texcoord2 ) );
half4 lightProj = ( idtex2Dproj( samp2, fragment.texcoord3 ) );
half4 YCoCG = tex2D( samp3, fragment.texcoord4.xy );
half4 specMapSRGB = tex2D( samp4, fragment.texcoord5.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 );
half3 lightVector = normalize( fragment.texcoord0.xyz );

View file

@ -28,11 +28,11 @@ If you have questions concerning this license or the applicable additional terms
#include "global.inc.hlsl"
uniform sampler2D samp0 : register(s0); // texture 1 is the per-surface bump map
uniform sampler2D samp1 : register(s1); // texture 2 is the light falloff texture
uniform sampler2D samp2 : register(s2); // texture 3 is the light projection texture
uniform sampler2D samp3 : register(s3); // texture 4 is the per-surface diffuse map
uniform sampler2D samp4 : register(s4); // texture 5 is the per-surface specular map
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;
@ -51,10 +51,10 @@ struct PS_OUT {
void main( PS_IN fragment, out PS_OUT result ) {
half4 bumpMap = tex2D( samp0, fragment.texcoord1.xy );
half4 lightFalloff = idtex2Dproj( samp1, fragment.texcoord2 );
half4 lightProj = idtex2Dproj( samp2, fragment.texcoord3 );
half4 YCoCG = tex2D( samp3, fragment.texcoord4.xy );
half4 specMap = sRGBAToLinearRGBA( tex2D( samp4, fragment.texcoord5.xy ) );
half4 lightFalloff = idtex2Dproj( samp3, fragment.texcoord2 );
half4 lightProj = idtex2Dproj( samp4, fragment.texcoord3 );
half4 YCoCG = tex2D( samp2, fragment.texcoord4.xy );
half4 specMap = sRGBAToLinearRGBA( tex2D( samp1, fragment.texcoord5.xy ) );
const half3 ambientLightVector = half3( 0.5f, 9.5f - 0.385f, 0.8925f );
half3 lightVector = normalize( ambientLightVector );

View file

@ -29,11 +29,11 @@ If you have questions concerning this license or the applicable additional terms
#include "global.inc.hlsl"
uniform sampler2D samp0 : register(s0); // texture 1 is the per-surface bump map
uniform sampler2D samp1 : register(s1); // texture 2 is the light falloff texture
uniform sampler2D samp2 : register(s2); // texture 3 is the light projection texture
uniform sampler2D samp3 : register(s3); // texture 4 is the per-surface diffuse map
uniform sampler2D samp4 : register(s4); // texture 5 is the per-surface specular map
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;
@ -52,10 +52,10 @@ struct PS_OUT {
void main( PS_IN fragment, out PS_OUT result ) {
half4 bumpMap = tex2D( samp0, fragment.texcoord1.xy );
half4 lightFalloff = idtex2Dproj( samp1, fragment.texcoord2 );
half4 lightProj = idtex2Dproj( samp2, fragment.texcoord3 );
half4 YCoCG = tex2D( samp3, fragment.texcoord4.xy );
half4 specMap = tex2D( samp4, fragment.texcoord5.xy );
half4 lightFalloff = idtex2Dproj( samp3, fragment.texcoord2 );
half4 lightProj = idtex2Dproj( samp4, fragment.texcoord3 );
half4 YCoCG = tex2D( samp2, fragment.texcoord4.xy );
half4 specMap = tex2D( samp1, fragment.texcoord5.xy );
const half3 ambientLightVector = half3( 0.5f, 9.5f - 0.385f, 0.8925f );
half3 lightVector = normalize( ambientLightVector );

View file

@ -30,11 +30,11 @@ If you have questions concerning this license or the applicable additional terms
#include "global.inc.hlsl"
#include "BRDF.inc.hlsl"
uniform sampler2D samp0 : register(s0); // texture 1 is the per-surface bump map
uniform sampler2D samp1 : register(s1); // texture 2 is the light falloff texture
uniform sampler2D samp2 : register(s2); // texture 3 is the light projection texture
uniform sampler2D samp3 : register(s3); // texture 4 is the per-surface diffuse map
uniform sampler2D samp4 : register(s4); // texture 5 is the per-surface specular map
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
uniform sampler2DArrayShadow samp5 : register(s5); // texture 6 is the shadowmap array
uniform sampler2D samp6 : register(s6); // texture 7 is the jitter texture
@ -64,10 +64,10 @@ struct PS_OUT
void main( PS_IN fragment, out PS_OUT result )
{
half4 bumpMap = tex2D( samp0, fragment.texcoord1.xy );
half4 lightFalloff = ( idtex2Dproj( samp1, fragment.texcoord2 ) );
half4 lightProj = ( idtex2Dproj( samp2, fragment.texcoord3 ) );
half4 YCoCG = tex2D( samp3, fragment.texcoord4.xy );
half4 specMapSRGB = tex2D( samp4, fragment.texcoord5.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 );
half3 lightVector = normalize( fragment.texcoord0.xyz );

View file

@ -454,7 +454,7 @@ void R_SetupProjectionMatrix( viewDef_t* viewDef )
ymax += jittery * height;
// RB: IMPORTANT - the projectionMatrix has a few changes to make it work with Vulkan
// In Vulkan is the y-axis flipped
// for a detailed explanation see https://matthewwellings.com/blog/the-new-vulkan-coordinate-system/
viewDef->projectionMatrix[0 * 4 + 0] = 2.0f * zNear / width;
viewDef->projectionMatrix[1 * 4 + 0] = 0.0f;
@ -462,6 +462,8 @@ void R_SetupProjectionMatrix( viewDef_t* viewDef )
viewDef->projectionMatrix[3 * 4 + 0] = 0.0f;
viewDef->projectionMatrix[0 * 4 + 1] = 0.0f;
// RB: Y axis now points down the screen
#if defined(USE_VULKAN)
viewDef->projectionMatrix[1 * 4 + 1] = -2.0f * zNear / height;
#else
@ -476,7 +478,10 @@ void R_SetupProjectionMatrix( viewDef_t* viewDef )
viewDef->projectionMatrix[0 * 4 + 2] = 0.0f;
viewDef->projectionMatrix[1 * 4 + 2] = 0.0f;
viewDef->projectionMatrix[2 * 4 + 2] = -0.999f; // adjust value to prevent imprecision issues
viewDef->projectionMatrix[3 * 4 + 2] = -1.0f * zNear; // RB: was -2.0f * zNear
// RB: was -2.0f * zNear
// the transformation into window space has changed from [-1 .. -1] to [0 .. -1]
viewDef->projectionMatrix[3 * 4 + 2] = -1.0f * zNear;
viewDef->projectionMatrix[0 * 4 + 3] = 0.0f;
viewDef->projectionMatrix[1 * 4 + 3] = 0.0f;

View file

@ -4,6 +4,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2013-2014 Robert Beckebans
Copyright (C) 2016-2017 Dustin Land
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -1392,8 +1393,7 @@ idRenderModel* idRenderModelMD5::InstantiateDynamicModel( const struct renderEnt
if( staticModel->jointsInverted == NULL )
{
staticModel->numInvertedJoints = numInvertedJoints;
const int alignment = glConfig.uniformBufferOffsetAlignment;
staticModel->jointsInverted = ( idJointMat* )Mem_ClearedAlloc( ALIGN( numInvertedJoints * sizeof( idJointMat ), alignment ), TAG_JOINTMAT );
staticModel->jointsInverted = ( idJointMat* )Mem_ClearedAlloc( numInvertedJoints * sizeof( idJointMat ), TAG_JOINTMAT );
staticModel->jointsInvertedBuffer = 0;
}
else

View file

@ -530,6 +530,40 @@ void idRenderProgManager::CommitUniforms( uint64 stateBits )
//GL_CheckErrors();
}
/*
================================================================================================
idRenderProgManager::KillAllShaders()
================================================================================================
*/
void idRenderProgManager::KillAllShaders()
{
Unbind();
for( int i = 0; i < shaders.Num(); i++ )
{
if( shaders[i].progId != INVALID_PROGID )
{
glDeleteShader( shaders[i].progId );
shaders[i].progId = INVALID_PROGID;
}
}
for( int i = 0; i < renderProgs.Num(); ++i )
{
if( renderProgs[i].progId != INVALID_PROGID )
{
glDeleteProgram( renderProgs[i].progId );
renderProgs[i].progId = INVALID_PROGID;
}
}
}
/*
====================
idRenderBackend::ResizeImages
====================
*/
void idRenderBackend::ResizeImages()
{
// TODO resize framebuffers here
}

View file

@ -1195,10 +1195,10 @@ GENERAL INTERACTION RENDERING
*/
const int INTERACTION_TEXUNIT_BUMP = 0;
const int INTERACTION_TEXUNIT_FALLOFF = 1;
const int INTERACTION_TEXUNIT_PROJECTION = 2;
const int INTERACTION_TEXUNIT_DIFFUSE = 3;
const int INTERACTION_TEXUNIT_SPECULAR = 4;
const int INTERACTION_TEXUNIT_SPECULARMIX = 1;
const int INTERACTION_TEXUNIT_BASECOLOR = 2;
const int INTERACTION_TEXUNIT_FALLOFF = 3;
const int INTERACTION_TEXUNIT_PROJECTION = 4;
const int INTERACTION_TEXUNIT_SHADOWMAPS = 5;
const int INTERACTION_TEXUNIT_JITTER = 6;
@ -1318,14 +1318,14 @@ void idRenderBackend::DrawSingleInteraction( drawInteraction_t* din )
GL_SelectTexture( INTERACTION_TEXUNIT_BUMP );
din->bumpImage->Bind();
// texture 3 is the per-surface diffuse map
GL_SelectTexture( INTERACTION_TEXUNIT_DIFFUSE );
din->diffuseImage->Bind();
// texture 4 is the per-surface specular map
GL_SelectTexture( INTERACTION_TEXUNIT_SPECULAR );
// texture 1 is the per-surface specular map
GL_SelectTexture( INTERACTION_TEXUNIT_SPECULARMIX );
din->specularImage->Bind();
// texture 2 is the per-surface diffuse map
GL_SelectTexture( INTERACTION_TEXUNIT_BASECOLOR );
din->diffuseImage->Bind();
DrawElementsWithCounters( din->surf );
}
@ -1779,14 +1779,14 @@ void idRenderBackend::RenderInteractions( const drawSurf_t* surfList, const view
GL_SelectTexture( INTERACTION_TEXUNIT_BUMP );
surfaceShader->GetFastPathBumpImage()->Bind();
// texture 3 is the per-surface diffuse map
GL_SelectTexture( INTERACTION_TEXUNIT_DIFFUSE );
surfaceShader->GetFastPathDiffuseImage()->Bind();
// texture 4 is the per-surface specular map
GL_SelectTexture( INTERACTION_TEXUNIT_SPECULAR );
// texture 1 is the per-surface specular map
GL_SelectTexture( INTERACTION_TEXUNIT_SPECULARMIX );
surfaceShader->GetFastPathSpecularImage()->Bind();
// texture 2 is the per-surface diffuse map
GL_SelectTexture( INTERACTION_TEXUNIT_BASECOLOR );
surfaceShader->GetFastPathDiffuseImage()->Bind();
DrawElementsWithCounters( surf );
renderLog.CloseBlock();
@ -2160,14 +2160,14 @@ void idRenderBackend::AmbientPass( const drawSurf_t* const* drawSurfs, int numDr
GL_SelectTexture( INTERACTION_TEXUNIT_BUMP );
surfaceMaterial->GetFastPathBumpImage()->Bind();
// texture 3 is the per-surface diffuse map
GL_SelectTexture( INTERACTION_TEXUNIT_DIFFUSE );
surfaceMaterial->GetFastPathDiffuseImage()->Bind();
// texture 4 is the per-surface specular map
GL_SelectTexture( INTERACTION_TEXUNIT_SPECULAR );
// texture 1 is the per-surface specular map
GL_SelectTexture( INTERACTION_TEXUNIT_SPECULARMIX );
surfaceMaterial->GetFastPathSpecularImage()->Bind();
// texture 2 is the per-surface diffuse map
GL_SelectTexture( INTERACTION_TEXUNIT_BASECOLOR );
surfaceMaterial->GetFastPathDiffuseImage()->Bind();
DrawElementsWithCounters( drawSurf );
renderLog.CloseBlock();

View file

@ -289,62 +289,7 @@ void idRenderProgManager::LoadAllShaders()
}
}
/*
================================================================================================
idRenderProgManager::KillAllShaders()
================================================================================================
*/
void idRenderProgManager::KillAllShaders()
{
Unbind();
// destroy shaders
for( int i = 0; i < shaders.Num(); ++i )
{
shader_t& shader = shaders[ i ];
vkDestroyShaderModule( vkcontext.device, shader.module, NULL );
shader.module = VK_NULL_HANDLE;
}
// destroy pipelines
for( int i = 0; i < renderProgs.Num(); ++i )
{
renderProg_t& prog = renderProgs[ i ];
for( int j = 0; j < prog.pipelines.Num(); ++j )
{
vkDestroyPipeline( vkcontext.device, prog.pipelines[ j ].pipeline, NULL );
}
prog.pipelines.Clear();
vkDestroyDescriptorSetLayout( vkcontext.device, prog.descriptorSetLayout, NULL );
vkDestroyPipelineLayout( vkcontext.device, prog.pipelineLayout, NULL );
}
renderProgs.Clear();
for( int i = 0; i < NUM_FRAME_DATA; ++i )
{
parmBuffers[ i ]->FreeBufferObject();
delete parmBuffers[ i ];
parmBuffers[ i ] = NULL;
}
emptyUBO.FreeBufferObject();
for( int i = 0; i < NUM_FRAME_DATA; ++i )
{
//vkFreeDescriptorSets( vkcontext.device, descriptorPools[ i ], MAX_DESC_SETS, descriptorSets[ i ] );
vkResetDescriptorPool( vkcontext.device, descriptorPools[ i ], 0 );
vkDestroyDescriptorPool( vkcontext.device, descriptorPools[ i ], NULL );
}
memset( descriptorSets, 0, sizeof( descriptorSets ) );
memset( descriptorPools, 0, sizeof( descriptorPools ) );
counter = 0;
currentData = 0;
currentDescSet = 0;
}
/*
================================================================================================

View file

@ -1490,7 +1490,6 @@ void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf )
// RB: yes but it would require an additional blend light skinned shader
//if( !verify( renderProgManager.ShaderUsesJoints() ) )
if( !renderProgManager.ShaderUsesJoints() )
// DG end
{
return;
}
@ -1512,12 +1511,6 @@ void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf )
idLib::Warning( "RB_DrawElementsWithCounters, jointBuffer == NULL" );
return;
}
assert( ( jointBuffer.GetOffset() & ( glConfig.uniformBufferOffsetAlignment - 1 ) ) == 0 );
// FIXME
//const GLintptr ubo = jointBuffer.GetAPIObject();
//glBindBufferRange( GL_UNIFORM_BUFFER, 0, ubo, jointBuffer.GetOffset(), jointBuffer.GetSize() );
}
renderProgManager.CommitUniforms( glStateBits );

View file

@ -770,6 +770,62 @@ void idRenderProgManager::LoadGLSLProgram( const int programIndex, const int ver
#endif
}
/*
================================================================================================
idRenderProgManager::KillAllShaders()
================================================================================================
*/
void idRenderProgManager::KillAllShaders()
{
Unbind();
// destroy shaders
for( int i = 0; i < shaders.Num(); ++i )
{
shader_t& shader = shaders[ i ];
vkDestroyShaderModule( vkcontext.device, shader.module, NULL );
shader.module = VK_NULL_HANDLE;
}
// destroy pipelines
for( int i = 0; i < renderProgs.Num(); ++i )
{
renderProg_t& prog = renderProgs[ i ];
for( int j = 0; j < prog.pipelines.Num(); ++j )
{
vkDestroyPipeline( vkcontext.device, prog.pipelines[ j ].pipeline, NULL );
}
prog.pipelines.Clear();
vkDestroyDescriptorSetLayout( vkcontext.device, prog.descriptorSetLayout, NULL );
vkDestroyPipelineLayout( vkcontext.device, prog.pipelineLayout, NULL );
}
renderProgs.Clear();
for( int i = 0; i < NUM_FRAME_DATA; ++i )
{
parmBuffers[ i ]->FreeBufferObject();
delete parmBuffers[ i ];
parmBuffers[ i ] = NULL;
}
emptyUBO.FreeBufferObject();
for( int i = 0; i < NUM_FRAME_DATA; ++i )
{
//vkFreeDescriptorSets( vkcontext.device, descriptorPools[ i ], MAX_DESC_SETS, descriptorSets[ i ] );
vkResetDescriptorPool( vkcontext.device, descriptorPools[ i ], 0 );
vkDestroyDescriptorPool( vkcontext.device, descriptorPools[ i ], NULL );
}
memset( descriptorSets, 0, sizeof( descriptorSets ) );
memset( descriptorPools, 0, sizeof( descriptorPools ) );
counter = 0;
currentData = 0;
currentDescSet = 0;
}
/*
========================