Dynamic lights.

This commit is contained in:
Artem Kharytoniuk 2017-04-29 15:44:26 +03:00
parent 8f51dbbc78
commit 9dd144766e
3 changed files with 33 additions and 11 deletions

View File

@ -248,8 +248,6 @@ static void ProjectDlightTexture( void ) {
float *texCoords;
byte *colors;
byte clipBits[SHADER_MAX_VERTEXES];
MAC_STATIC float texCoordsArray[SHADER_MAX_VERTEXES][2];
byte colorArray[SHADER_MAX_VERTEXES][4];
unsigned hitIndexes[SHADER_MAX_INDEXES];
int numIndexes;
float scale;
@ -267,8 +265,8 @@ static void ProjectDlightTexture( void ) {
if ( !( tess.dlightBits & ( 1 << l ) ) ) {
continue; // this surface definately doesn't have any of this light
}
texCoords = texCoordsArray[0];
colors = colorArray[0];
texCoords = tess.svars.texcoords[0][0];
colors = tess.svars.colors[0];
dl = &backEnd.refdef.dlights[l];
VectorCopy( dl->transformed, origin );
@ -345,10 +343,10 @@ static void ProjectDlightTexture( void ) {
}
qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
qglTexCoordPointer( 2, GL_FLOAT, 0, texCoordsArray[0] );
qglTexCoordPointer( 2, GL_FLOAT, 0, tess.svars.texcoords[0] );
qglEnableClientState( GL_COLOR_ARRAY );
qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorArray );
qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, tess.svars.colors );
GL_Bind( tr.dlightImage );
// include GLS_DEPTHFUNC_EQUAL so alpha tested surfaces don't add light
@ -362,6 +360,12 @@ static void ProjectDlightTexture( void ) {
R_DrawElements( numIndexes, hitIndexes );
backEnd.pc.c_totalIndexes += numIndexes;
backEnd.pc.c_dlightIndexes += numIndexes;
// VULKAN
VkPipeline pipeline = vk.dlight_pipelines[dl->additive > 0 ? 1 : 0][tess.shader->cullType][tess.shader->polygonOffset];
vk_bind_stage_specific_resources(pipeline, false, false);
vkCmdDrawIndexed(vk.command_buffer, tess.numIndexes, 1, 0, 0, 0);
glState.vk_dirty_attachments = true;
}
}

View File

@ -880,31 +880,42 @@ void vk_create_instance(HWND hwnd) {
vk.skybox_pipeline = create_pipeline(def);
}
// fog
// fog and dlights
{
Vk_Pipeline_Def def;
def.shader_type = Vk_Shader_Type::single_texture;
def.clipping_plane = false;
def.mirror = false;
unsigned int state_bits[2] = {
unsigned int fog_state_bits[2] = {
GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA | GLS_DEPTHFUNC_EQUAL,
GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA
};
unsigned int dlight_state_bits[2] = {
GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL,
GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL
};
bool polygon_offset[2] = {false, true};
for (int i = 0; i < 2; i++) {
def.state_bits = state_bits[i];
unsigned fog_state = fog_state_bits[i];
unsigned dlight_state = dlight_state_bits[i];
for (int j = 0; j < 3; j++) {
def.face_culling = j; // cullType_t value
for (int k = 0; k < 2; k++) {
def.polygon_offset = polygon_offset[k];
def.state_bits = fog_state;
vk.fog_pipelines[i][j][k] = create_pipeline(def);
def.state_bits = dlight_state;
vk.dlight_pipelines[i][j][k] = create_pipeline(def);
}
}
}
}
}
}
@ -947,8 +958,10 @@ void vk_destroy_instance() {
vkDestroyPipeline(vk.device, vk.skybox_pipeline, nullptr);
for (int i = 0; i < 2; i++)
for (int j = 0; j < 3; j++)
for (int k = 0; k < 2; k++)
for (int k = 0; k < 2; k++) {
vkDestroyPipeline(vk.device, vk.fog_pipelines[i][j][k], nullptr);
vkDestroyPipeline(vk.device, vk.dlight_pipelines[i][j][k], nullptr);
}
vkDestroySwapchainKHR(vk.device, vk.swapchain, nullptr);
vkDestroyDevice(vk.device, nullptr);

View File

@ -138,6 +138,11 @@ struct Vk_Instance {
// dim 1 is directly a cullType_t enum value.
// dim 2 is a polygon offset value (0 - off, 1 - on).
VkPipeline fog_pipelines[2][3][2];
// dim 0 is based on dlight additive flag: 0 - not additive, 1 - additive
// dim 1 is directly a cullType_t enum value.
// dim 2 is a polygon offset value (0 - off, 1 - on).
VkPipeline dlight_pipelines[2][3][2];
};
struct Vk_Resources {