mirror of
https://github.com/jmarshall23/DoomRTX.git
synced 2026-08-12 08:11:10 +02:00
1676 lines
49 KiB
C++
1676 lines
49 KiB
C++
/*
|
|
===========================================================================
|
|
|
|
IceTech GPL Source Code
|
|
Copyright (C) 2026 Justin Marshall
|
|
|
|
This file is part of the IceTech GPL Source Code (?IceTech Source Code?).
|
|
|
|
IceTech 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.
|
|
|
|
IceTech 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 IceTech Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
In addition, the IceTech 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 IceTech 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 Justin Marshall, justinmarshall20@gmail.com
|
|
|
|
===========================================================================
|
|
*/
|
|
#include "precompiled.h"
|
|
#pragma hdrstop
|
|
|
|
#include "tr_local.h"
|
|
|
|
idCVar r_renderNeuralMaterial("r_renderNeuralMaterial", "0", CVAR_BOOL, "");
|
|
|
|
static idDrawVert *RB_BindAmbientBuffer( const srfTriangles_t *tri ) {
|
|
if ( tri->ambientVbo ) {
|
|
glBindBufferARB( GL_ARRAY_BUFFER_ARB, tri->ambientVbo );
|
|
return (idDrawVert *)0;
|
|
}
|
|
return (idDrawVert *)vertexCache.Position( tri->ambientCache );
|
|
}
|
|
|
|
/*
|
|
=====================
|
|
RB_BakeTextureMatrixIntoTexgen
|
|
=====================
|
|
*/
|
|
void RB_BakeTextureMatrixIntoTexgen( idPlane lightProject[3], const float *textureMatrix ) {
|
|
float genMatrix[16];
|
|
float final[16];
|
|
|
|
genMatrix[0] = lightProject[0][0];
|
|
genMatrix[4] = lightProject[0][1];
|
|
genMatrix[8] = lightProject[0][2];
|
|
genMatrix[12] = lightProject[0][3];
|
|
|
|
genMatrix[1] = lightProject[1][0];
|
|
genMatrix[5] = lightProject[1][1];
|
|
genMatrix[9] = lightProject[1][2];
|
|
genMatrix[13] = lightProject[1][3];
|
|
|
|
genMatrix[2] = 0;
|
|
genMatrix[6] = 0;
|
|
genMatrix[10] = 0;
|
|
genMatrix[14] = 0;
|
|
|
|
genMatrix[3] = lightProject[2][0];
|
|
genMatrix[7] = lightProject[2][1];
|
|
genMatrix[11] = lightProject[2][2];
|
|
genMatrix[15] = lightProject[2][3];
|
|
|
|
myGlMultMatrix( genMatrix, backEnd.lightTextureMatrix, final );
|
|
|
|
lightProject[0][0] = final[0];
|
|
lightProject[0][1] = final[4];
|
|
lightProject[0][2] = final[8];
|
|
lightProject[0][3] = final[12];
|
|
|
|
lightProject[1][0] = final[1];
|
|
lightProject[1][1] = final[5];
|
|
lightProject[1][2] = final[9];
|
|
lightProject[1][3] = final[13];
|
|
}
|
|
|
|
/*
|
|
================
|
|
RB_PrepareStageTexturing
|
|
================
|
|
*/
|
|
void RB_PrepareStageTexturing( const shaderStage_t *pStage, const drawSurf_t *surf, idDrawVert *ac ) {
|
|
// set privatePolygonOffset if necessary
|
|
if ( pStage->privatePolygonOffset ) {
|
|
glEnable( GL_POLYGON_OFFSET_FILL );
|
|
glPolygonOffset( r_offsetFactor.GetFloat(), r_offsetUnits.GetFloat() * pStage->privatePolygonOffset );
|
|
}
|
|
|
|
// set the texture matrix if needed
|
|
if ( pStage->texture.hasMatrix ) {
|
|
RB_LoadShaderTextureMatrix( surf->shaderRegisters, &pStage->texture );
|
|
}
|
|
|
|
// texgens
|
|
if ( pStage->texture.texgen == TG_DIFFUSE_CUBE ) {
|
|
glTexCoordPointer( 3, GL_FLOAT, sizeof( idDrawVert ), ac->normal.ToFloatPtr() );
|
|
}
|
|
if ( pStage->texture.texgen == TG_SKYBOX_CUBE || pStage->texture.texgen == TG_WOBBLESKY_CUBE ) {
|
|
glTexCoordPointer( 3, GL_FLOAT, 0, vertexCache.Position( surf->dynamicTexCoords ) );
|
|
}
|
|
if ( pStage->texture.texgen == TG_SCREEN ) {
|
|
glEnable( GL_TEXTURE_GEN_S );
|
|
glEnable( GL_TEXTURE_GEN_T );
|
|
glEnable( GL_TEXTURE_GEN_Q );
|
|
|
|
float mat[16], plane[4];
|
|
myGlMultMatrix( surf->space->modelViewMatrix, backEnd.viewDef->projectionMatrix, mat );
|
|
|
|
plane[0] = mat[0];
|
|
plane[1] = mat[4];
|
|
plane[2] = mat[8];
|
|
plane[3] = mat[12];
|
|
glTexGenfv( GL_S, GL_OBJECT_PLANE, plane );
|
|
|
|
plane[0] = mat[1];
|
|
plane[1] = mat[5];
|
|
plane[2] = mat[9];
|
|
plane[3] = mat[13];
|
|
glTexGenfv( GL_T, GL_OBJECT_PLANE, plane );
|
|
|
|
plane[0] = mat[3];
|
|
plane[1] = mat[7];
|
|
plane[2] = mat[11];
|
|
plane[3] = mat[15];
|
|
glTexGenfv( GL_Q, GL_OBJECT_PLANE, plane );
|
|
}
|
|
|
|
if ( pStage->texture.texgen == TG_SCREEN2 ) {
|
|
glEnable( GL_TEXTURE_GEN_S );
|
|
glEnable( GL_TEXTURE_GEN_T );
|
|
glEnable( GL_TEXTURE_GEN_Q );
|
|
|
|
float mat[16], plane[4];
|
|
myGlMultMatrix( surf->space->modelViewMatrix, backEnd.viewDef->projectionMatrix, mat );
|
|
|
|
plane[0] = mat[0];
|
|
plane[1] = mat[4];
|
|
plane[2] = mat[8];
|
|
plane[3] = mat[12];
|
|
glTexGenfv( GL_S, GL_OBJECT_PLANE, plane );
|
|
|
|
plane[0] = mat[1];
|
|
plane[1] = mat[5];
|
|
plane[2] = mat[9];
|
|
plane[3] = mat[13];
|
|
glTexGenfv( GL_T, GL_OBJECT_PLANE, plane );
|
|
|
|
plane[0] = mat[3];
|
|
plane[1] = mat[7];
|
|
plane[2] = mat[11];
|
|
plane[3] = mat[15];
|
|
glTexGenfv( GL_Q, GL_OBJECT_PLANE, plane );
|
|
}
|
|
|
|
if ( pStage->texture.texgen == TG_GLASSWARP ) {
|
|
if ( tr.backEndRenderer == BE_ARB2 /*|| tr.backEndRenderer == BE_NV30*/ ) {
|
|
glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, FPROG_GLASSWARP );
|
|
glEnable( GL_FRAGMENT_PROGRAM_ARB );
|
|
|
|
GL_SelectTexture( 2 );
|
|
globalImages->scratchImage->Bind();
|
|
|
|
GL_SelectTexture( 1 );
|
|
globalImages->scratchImage2->Bind();
|
|
|
|
glEnable( GL_TEXTURE_GEN_S );
|
|
glEnable( GL_TEXTURE_GEN_T );
|
|
glEnable( GL_TEXTURE_GEN_Q );
|
|
|
|
float mat[16], plane[4];
|
|
myGlMultMatrix( surf->space->modelViewMatrix, backEnd.viewDef->projectionMatrix, mat );
|
|
|
|
plane[0] = mat[0];
|
|
plane[1] = mat[4];
|
|
plane[2] = mat[8];
|
|
plane[3] = mat[12];
|
|
glTexGenfv( GL_S, GL_OBJECT_PLANE, plane );
|
|
|
|
plane[0] = mat[1];
|
|
plane[1] = mat[5];
|
|
plane[2] = mat[9];
|
|
plane[3] = mat[13];
|
|
glTexGenfv( GL_T, GL_OBJECT_PLANE, plane );
|
|
|
|
plane[0] = mat[3];
|
|
plane[1] = mat[7];
|
|
plane[2] = mat[11];
|
|
plane[3] = mat[15];
|
|
glTexGenfv( GL_Q, GL_OBJECT_PLANE, plane );
|
|
|
|
GL_SelectTexture( 0 );
|
|
}
|
|
}
|
|
|
|
if ( pStage->texture.texgen == TG_REFLECT_CUBE ) {
|
|
if ( tr.backEndRenderer == BE_ARB2 ) {
|
|
// see if there is also a bump map specified
|
|
const shaderStage_t *bumpStage = surf->material->GetBumpStage();
|
|
if ( bumpStage ) {
|
|
// per-pixel reflection mapping with bump mapping
|
|
GL_SelectTexture( 1 );
|
|
bumpStage->texture.image->Bind();
|
|
GL_SelectTexture( 0 );
|
|
|
|
glNormalPointer( GL_FLOAT, sizeof( idDrawVert ), ac->normal.ToFloatPtr() );
|
|
glVertexAttribPointerARB( 10, 3, GL_FLOAT, false, sizeof( idDrawVert ), ac->tangents[1].ToFloatPtr() );
|
|
glVertexAttribPointerARB( 9, 3, GL_FLOAT, false, sizeof( idDrawVert ), ac->tangents[0].ToFloatPtr() );
|
|
|
|
glEnableVertexAttribArrayARB( 9 );
|
|
glEnableVertexAttribArrayARB( 10 );
|
|
glEnableClientState( GL_NORMAL_ARRAY );
|
|
|
|
// Program env 5, 6, 7, 8 have been set in RB_SetProgramEnvironmentSpace
|
|
|
|
glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, FPROG_BUMPY_ENVIRONMENT );
|
|
glEnable( GL_FRAGMENT_PROGRAM_ARB );
|
|
glBindProgramARB( GL_VERTEX_PROGRAM_ARB, VPROG_BUMPY_ENVIRONMENT );
|
|
glEnable( GL_VERTEX_PROGRAM_ARB );
|
|
} else {
|
|
// per-pixel reflection mapping without a normal map
|
|
glNormalPointer( GL_FLOAT, sizeof( idDrawVert ), ac->normal.ToFloatPtr() );
|
|
glEnableClientState( GL_NORMAL_ARRAY );
|
|
|
|
glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, FPROG_ENVIRONMENT );
|
|
glEnable( GL_FRAGMENT_PROGRAM_ARB );
|
|
glBindProgramARB( GL_VERTEX_PROGRAM_ARB, VPROG_ENVIRONMENT );
|
|
glEnable( GL_VERTEX_PROGRAM_ARB );
|
|
}
|
|
} else {
|
|
glEnable( GL_TEXTURE_GEN_S );
|
|
glEnable( GL_TEXTURE_GEN_T );
|
|
glEnable( GL_TEXTURE_GEN_R );
|
|
glTexGenf( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT );
|
|
glTexGenf( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT );
|
|
glTexGenf( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT );
|
|
glEnableClientState( GL_NORMAL_ARRAY );
|
|
glNormalPointer( GL_FLOAT, sizeof( idDrawVert ), ac->normal.ToFloatPtr() );
|
|
|
|
glMatrixMode( GL_TEXTURE );
|
|
float mat[16];
|
|
|
|
R_TransposeGLMatrix( backEnd.viewDef->worldSpace.modelViewMatrix, mat );
|
|
|
|
glLoadMatrixf( mat );
|
|
glMatrixMode( GL_MODELVIEW );
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
================
|
|
RB_FinishStageTexturing
|
|
================
|
|
*/
|
|
void RB_FinishStageTexturing( const shaderStage_t *pStage, const drawSurf_t *surf, idDrawVert *ac ) {
|
|
// unset privatePolygonOffset if necessary
|
|
if ( pStage->privatePolygonOffset && !surf->material->TestMaterialFlag(MF_POLYGONOFFSET) ) {
|
|
glDisable( GL_POLYGON_OFFSET_FILL );
|
|
}
|
|
|
|
if ( pStage->texture.texgen == TG_DIFFUSE_CUBE || pStage->texture.texgen == TG_SKYBOX_CUBE
|
|
|| pStage->texture.texgen == TG_WOBBLESKY_CUBE ) {
|
|
glTexCoordPointer( 2, GL_FLOAT, sizeof( idDrawVert ), (void *)&ac->st );
|
|
}
|
|
|
|
if ( pStage->texture.texgen == TG_SCREEN ) {
|
|
glDisable( GL_TEXTURE_GEN_S );
|
|
glDisable( GL_TEXTURE_GEN_T );
|
|
glDisable( GL_TEXTURE_GEN_Q );
|
|
}
|
|
if ( pStage->texture.texgen == TG_SCREEN2 ) {
|
|
glDisable( GL_TEXTURE_GEN_S );
|
|
glDisable( GL_TEXTURE_GEN_T );
|
|
glDisable( GL_TEXTURE_GEN_Q );
|
|
}
|
|
|
|
if ( pStage->texture.texgen == TG_GLASSWARP ) {
|
|
if ( tr.backEndRenderer == BE_ARB2 /*|| tr.backEndRenderer == BE_NV30*/ ) {
|
|
GL_SelectTexture( 2 );
|
|
globalImages->BindNull();
|
|
|
|
GL_SelectTexture( 1 );
|
|
if ( pStage->texture.hasMatrix ) {
|
|
RB_LoadShaderTextureMatrix( surf->shaderRegisters, &pStage->texture );
|
|
}
|
|
glDisable( GL_TEXTURE_GEN_S );
|
|
glDisable( GL_TEXTURE_GEN_T );
|
|
glDisable( GL_TEXTURE_GEN_Q );
|
|
glDisable( GL_FRAGMENT_PROGRAM_ARB );
|
|
globalImages->BindNull();
|
|
GL_SelectTexture( 0 );
|
|
}
|
|
}
|
|
|
|
if ( pStage->texture.texgen == TG_REFLECT_CUBE ) {
|
|
if ( tr.backEndRenderer == BE_ARB2 ) {
|
|
// see if there is also a bump map specified
|
|
const shaderStage_t *bumpStage = surf->material->GetBumpStage();
|
|
if ( bumpStage ) {
|
|
// per-pixel reflection mapping with bump mapping
|
|
GL_SelectTexture( 1 );
|
|
globalImages->BindNull();
|
|
GL_SelectTexture( 0 );
|
|
|
|
glDisableVertexAttribArrayARB( 9 );
|
|
glDisableVertexAttribArrayARB( 10 );
|
|
} else {
|
|
// per-pixel reflection mapping without bump mapping
|
|
}
|
|
|
|
glDisableClientState( GL_NORMAL_ARRAY );
|
|
glDisable( GL_FRAGMENT_PROGRAM_ARB );
|
|
glDisable( GL_VERTEX_PROGRAM_ARB );
|
|
// Fixme: Hack to get around an apparent bug in ATI drivers. Should remove as soon as it gets fixed.
|
|
glBindProgramARB( GL_VERTEX_PROGRAM_ARB, 0 );
|
|
} else {
|
|
glDisable( GL_TEXTURE_GEN_S );
|
|
glDisable( GL_TEXTURE_GEN_T );
|
|
glDisable( GL_TEXTURE_GEN_R );
|
|
glTexGenf( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
|
|
glTexGenf( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
|
|
glTexGenf( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
|
|
glDisableClientState( GL_NORMAL_ARRAY );
|
|
|
|
glMatrixMode( GL_TEXTURE );
|
|
glLoadIdentity();
|
|
glMatrixMode( GL_MODELVIEW );
|
|
}
|
|
}
|
|
|
|
if ( pStage->texture.hasMatrix ) {
|
|
glMatrixMode( GL_TEXTURE );
|
|
glLoadIdentity();
|
|
glMatrixMode( GL_MODELVIEW );
|
|
}
|
|
}
|
|
|
|
/*
|
|
=============================================================================================
|
|
|
|
FILL DEPTH BUFFER
|
|
|
|
=============================================================================================
|
|
*/
|
|
|
|
/*
|
|
==================
|
|
RB_T_FillDepthBuffer
|
|
==================
|
|
*/
|
|
void RB_T_FillDepthBuffer(const drawSurf_t* surf) {
|
|
int stage;
|
|
const idMaterial* shader;
|
|
const shaderStage_t* pStage;
|
|
const float* regs;
|
|
float color[4];
|
|
const srfTriangles_t* tri;
|
|
|
|
tri = surf->geo;
|
|
shader = surf->material;
|
|
|
|
if ( r_screenSpaceParticles.GetBool() && ( surf->dsFlags & DSF_SCREEN_SPACE_PARTICLE ) ) {
|
|
return;
|
|
}
|
|
|
|
// update the clip plane if needed
|
|
if (backEnd.viewDef->numClipPlanes && surf->space != backEnd.currentSpace) {
|
|
GL_SelectTexture(1);
|
|
|
|
idPlane plane;
|
|
|
|
R_GlobalPlaneToLocal(surf->space->modelMatrix, backEnd.viewDef->clipPlanes[0], plane);
|
|
plane[3] += 0.5f; // the notch is in the middle
|
|
glTexGenfv(GL_S, GL_OBJECT_PLANE, plane.ToFloatPtr());
|
|
|
|
GL_SelectTexture(0);
|
|
}
|
|
|
|
glLoadModelMatrixf(surf->space->modelMatrix);
|
|
|
|
if (!shader->IsDrawn()) {
|
|
return;
|
|
}
|
|
|
|
// some deforms may disable themselves by setting numIndexes = 0
|
|
if (!tri->numIndexes) {
|
|
return;
|
|
}
|
|
|
|
// translucent surfaces don't put anything in the depth buffer and don't
|
|
// test against it, which makes them fail the mirror clip plane operation
|
|
if (shader->Coverage() == MC_TRANSLUCENT) {
|
|
return;
|
|
}
|
|
|
|
if (!tri->ambientVbo && !tri->ambientCache) {
|
|
common->Printf("RB_T_FillDepthBuffer: !tri->ambientCache\n");
|
|
return;
|
|
}
|
|
|
|
// get the expressions for conditionals / color / texcoords
|
|
regs = surf->shaderRegisters;
|
|
|
|
// if all stages of a material have been conditioned off, don't do anything
|
|
pStage = nullptr;
|
|
for (stage = 0; stage < shader->GetNumStages(); stage++) {
|
|
pStage = shader->GetStage(stage);
|
|
|
|
// check the stage enable condition
|
|
if (regs[pStage->conditionRegister] != 0.0f) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (stage == shader->GetNumStages()) {
|
|
return;
|
|
}
|
|
|
|
// set polygon offset if necessary
|
|
if (shader->TestMaterialFlag(MF_POLYGONOFFSET)) {
|
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
|
glPolygonOffset(r_offsetFactor.GetFloat(), r_offsetUnits.GetFloat() * shader->GetPolygonOffset());
|
|
}
|
|
|
|
// subviews will just down-modulate the color buffer by overbright
|
|
if (shader->GetSort() == SS_SUBVIEW) {
|
|
GL_State(GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO | GLS_DEPTHFUNC_LESS);
|
|
|
|
color[0] =
|
|
color[1] =
|
|
color[2] = (1.0f / backEnd.overBright);
|
|
color[3] = 1.0f;
|
|
}
|
|
else {
|
|
// others just draw black
|
|
color[0] = 0.0f;
|
|
color[1] = 0.0f;
|
|
color[2] = 0.0f;
|
|
color[3] = 1.0f;
|
|
}
|
|
|
|
idDrawVert* ac = RB_BindAmbientBuffer(tri);
|
|
|
|
glVertexPointer(3, GL_FLOAT, sizeof(idDrawVert), ac->xyz.ToFloatPtr());
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(idDrawVert), reinterpret_cast<void*>(&ac->st));
|
|
glNormalPointer(GL_FLOAT, sizeof(idDrawVert), ac->normal.ToFloatPtr());
|
|
glTangentPointer(GL_FLOAT, sizeof(idDrawVert), ac->tangents[0].ToFloatPtr());
|
|
glBinormalPointer(GL_FLOAT, sizeof(idDrawVert), ac->tangents[1].ToFloatPtr());
|
|
|
|
glEnableClientState(GL_NORMAL_ARRAY);
|
|
glEnableClientState(GL_TANGENT_ARRAY_QD3D12);
|
|
glEnableClientState(GL_BINORMAL_ARRAY_QD3D12);
|
|
|
|
bool drawSolid = true;
|
|
bool alphaTestWasEnabled = false;
|
|
|
|
// draw the entire surface solid
|
|
if (drawSolid && !shader->IsSky() && (shader->Coverage() == MC_PERFORATED || shader->Coverage() == MC_OPAQUE)) {
|
|
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
if (shader->Coverage() == MC_PERFORATED) {
|
|
for (stage = 0; stage < shader->GetNumStages(); stage++) {
|
|
pStage = shader->GetStage(stage);
|
|
|
|
if (regs[pStage->conditionRegister] == 0.0f) {
|
|
continue;
|
|
}
|
|
|
|
if (!pStage->hasAlphaTest) {
|
|
continue;
|
|
}
|
|
|
|
// set the alpha modulate
|
|
color[0] = 1.0f;
|
|
color[1] = 1.0f;
|
|
color[2] = 1.0f;
|
|
color[3] = regs[pStage->color.registers[3]];
|
|
|
|
glColor4fv(color);
|
|
glDisable(GL_BLEND);
|
|
glEnable(GL_ALPHA_TEST);
|
|
glAlphaFunc(GL_GREATER, regs[pStage->alphaTestRegister]);
|
|
|
|
alphaTestWasEnabled = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
idImage* diffuseImage = shader->GetDiffuseImage(regs);
|
|
idImage* bumpImage = shader->GetBumpImage();
|
|
idImage* specImage = shader->GetSpecImage();
|
|
idImage* glowMapImage = shader->GetGlowImage(regs);
|
|
|
|
// Make sure the material has tried to load/upload its NeuralPOM payload.
|
|
// If no neural files exist, this should leave the handle as 0.
|
|
const GLuint neuralPOMHandle = shader->GetNeuralPOMGLHandle();
|
|
|
|
// diffuse/albedo fallback
|
|
GL_SelectTexture(0);
|
|
glEnable(GL_TEXTURE_2D);
|
|
if (diffuseImage) {
|
|
diffuseImage->Bind();
|
|
}
|
|
else {
|
|
globalImages->BindNull();
|
|
}
|
|
|
|
// normal map fallback + NeuralPOM material override
|
|
GL_SelectTexture(1);
|
|
glEnable(GL_TEXTURE_2D);
|
|
if (bumpImage) {
|
|
bumpImage->Bind();
|
|
glBindNormalMapTexture(bumpImage->texnum);
|
|
}
|
|
else {
|
|
globalImages->BindNull();
|
|
glBindNormalMapTexture(0);
|
|
}
|
|
|
|
// If neuralPOMHandle != 0, the shim evaluates the neural material on GPU.
|
|
// If neuralPOMHandle == 0, the shim falls back to normal old POM/normal-map sampling.
|
|
if (r_renderNeuralMaterial.GetBool())
|
|
{
|
|
glBindNeuralPOMTextureQD3D12(neuralPOMHandle);
|
|
}
|
|
else
|
|
{
|
|
glBindNeuralPOMTextureQD3D12(0);
|
|
}
|
|
|
|
// specular fallback
|
|
GL_SelectTexture(2);
|
|
glEnable(GL_TEXTURE_2D);
|
|
if (specImage) {
|
|
specImage->Bind();
|
|
glBindSpecularMapTexture(specImage->texnum);
|
|
}
|
|
else {
|
|
globalImages->BindNull();
|
|
glBindSpecularMapTexture(0);
|
|
}
|
|
|
|
// glow fallback
|
|
if (glowMapImage) {
|
|
GL_SelectTexture(3);
|
|
glEnable(GL_TEXTURE_2D);
|
|
glowMapImage->Bind();
|
|
glBindGlowMapTexture(glowMapImage->texnum);
|
|
glGlowMapStrengthf(0.5f);
|
|
}
|
|
|
|
if (!surf->geo->isSkeletal) {
|
|
glGeometryFlagf(GEOMETRY_FLAG_NONE);
|
|
}
|
|
else {
|
|
glGeometryFlagf(GEOMETRY_FLAG_SKELETAL);
|
|
}
|
|
|
|
// set texture matrix and texGens. The Quake 4 path needs to know this is a depth fill.
|
|
RB_PrepareStageTexturing(pStage, surf, ac);
|
|
|
|
// draw it
|
|
RB_DrawElementsWithCounters(tri);
|
|
|
|
//RB_FinishStageTexturing(pStage, surf, ac);
|
|
|
|
if (glowMapImage) {
|
|
GL_SelectTexture(3);
|
|
glBindGlowMapTexture(0);
|
|
globalImages->BindNull();
|
|
}
|
|
|
|
GL_SelectTexture(2);
|
|
glBindSpecularMapTexture(0);
|
|
globalImages->BindNull();
|
|
|
|
GL_SelectTexture(1);
|
|
glBindNeuralPOMTextureQD3D12(0);
|
|
glBindNormalMapTexture(0);
|
|
globalImages->BindNull();
|
|
|
|
GL_SelectTexture(0);
|
|
globalImages->BindNull();
|
|
|
|
if (alphaTestWasEnabled) {
|
|
glDisable(GL_ALPHA_TEST);
|
|
glEnable(GL_BLEND);
|
|
|
|
color[0] = 1.0f;
|
|
color[1] = 1.0f;
|
|
color[2] = 1.0f;
|
|
color[3] = 1.0f;
|
|
|
|
glColor4fv(color);
|
|
}
|
|
}
|
|
|
|
// reset polygon offset
|
|
if (shader->TestMaterialFlag(MF_POLYGONOFFSET)) {
|
|
glDisable(GL_POLYGON_OFFSET_FILL);
|
|
}
|
|
|
|
// reset blending
|
|
if (shader->GetSort() == SS_SUBVIEW) {
|
|
GL_State(GLS_DEPTHFUNC_LESS);
|
|
}
|
|
|
|
glDisableClientState(GL_NORMAL_ARRAY);
|
|
glDisableClientState(GL_TANGENT_ARRAY_QD3D12);
|
|
glDisableClientState(GL_BINORMAL_ARRAY_QD3D12);
|
|
|
|
glGeometryFlagf(GEOMETRY_FLAG_NONE);
|
|
}
|
|
|
|
/*
|
|
=====================
|
|
RB_STD_FillDepthBuffer
|
|
|
|
If we are rendering a subview with a near clip plane, use a second texture
|
|
to force the alpha test to fail when behind that clip plane
|
|
=====================
|
|
*/
|
|
void RB_STD_FillDepthBuffer( drawSurf_t **drawSurfs, int numDrawSurfs ) {
|
|
// if we are just doing 2D rendering, no need to fill the depth buffer
|
|
if ( !backEnd.viewDef->viewEntitys ) {
|
|
return;
|
|
}
|
|
|
|
RB_LogComment( "---------- RB_STD_FillDepthBuffer ----------\n" );
|
|
|
|
// enable the second texture for mirror plane clipping if needed
|
|
if ( backEnd.viewDef->numClipPlanes ) {
|
|
GL_SelectTexture( 1 );
|
|
globalImages->alphaNotchImage->Bind();
|
|
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
|
glEnable( GL_TEXTURE_GEN_S );
|
|
glTexCoord2f( 1, 0.5 );
|
|
}
|
|
|
|
// the first texture will be used for alpha tested surfaces
|
|
GL_SelectTexture( 0 );
|
|
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
|
|
|
// decal surfaces may enable polygon offset
|
|
glPolygonOffset( r_offsetFactor.GetFloat(), r_offsetUnits.GetFloat() );
|
|
|
|
GL_State( GLS_DEPTHFUNC_LESS );
|
|
|
|
glDisable( GL_STENCIL_TEST );
|
|
|
|
RB_RenderDrawSurfListWithFunction( drawSurfs, numDrawSurfs, RB_T_FillDepthBuffer );
|
|
|
|
if ( backEnd.viewDef->numClipPlanes ) {
|
|
GL_SelectTexture( 1 );
|
|
globalImages->BindNull();
|
|
glDisable( GL_TEXTURE_GEN_S );
|
|
GL_SelectTexture( 0 );
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
=============================================================================================
|
|
|
|
SHADER PASSES
|
|
|
|
=============================================================================================
|
|
*/
|
|
|
|
/*
|
|
==================
|
|
RB_SetProgramEnvironment
|
|
|
|
Sets variables that can be used by all vertex programs
|
|
==================
|
|
*/
|
|
void RB_SetProgramEnvironment( void ) {
|
|
float parm[4];
|
|
int pot;
|
|
|
|
if ( !glConfig.ARBVertexProgramAvailable ) {
|
|
return;
|
|
}
|
|
|
|
#if 0
|
|
// screen power of two correction factor, one pixel in so we don't get a bilerp
|
|
// of an uncopied pixel
|
|
int w = backEnd.viewDef->viewport.x2 - backEnd.viewDef->viewport.x1 + 1;
|
|
pot = globalImages->currentRenderImage->uploadWidth;
|
|
if ( w == pot ) {
|
|
parm[0] = 1.0;
|
|
} else {
|
|
parm[0] = (float)(w-1) / pot;
|
|
}
|
|
|
|
int h = backEnd.viewDef->viewport.y2 - backEnd.viewDef->viewport.y1 + 1;
|
|
pot = globalImages->currentRenderImage->uploadHeight;
|
|
if ( h == pot ) {
|
|
parm[1] = 1.0;
|
|
} else {
|
|
parm[1] = (float)(h-1) / pot;
|
|
}
|
|
|
|
parm[2] = 0;
|
|
parm[3] = 1;
|
|
glProgramEnvParameter4fvARB( GL_VERTEX_PROGRAM_ARB, 0, parm );
|
|
#else
|
|
// screen power of two correction factor, assuming the copy to _currentRender
|
|
// also copied an extra row and column for the bilerp
|
|
int w = backEnd.viewDef->viewport.x2 - backEnd.viewDef->viewport.x1 + 1;
|
|
pot = globalImages->currentRenderImage->uploadWidth;
|
|
parm[0] = (float)w / pot;
|
|
|
|
int h = backEnd.viewDef->viewport.y2 - backEnd.viewDef->viewport.y1 + 1;
|
|
pot = globalImages->currentRenderImage->uploadHeight;
|
|
parm[1] = (float)h / pot;
|
|
|
|
parm[2] = 0;
|
|
parm[3] = 1;
|
|
glProgramEnvParameter4fvARB( GL_VERTEX_PROGRAM_ARB, 0, parm );
|
|
#endif
|
|
|
|
glProgramEnvParameter4fvARB( GL_FRAGMENT_PROGRAM_ARB, 0, parm );
|
|
|
|
// window coord to 0.0 to 1.0 conversion
|
|
parm[0] = 1.0 / w;
|
|
parm[1] = 1.0 / h;
|
|
parm[2] = 0;
|
|
parm[3] = 1;
|
|
glProgramEnvParameter4fvARB( GL_FRAGMENT_PROGRAM_ARB, 1, parm );
|
|
|
|
//
|
|
// set eye position in global space
|
|
//
|
|
parm[0] = backEnd.viewDef->renderView.vieworg[0];
|
|
parm[1] = backEnd.viewDef->renderView.vieworg[1];
|
|
parm[2] = backEnd.viewDef->renderView.vieworg[2];
|
|
parm[3] = 1.0;
|
|
glProgramEnvParameter4fvARB( GL_VERTEX_PROGRAM_ARB, 1, parm );
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
==================
|
|
RB_SetProgramEnvironmentSpace
|
|
|
|
Sets variables related to the current space that can be used by all vertex programs
|
|
==================
|
|
*/
|
|
void RB_SetProgramEnvironmentSpace( void ) {
|
|
if ( !glConfig.ARBVertexProgramAvailable ) {
|
|
return;
|
|
}
|
|
|
|
const struct viewEntity_s *space = backEnd.currentSpace;
|
|
float parm[4];
|
|
|
|
// set eye position in local space
|
|
R_GlobalPointToLocal( space->modelMatrix, backEnd.viewDef->renderView.vieworg, *(idVec3 *)parm );
|
|
parm[3] = 1.0;
|
|
glProgramEnvParameter4fvARB( GL_VERTEX_PROGRAM_ARB, 5, parm );
|
|
|
|
// we need the model matrix without it being combined with the view matrix
|
|
// so we can transform local vectors to global coordinates
|
|
parm[0] = space->modelMatrix[0];
|
|
parm[1] = space->modelMatrix[4];
|
|
parm[2] = space->modelMatrix[8];
|
|
parm[3] = space->modelMatrix[12];
|
|
glProgramEnvParameter4fvARB( GL_VERTEX_PROGRAM_ARB, 6, parm );
|
|
parm[0] = space->modelMatrix[1];
|
|
parm[1] = space->modelMatrix[5];
|
|
parm[2] = space->modelMatrix[9];
|
|
parm[3] = space->modelMatrix[13];
|
|
glProgramEnvParameter4fvARB( GL_VERTEX_PROGRAM_ARB, 7, parm );
|
|
parm[0] = space->modelMatrix[2];
|
|
parm[1] = space->modelMatrix[6];
|
|
parm[2] = space->modelMatrix[10];
|
|
parm[3] = space->modelMatrix[14];
|
|
glProgramEnvParameter4fvARB( GL_VERTEX_PROGRAM_ARB, 8, parm );
|
|
}
|
|
|
|
/*
|
|
==================
|
|
RB_STD_T_RenderShaderPasses
|
|
|
|
This is also called for the generated 2D rendering
|
|
==================
|
|
*/
|
|
void RB_STD_T_RenderShaderPasses( const drawSurf_t *surf ) {
|
|
int stage;
|
|
const idMaterial *shader;
|
|
const shaderStage_t *pStage;
|
|
const float *regs;
|
|
float color[4];
|
|
const srfTriangles_t *tri;
|
|
|
|
tri = surf->geo;
|
|
shader = surf->material;
|
|
|
|
if ( r_screenSpaceParticles.GetBool() && ( surf->dsFlags & DSF_SCREEN_SPACE_PARTICLE ) ) {
|
|
return;
|
|
}
|
|
|
|
if ( !shader->HasAmbient() ) {
|
|
return;
|
|
}
|
|
|
|
if ( shader->IsPortalSky() ) {
|
|
return;
|
|
}
|
|
|
|
// change the matrix if needed
|
|
if ( surf->space != backEnd.currentSpace ) {
|
|
glLoadMatrixf( surf->space->modelViewMatrix );
|
|
backEnd.currentSpace = surf->space;
|
|
RB_SetProgramEnvironmentSpace();
|
|
}
|
|
|
|
// change the scissor if needed
|
|
if ( r_useScissor.GetBool() && !backEnd.currentScissor.Equals( surf->scissorRect ) ) {
|
|
backEnd.currentScissor = surf->scissorRect;
|
|
glScissor( backEnd.viewDef->viewport.x1 + backEnd.currentScissor.x1,
|
|
backEnd.viewDef->viewport.y1 + backEnd.currentScissor.y1,
|
|
backEnd.currentScissor.x2 + 1 - backEnd.currentScissor.x1,
|
|
backEnd.currentScissor.y2 + 1 - backEnd.currentScissor.y1 );
|
|
}
|
|
|
|
// some deforms may disable themselves by setting numIndexes = 0
|
|
if ( !tri->numIndexes ) {
|
|
return;
|
|
}
|
|
|
|
if ( !tri->ambientVbo && !tri->ambientCache ) {
|
|
common->Printf( "RB_T_RenderShaderPasses: !tri->ambientCache\n" );
|
|
return;
|
|
}
|
|
|
|
// get the expressions for conditionals / color / texcoords
|
|
regs = surf->shaderRegisters;
|
|
|
|
// set face culling appropriately
|
|
GL_Cull( shader->GetCullType() );
|
|
|
|
// set polygon offset if necessary
|
|
if ( shader->TestMaterialFlag(MF_POLYGONOFFSET) ) {
|
|
glEnable( GL_POLYGON_OFFSET_FILL );
|
|
glPolygonOffset( r_offsetFactor.GetFloat(), r_offsetUnits.GetFloat() * shader->GetPolygonOffset() );
|
|
}
|
|
|
|
if ( surf->space->weaponDepthHack ) {
|
|
RB_EnterWeaponDepthHack();
|
|
}
|
|
|
|
if ( surf->space->modelDepthHack != 0.0f ) {
|
|
RB_EnterModelDepthHack( surf->space->modelDepthHack );
|
|
}
|
|
|
|
idDrawVert *ac = RB_BindAmbientBuffer( tri );
|
|
glVertexPointer( 3, GL_FLOAT, sizeof( idDrawVert ), ac->xyz.ToFloatPtr() );
|
|
glTexCoordPointer( 2, GL_FLOAT, sizeof( idDrawVert ), reinterpret_cast<void *>(&ac->st) );
|
|
glNormalPointer( GL_FLOAT, sizeof( idDrawVert ), ac->normal.ToFloatPtr() );
|
|
glTangentPointer( GL_FLOAT, sizeof( idDrawVert ), ac->tangents[0].ToFloatPtr() );
|
|
glBinormalPointer( GL_FLOAT, sizeof( idDrawVert ), ac->tangents[1].ToFloatPtr() );
|
|
|
|
glEnableClientState( GL_NORMAL_ARRAY );
|
|
glEnableClientState( GL_TANGENT_ARRAY_QD3D12 );
|
|
glEnableClientState( GL_BINORMAL_ARRAY_QD3D12 );
|
|
|
|
const bool glassMaterial = shader->GetSurfaceType() == SURFTYPE_GLASS;
|
|
const float baseGeometryFlag = surf->geo->isSkeletal ? (float)GEOMETRY_FLAG_SKELETAL : (float)GEOMETRY_FLAG_NONE;
|
|
glGlassMaterialQD3D12( glassMaterial ? GL_TRUE : GL_FALSE );
|
|
glGeometryFlagf( glassMaterial ? ( baseGeometryFlag + (float)GEOMETRY_FLAG_GLASS ) : baseGeometryFlag );
|
|
|
|
for ( stage = 0; stage < shader->GetNumStages() ; stage++ ) {
|
|
pStage = shader->GetStage(stage);
|
|
|
|
// check the enable condition
|
|
if ( regs[ pStage->conditionRegister ] == 0 ) {
|
|
continue;
|
|
}
|
|
|
|
// skip the stages involved in lighting
|
|
if ( pStage->lighting != SL_AMBIENT ) {
|
|
continue;
|
|
}
|
|
|
|
// skip if the stage is ( GL_ZERO, GL_ONE ), which is used for some alpha masks
|
|
if ( ( pStage->drawStateBits & (GLS_SRCBLEND_BITS|GLS_DSTBLEND_BITS) ) == ( GLS_SRCBLEND_ZERO | GLS_DSTBLEND_ONE ) ) {
|
|
continue;
|
|
}
|
|
#if 0
|
|
// see if we are a new-style stage
|
|
newShaderStage_t *newStage = pStage->newStage;
|
|
if ( newStage ) {
|
|
//--------------------------
|
|
//
|
|
// new style stages
|
|
//
|
|
//--------------------------
|
|
|
|
// completely skip the stage if we don't have the capability
|
|
if ( tr.backEndRenderer != BE_ARB2 ) {
|
|
continue;
|
|
}
|
|
if ( r_skipNewAmbient.GetBool() ) {
|
|
continue;
|
|
}
|
|
glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( idDrawVert ), (void *)&ac->color );
|
|
glVertexAttribPointerARB( 9, 3, GL_FLOAT, false, sizeof( idDrawVert ), ac->tangents[0].ToFloatPtr() );
|
|
glVertexAttribPointerARB( 10, 3, GL_FLOAT, false, sizeof( idDrawVert ), ac->tangents[1].ToFloatPtr() );
|
|
glNormalPointer( GL_FLOAT, sizeof( idDrawVert ), ac->normal.ToFloatPtr() );
|
|
|
|
glEnableClientState( GL_COLOR_ARRAY );
|
|
glEnableVertexAttribArrayARB( 9 );
|
|
glEnableVertexAttribArrayARB( 10 );
|
|
glEnableClientState( GL_NORMAL_ARRAY );
|
|
|
|
GL_State( pStage->drawStateBits );
|
|
|
|
glBindProgramARB( GL_VERTEX_PROGRAM_ARB, newStage->vertexProgram );
|
|
glEnable( GL_VERTEX_PROGRAM_ARB );
|
|
|
|
// megaTextures bind a lot of images and set a lot of parameters
|
|
if ( newStage->megaTexture ) {
|
|
newStage->megaTexture->SetMappingForSurface( tri );
|
|
idVec3 localViewer;
|
|
R_GlobalPointToLocal( surf->space->modelMatrix, backEnd.viewDef->renderView.vieworg, localViewer );
|
|
newStage->megaTexture->BindForViewOrigin( localViewer );
|
|
}
|
|
|
|
for ( int i = 0 ; i < newStage->numVertexParms ; i++ ) {
|
|
float parm[4];
|
|
parm[0] = regs[ newStage->vertexParms[i][0] ];
|
|
parm[1] = regs[ newStage->vertexParms[i][1] ];
|
|
parm[2] = regs[ newStage->vertexParms[i][2] ];
|
|
parm[3] = regs[ newStage->vertexParms[i][3] ];
|
|
glProgramLocalParameter4fvARB( GL_VERTEX_PROGRAM_ARB, i, parm );
|
|
}
|
|
|
|
for ( int i = 0 ; i < newStage->numFragmentProgramImages ; i++ ) {
|
|
if ( newStage->fragmentProgramImages[i] ) {
|
|
GL_SelectTexture( i );
|
|
newStage->fragmentProgramImages[i]->Bind();
|
|
}
|
|
}
|
|
glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, newStage->fragmentProgram );
|
|
glEnable( GL_FRAGMENT_PROGRAM_ARB );
|
|
|
|
// draw it
|
|
RB_DrawElementsWithCounters( tri );
|
|
|
|
for ( int i = 1 ; i < newStage->numFragmentProgramImages ; i++ ) {
|
|
if ( newStage->fragmentProgramImages[i] ) {
|
|
GL_SelectTexture( i );
|
|
globalImages->BindNull();
|
|
}
|
|
}
|
|
if ( newStage->megaTexture ) {
|
|
newStage->megaTexture->Unbind();
|
|
}
|
|
|
|
GL_SelectTexture( 0 );
|
|
|
|
glDisable( GL_VERTEX_PROGRAM_ARB );
|
|
glDisable( GL_FRAGMENT_PROGRAM_ARB );
|
|
// Fixme: Hack to get around an apparent bug in ATI drivers. Should remove as soon as it gets fixed.
|
|
glBindProgramARB( GL_VERTEX_PROGRAM_ARB, 0 );
|
|
|
|
glDisableClientState( GL_COLOR_ARRAY );
|
|
glDisableVertexAttribArrayARB( 9 );
|
|
glDisableVertexAttribArrayARB( 10 );
|
|
glDisableClientState( GL_NORMAL_ARRAY );
|
|
continue;
|
|
}
|
|
#endif
|
|
//--------------------------
|
|
//
|
|
// old style stages
|
|
//
|
|
//--------------------------
|
|
|
|
// set the color
|
|
color[0] = regs[ pStage->color.registers[0] ];
|
|
color[1] = regs[ pStage->color.registers[1] ];
|
|
color[2] = regs[ pStage->color.registers[2] ];
|
|
color[3] = regs[ pStage->color.registers[3] ];
|
|
|
|
// skip the entire stage if an add would be black
|
|
if ( ( pStage->drawStateBits & (GLS_SRCBLEND_BITS|GLS_DSTBLEND_BITS) ) == ( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE )
|
|
&& color[0] <= 0 && color[1] <= 0 && color[2] <= 0 ) {
|
|
continue;
|
|
}
|
|
|
|
// skip the entire stage if a blend would be completely transparent
|
|
if ( ( pStage->drawStateBits & (GLS_SRCBLEND_BITS|GLS_DSTBLEND_BITS) ) == ( GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA )
|
|
&& color[3] <= 0 ) {
|
|
continue;
|
|
}
|
|
|
|
// select the vertex color source
|
|
if ( pStage->vertexColor == SVC_IGNORE ) {
|
|
glColor4fv( color );
|
|
} else {
|
|
glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( idDrawVert ), (void *)&ac->color );
|
|
glEnableClientState( GL_COLOR_ARRAY );
|
|
|
|
if ( pStage->vertexColor == SVC_INVERSE_MODULATE ) {
|
|
GL_TexEnv( GL_COMBINE_ARB );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_ONE_MINUS_SRC_COLOR );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1 );
|
|
}
|
|
|
|
// for vertex color and modulated color, we need to enable a second
|
|
// texture stage
|
|
if ( color[0] != 1 || color[1] != 1 || color[2] != 1 || color[3] != 1 ) {
|
|
GL_SelectTexture( 1 );
|
|
|
|
globalImages->whiteImage->Bind();
|
|
GL_TexEnv( GL_COMBINE_ARB );
|
|
|
|
glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color );
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_CONSTANT_ARB );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1 );
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_CONSTANT_ARB );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, GL_SRC_ALPHA );
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1 );
|
|
|
|
GL_SelectTexture( 0 );
|
|
}
|
|
}
|
|
|
|
// bind the texture
|
|
RB_BindVariableStageImage( &pStage->texture, regs );
|
|
|
|
// set the state
|
|
GL_State( pStage->drawStateBits );
|
|
|
|
RB_PrepareStageTexturing( pStage, surf, ac );
|
|
|
|
// draw it
|
|
RB_DrawElementsWithCounters( tri );
|
|
|
|
RB_FinishStageTexturing( pStage, surf, ac );
|
|
|
|
if ( pStage->vertexColor != SVC_IGNORE ) {
|
|
glDisableClientState( GL_COLOR_ARRAY );
|
|
|
|
GL_SelectTexture( 1 );
|
|
GL_TexEnv( GL_MODULATE );
|
|
globalImages->BindNull();
|
|
GL_SelectTexture( 0 );
|
|
GL_TexEnv( GL_MODULATE );
|
|
}
|
|
}
|
|
|
|
// reset polygon offset
|
|
if ( shader->TestMaterialFlag(MF_POLYGONOFFSET) ) {
|
|
glDisable( GL_POLYGON_OFFSET_FILL );
|
|
}
|
|
if ( surf->space->weaponDepthHack || surf->space->modelDepthHack != 0.0f ) {
|
|
RB_LeaveDepthHack();
|
|
}
|
|
|
|
glGlassMaterialQD3D12( GL_FALSE );
|
|
glGeometryFlagf( GEOMETRY_FLAG_NONE );
|
|
glDisableClientState( GL_NORMAL_ARRAY );
|
|
glDisableClientState( GL_TANGENT_ARRAY_QD3D12 );
|
|
glDisableClientState( GL_BINORMAL_ARRAY_QD3D12 );
|
|
}
|
|
|
|
/*
|
|
=====================
|
|
RB_STD_DrawShaderPasses
|
|
|
|
Draw non-light dependent passes
|
|
=====================
|
|
*/
|
|
int RB_STD_DrawShaderPasses( drawSurf_t **drawSurfs, int numDrawSurfs ) {
|
|
int i;
|
|
|
|
// only obey skipAmbient if we are rendering a view
|
|
if ( backEnd.viewDef->viewEntitys && r_skipAmbient.GetBool() ) {
|
|
return numDrawSurfs;
|
|
}
|
|
|
|
RB_LogComment( "---------- RB_STD_DrawShaderPasses ----------\n" );
|
|
|
|
// if we are about to draw the first surface that needs
|
|
// the rendering in a texture, copy it over
|
|
if ( drawSurfs[0]->material->GetSort() >= SS_POST_PROCESS ) {
|
|
if ( r_skipPostProcess.GetBool() ) {
|
|
return 0;
|
|
}
|
|
|
|
// only dump if in a 3d view
|
|
if ( backEnd.viewDef->viewEntitys && tr.backEndRenderer == BE_ARB2 ) {
|
|
globalImages->currentRenderImage->CopyFramebuffer( backEnd.viewDef->viewport.x1,
|
|
backEnd.viewDef->viewport.y1, backEnd.viewDef->viewport.x2 - backEnd.viewDef->viewport.x1 + 1,
|
|
backEnd.viewDef->viewport.y2 - backEnd.viewDef->viewport.y1 + 1, true );
|
|
}
|
|
backEnd.currentRenderCopied = true;
|
|
}
|
|
|
|
GL_SelectTexture( 1 );
|
|
globalImages->BindNull();
|
|
|
|
GL_SelectTexture( 0 );
|
|
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
|
|
|
|
RB_SetProgramEnvironment();
|
|
|
|
// we don't use RB_RenderDrawSurfListWithFunction()
|
|
// because we want to defer the matrix load because many
|
|
// surfaces won't draw any ambient passes
|
|
backEnd.currentSpace = NULL;
|
|
for (i = 0 ; i < numDrawSurfs ; i++ ) {
|
|
if ( drawSurfs[i]->material->SuppressInSubview() ) {
|
|
continue;
|
|
}
|
|
#ifndef QUAKE4
|
|
if ( backEnd.viewDef->isXraySubview && drawSurfs[i]->space->entityDef ) {
|
|
if ( drawSurfs[i]->space->entityDef->parms.xrayIndex != 2 ) {
|
|
continue;
|
|
}
|
|
}
|
|
#endif
|
|
// we need to draw the post process shaders after we have drawn the fog lights
|
|
if ( drawSurfs[i]->material->GetSort() >= SS_POST_PROCESS
|
|
&& !backEnd.currentRenderCopied ) {
|
|
break;
|
|
}
|
|
|
|
RB_STD_T_RenderShaderPasses( drawSurfs[i] );
|
|
}
|
|
|
|
GL_Cull( CT_FRONT_SIDED );
|
|
glColor3f( 1, 1, 1 );
|
|
|
|
return i;
|
|
}
|
|
|
|
/*
|
|
=============================================================================================
|
|
|
|
BLEND LIGHT PROJECTION
|
|
|
|
=============================================================================================
|
|
*/
|
|
|
|
/*
|
|
=====================
|
|
RB_T_BlendLight
|
|
|
|
=====================
|
|
*/
|
|
static void RB_T_BlendLight( const drawSurf_t *surf ) {
|
|
const srfTriangles_t *tri;
|
|
|
|
tri = surf->geo;
|
|
|
|
if ( backEnd.currentSpace != surf->space ) {
|
|
idPlane lightProject[4];
|
|
int i;
|
|
|
|
for ( i = 0 ; i < 4 ; i++ ) {
|
|
R_GlobalPlaneToLocal( surf->space->modelMatrix, backEnd.vLight->lightProject[i], lightProject[i] );
|
|
}
|
|
|
|
GL_SelectTexture( 0 );
|
|
glTexGenfv( GL_S, GL_OBJECT_PLANE, lightProject[0].ToFloatPtr() );
|
|
glTexGenfv( GL_T, GL_OBJECT_PLANE, lightProject[1].ToFloatPtr() );
|
|
glTexGenfv( GL_Q, GL_OBJECT_PLANE, lightProject[2].ToFloatPtr() );
|
|
|
|
GL_SelectTexture( 1 );
|
|
glTexGenfv( GL_S, GL_OBJECT_PLANE, lightProject[3].ToFloatPtr() );
|
|
}
|
|
|
|
if ( tri->ambientVbo || tri->ambientCache ) {
|
|
idDrawVert *ac = RB_BindAmbientBuffer( tri );
|
|
glVertexPointer( 3, GL_FLOAT, sizeof( idDrawVert ), ac->xyz.ToFloatPtr() );
|
|
}
|
|
|
|
RB_DrawElementsWithCounters( tri );
|
|
}
|
|
|
|
|
|
/*
|
|
=====================
|
|
RB_BlendLight
|
|
|
|
Dual texture together the falloff and projection texture with a blend
|
|
mode to the framebuffer, instead of interacting with the surface texture
|
|
=====================
|
|
*/
|
|
static void RB_BlendLight( const drawSurf_t *drawSurfs, const drawSurf_t *drawSurfs2 ) {
|
|
const idMaterial *lightShader;
|
|
const shaderStage_t *stage;
|
|
int i;
|
|
const float *regs;
|
|
|
|
if ( !drawSurfs ) {
|
|
return;
|
|
}
|
|
if ( r_skipBlendLights.GetBool() ) {
|
|
return;
|
|
}
|
|
RB_LogComment( "---------- RB_BlendLight ----------\n" );
|
|
|
|
lightShader = backEnd.vLight->lightShader;
|
|
regs = backEnd.vLight->shaderRegisters;
|
|
|
|
// texture 1 will get the falloff texture
|
|
GL_SelectTexture( 1 );
|
|
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
|
glEnable( GL_TEXTURE_GEN_S );
|
|
glTexCoord2f( 0, 0.5 );
|
|
backEnd.vLight->falloffImage->Bind();
|
|
|
|
// texture 0 will get the projected texture
|
|
GL_SelectTexture( 0 );
|
|
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
|
glEnable( GL_TEXTURE_GEN_S );
|
|
glEnable( GL_TEXTURE_GEN_T );
|
|
glEnable( GL_TEXTURE_GEN_Q );
|
|
|
|
for ( i = 0 ; i < lightShader->GetNumStages() ; i++ ) {
|
|
stage = lightShader->GetStage(i);
|
|
|
|
if ( !regs[ stage->conditionRegister ] ) {
|
|
continue;
|
|
}
|
|
|
|
GL_State( GLS_DEPTHMASK | stage->drawStateBits | GLS_DEPTHFUNC_EQUAL );
|
|
|
|
GL_SelectTexture( 0 );
|
|
stage->texture.image->Bind();
|
|
|
|
if ( stage->texture.hasMatrix ) {
|
|
RB_LoadShaderTextureMatrix( regs, &stage->texture );
|
|
}
|
|
|
|
// get the modulate values from the light, including alpha, unlike normal lights
|
|
backEnd.lightColor[0] = regs[ stage->color.registers[0] ];
|
|
backEnd.lightColor[1] = regs[ stage->color.registers[1] ];
|
|
backEnd.lightColor[2] = regs[ stage->color.registers[2] ];
|
|
backEnd.lightColor[3] = regs[ stage->color.registers[3] ];
|
|
glColor4fv( backEnd.lightColor );
|
|
|
|
RB_RenderDrawSurfChainWithFunction( drawSurfs, RB_T_BlendLight );
|
|
RB_RenderDrawSurfChainWithFunction( drawSurfs2, RB_T_BlendLight );
|
|
|
|
if ( stage->texture.hasMatrix ) {
|
|
GL_SelectTexture( 0 );
|
|
glMatrixMode( GL_TEXTURE );
|
|
glLoadIdentity();
|
|
glMatrixMode( GL_MODELVIEW );
|
|
}
|
|
}
|
|
|
|
GL_SelectTexture( 1 );
|
|
glDisable( GL_TEXTURE_GEN_S );
|
|
globalImages->BindNull();
|
|
|
|
GL_SelectTexture( 0 );
|
|
glDisable( GL_TEXTURE_GEN_S );
|
|
glDisable( GL_TEXTURE_GEN_T );
|
|
glDisable( GL_TEXTURE_GEN_Q );
|
|
}
|
|
|
|
|
|
//========================================================================
|
|
|
|
static idPlane fogPlanes[4];
|
|
|
|
/*
|
|
=====================
|
|
RB_T_BasicFog
|
|
|
|
=====================
|
|
*/
|
|
static void RB_T_BasicFog( const drawSurf_t *surf ) {
|
|
if ( backEnd.currentSpace != surf->space ) {
|
|
idPlane local;
|
|
|
|
GL_SelectTexture( 0 );
|
|
|
|
R_GlobalPlaneToLocal( surf->space->modelMatrix, fogPlanes[0], local );
|
|
local[3] += 0.5;
|
|
glTexGenfv( GL_S, GL_OBJECT_PLANE, local.ToFloatPtr() );
|
|
|
|
// R_GlobalPlaneToLocal( surf->space->modelMatrix, fogPlanes[1], local );
|
|
// local[3] += 0.5;
|
|
local[0] = local[1] = local[2] = 0; local[3] = 0.5;
|
|
glTexGenfv( GL_T, GL_OBJECT_PLANE, local.ToFloatPtr() );
|
|
|
|
GL_SelectTexture( 1 );
|
|
|
|
// GL_S is constant per viewer
|
|
R_GlobalPlaneToLocal( surf->space->modelMatrix, fogPlanes[2], local );
|
|
local[3] += FOG_ENTER;
|
|
glTexGenfv( GL_T, GL_OBJECT_PLANE, local.ToFloatPtr() );
|
|
|
|
R_GlobalPlaneToLocal( surf->space->modelMatrix, fogPlanes[3], local );
|
|
glTexGenfv( GL_S, GL_OBJECT_PLANE, local.ToFloatPtr() );
|
|
}
|
|
|
|
RB_T_RenderTriangleSurface( surf );
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
==================
|
|
RB_FogPass
|
|
==================
|
|
*/
|
|
static void RB_FogPass( const drawSurf_t *drawSurfs, const drawSurf_t *drawSurfs2 ) {
|
|
const srfTriangles_t*frustumTris;
|
|
drawSurf_t ds;
|
|
const idMaterial *lightShader;
|
|
const shaderStage_t *stage;
|
|
const float *regs;
|
|
|
|
RB_LogComment( "---------- RB_FogPass ----------\n" );
|
|
|
|
// create a surface for the light frustom triangles, which are oriented drawn side out
|
|
frustumTris = backEnd.vLight->frustumTris;
|
|
|
|
// if we ran out of vertex cache memory, skip it
|
|
if ( !frustumTris->ambientVbo && !frustumTris->ambientCache ) {
|
|
return;
|
|
}
|
|
memset( &ds, 0, sizeof( ds ) );
|
|
ds.space = &backEnd.viewDef->worldSpace;
|
|
ds.geo = frustumTris;
|
|
ds.scissorRect = backEnd.viewDef->scissor;
|
|
|
|
// find the current color and density of the fog
|
|
lightShader = backEnd.vLight->lightShader;
|
|
regs = backEnd.vLight->shaderRegisters;
|
|
// assume fog shaders have only a single stage
|
|
stage = lightShader->GetStage(0);
|
|
|
|
backEnd.lightColor[0] = regs[ stage->color.registers[0] ];
|
|
backEnd.lightColor[1] = regs[ stage->color.registers[1] ];
|
|
backEnd.lightColor[2] = regs[ stage->color.registers[2] ];
|
|
backEnd.lightColor[3] = regs[ stage->color.registers[3] ];
|
|
|
|
glColor3fv( backEnd.lightColor );
|
|
|
|
// calculate the falloff planes
|
|
float a;
|
|
|
|
// if they left the default value on, set a fog distance of 500
|
|
if ( backEnd.lightColor[3] <= 1.0 ) {
|
|
a = -0.5f / DEFAULT_FOG_DISTANCE;
|
|
} else {
|
|
// otherwise, distance = alpha color
|
|
a = -0.5f / backEnd.lightColor[3];
|
|
}
|
|
|
|
GL_State( GLS_DEPTHMASK | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA | GLS_DEPTHFUNC_EQUAL );
|
|
|
|
// texture 0 is the falloff image
|
|
GL_SelectTexture( 0 );
|
|
globalImages->fogImage->Bind();
|
|
//GL_Bind( tr.whiteImage );
|
|
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
|
glEnable( GL_TEXTURE_GEN_S );
|
|
glEnable( GL_TEXTURE_GEN_T );
|
|
glTexCoord2f( 0.5f, 0.5f ); // make sure Q is set
|
|
|
|
fogPlanes[0][0] = a * backEnd.viewDef->worldSpace.modelViewMatrix[2];
|
|
fogPlanes[0][1] = a * backEnd.viewDef->worldSpace.modelViewMatrix[6];
|
|
fogPlanes[0][2] = a * backEnd.viewDef->worldSpace.modelViewMatrix[10];
|
|
fogPlanes[0][3] = a * backEnd.viewDef->worldSpace.modelViewMatrix[14];
|
|
|
|
fogPlanes[1][0] = a * backEnd.viewDef->worldSpace.modelViewMatrix[0];
|
|
fogPlanes[1][1] = a * backEnd.viewDef->worldSpace.modelViewMatrix[4];
|
|
fogPlanes[1][2] = a * backEnd.viewDef->worldSpace.modelViewMatrix[8];
|
|
fogPlanes[1][3] = a * backEnd.viewDef->worldSpace.modelViewMatrix[12];
|
|
|
|
|
|
// texture 1 is the entering plane fade correction
|
|
GL_SelectTexture( 1 );
|
|
globalImages->fogEnterImage->Bind();
|
|
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
|
|
glEnable( GL_TEXTURE_GEN_S );
|
|
glEnable( GL_TEXTURE_GEN_T );
|
|
|
|
// T will get a texgen for the fade plane, which is always the "top" plane on unrotated lights
|
|
fogPlanes[2][0] = 0.001f * backEnd.vLight->fogPlane[0];
|
|
fogPlanes[2][1] = 0.001f * backEnd.vLight->fogPlane[1];
|
|
fogPlanes[2][2] = 0.001f * backEnd.vLight->fogPlane[2];
|
|
fogPlanes[2][3] = 0.001f * backEnd.vLight->fogPlane[3];
|
|
|
|
// S is based on the view origin
|
|
float s = backEnd.viewDef->renderView.vieworg * fogPlanes[2].Normal() + fogPlanes[2][3];
|
|
|
|
fogPlanes[3][0] = 0;
|
|
fogPlanes[3][1] = 0;
|
|
fogPlanes[3][2] = 0;
|
|
fogPlanes[3][3] = FOG_ENTER + s;
|
|
|
|
glTexCoord2f( FOG_ENTER + s, FOG_ENTER );
|
|
|
|
|
|
// draw it
|
|
RB_RenderDrawSurfChainWithFunction( drawSurfs, RB_T_BasicFog );
|
|
RB_RenderDrawSurfChainWithFunction( drawSurfs2, RB_T_BasicFog );
|
|
|
|
// the light frustum bounding planes aren't in the depth buffer, so use depthfunc_less instead
|
|
// of depthfunc_equal
|
|
GL_State( GLS_DEPTHMASK | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA | GLS_DEPTHFUNC_LESS );
|
|
GL_Cull( CT_BACK_SIDED );
|
|
RB_RenderDrawSurfChainWithFunction( &ds, RB_T_BasicFog );
|
|
GL_Cull( CT_FRONT_SIDED );
|
|
|
|
GL_SelectTexture( 1 );
|
|
glDisable( GL_TEXTURE_GEN_S );
|
|
glDisable( GL_TEXTURE_GEN_T );
|
|
globalImages->BindNull();
|
|
|
|
GL_SelectTexture( 0 );
|
|
glDisable( GL_TEXTURE_GEN_S );
|
|
glDisable( GL_TEXTURE_GEN_T );
|
|
}
|
|
|
|
|
|
/*
|
|
==================
|
|
RB_STD_FogAllLights
|
|
==================
|
|
*/
|
|
void RB_STD_FogAllLights( void ) {
|
|
viewLight_t *vLight;
|
|
|
|
if ( r_skipFogLights.GetBool() || r_showOverDraw.GetInteger() != 0
|
|
|| backEnd.viewDef->isXraySubview /* dont fog in xray mode*/
|
|
) {
|
|
return;
|
|
}
|
|
|
|
RB_LogComment( "---------- RB_STD_FogAllLights ----------\n" );
|
|
|
|
glDisable( GL_STENCIL_TEST );
|
|
|
|
for ( vLight = backEnd.viewDef->viewLights ; vLight ; vLight = vLight->next ) {
|
|
backEnd.vLight = vLight;
|
|
|
|
if ( !vLight->lightShader->IsFogLight() && !vLight->lightShader->IsBlendLight() ) {
|
|
continue;
|
|
}
|
|
|
|
#if 0 // _D3XP disabled that
|
|
if ( r_ignore.GetInteger() ) {
|
|
// we use the stencil buffer to guarantee that no pixels will be
|
|
// double fogged, which happens in some areas that are thousands of
|
|
// units from the origin
|
|
backEnd.currentScissor = vLight->scissorRect;
|
|
if ( r_useScissor.GetBool() ) {
|
|
glScissor( backEnd.viewDef->viewport.x1 + backEnd.currentScissor.x1,
|
|
backEnd.viewDef->viewport.y1 + backEnd.currentScissor.y1,
|
|
backEnd.currentScissor.x2 + 1 - backEnd.currentScissor.x1,
|
|
backEnd.currentScissor.y2 + 1 - backEnd.currentScissor.y1 );
|
|
}
|
|
glClear( GL_STENCIL_BUFFER_BIT );
|
|
|
|
glEnable( GL_STENCIL_TEST );
|
|
|
|
// only pass on the cleared stencil values
|
|
glStencilFunc( GL_EQUAL, 128, 255 );
|
|
|
|
// when we pass the stencil test and depth test and are going to draw,
|
|
// increment the stencil buffer so we don't ever draw on that pixel again
|
|
glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
|
|
}
|
|
#endif
|
|
|
|
if ( vLight->lightShader->IsFogLight() ) {
|
|
RB_FogPass( vLight->globalInteractions, vLight->localInteractions );
|
|
} else if ( vLight->lightShader->IsBlendLight() ) {
|
|
RB_BlendLight( vLight->globalInteractions, vLight->localInteractions );
|
|
}
|
|
glDisable( GL_STENCIL_TEST );
|
|
}
|
|
|
|
glEnable( GL_STENCIL_TEST );
|
|
}
|
|
|
|
//=========================================================================================
|
|
|
|
static const shaderStage_t *RB_FirstDrawableParticleStage( const drawSurf_t *surf, idImage *&image, uint32_t &blendMode ) {
|
|
image = NULL;
|
|
blendMode = 0;
|
|
|
|
if ( !surf || !surf->material || !surf->shaderRegisters ) {
|
|
return NULL;
|
|
}
|
|
|
|
for ( int stage = 0; stage < surf->material->GetNumStages(); stage++ ) {
|
|
const shaderStage_t *pStage = surf->material->GetStage( stage );
|
|
if ( pStage->lighting != SL_AMBIENT ) {
|
|
continue;
|
|
}
|
|
if ( surf->shaderRegisters[pStage->conditionRegister] == 0.0f ) {
|
|
continue;
|
|
}
|
|
|
|
image = pStage->texture.image;
|
|
const int srcBlend = pStage->drawStateBits & GLS_SRCBLEND_BITS;
|
|
const int dstBlend = pStage->drawStateBits & GLS_DSTBLEND_BITS;
|
|
if ( srcBlend == GLS_SRCBLEND_ONE && dstBlend == GLS_DSTBLEND_ONE ) {
|
|
blendMode = 1;
|
|
}
|
|
return pStage;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static void RB_FillScreenSpaceParticleVertex( glScreenSpaceParticleVertex_t &dst, const idDrawVert &src, const viewEntity_t *space, const float *projectionMatrix, const float stageColor[4] ) {
|
|
idVec3 world;
|
|
idPlane eye, clip;
|
|
|
|
R_LocalPointToGlobal( space->modelMatrix, src.xyz, world );
|
|
R_TransformModelToClip( src.xyz, space->modelViewMatrix, projectionMatrix, eye, clip );
|
|
|
|
dst.clip[0] = clip[0];
|
|
dst.clip[1] = clip[1];
|
|
dst.clip[2] = 0.5f * ( clip[2] + clip[3] );
|
|
dst.clip[3] = clip[3];
|
|
dst.st[0] = src.st[0];
|
|
dst.st[1] = src.st[1];
|
|
dst.color[0] = ( src.color[0] * ( 1.0f / 255.0f ) ) * stageColor[0];
|
|
dst.color[1] = ( src.color[1] * ( 1.0f / 255.0f ) ) * stageColor[1];
|
|
dst.color[2] = ( src.color[2] * ( 1.0f / 255.0f ) ) * stageColor[2];
|
|
dst.color[3] = ( src.color[3] * ( 1.0f / 255.0f ) ) * stageColor[3];
|
|
dst.world[0] = world[0];
|
|
dst.world[1] = world[1];
|
|
dst.world[2] = world[2];
|
|
dst.pad0 = 0.0f;
|
|
}
|
|
|
|
static void RB_SubmitScreenSpaceParticleSurf( const drawSurf_t *surf ) {
|
|
if ( !surf || !surf->geo || !surf->space || !surf->material || !surf->geo->verts || !surf->geo->indexes ) {
|
|
return;
|
|
}
|
|
if ( !surf->geo->numIndexes || !surf->geo->numVerts ) {
|
|
return;
|
|
}
|
|
|
|
idImage *image = NULL;
|
|
uint32_t blendMode = 0;
|
|
const shaderStage_t *stage = RB_FirstDrawableParticleStage( surf, image, blendMode );
|
|
if ( !stage ) {
|
|
return;
|
|
}
|
|
|
|
float stageColor[4];
|
|
for ( int i = 0; i < 4; i++ ) {
|
|
stageColor[i] = surf->shaderRegisters[stage->color.registers[i]];
|
|
}
|
|
|
|
if ( image ) {
|
|
image->Bind();
|
|
} else {
|
|
globalImages->whiteImage->Bind();
|
|
image = globalImages->whiteImage;
|
|
}
|
|
|
|
float projectionMatrix[16];
|
|
memcpy( projectionMatrix, backEnd.viewDef->projectionMatrix, sizeof( projectionMatrix ) );
|
|
if ( surf->space->weaponDepthHack ) {
|
|
projectionMatrix[14] *= 0.25f;
|
|
}
|
|
if ( surf->space->modelDepthHack != 0.0f ) {
|
|
projectionMatrix[14] -= surf->space->modelDepthHack;
|
|
}
|
|
|
|
idList<glScreenSpaceParticleVertex_t> particleVerts;
|
|
particleVerts.SetNum( surf->geo->numIndexes, false );
|
|
for ( int i = 0; i < surf->geo->numIndexes; i++ ) {
|
|
const int vertIndex = surf->geo->indexes[i];
|
|
if ( vertIndex < 0 || vertIndex >= surf->geo->numVerts ) {
|
|
continue;
|
|
}
|
|
RB_FillScreenSpaceParticleVertex( particleVerts[i], surf->geo->verts[vertIndex], surf->space, projectionMatrix, stageColor );
|
|
}
|
|
|
|
glDrawScreenSpaceParticlesQD3D12( particleVerts.Ptr(), particleVerts.Num(), image->texnum, blendMode, 16.0f );
|
|
}
|
|
|
|
static void RB_STD_DrawScreenSpaceParticles( drawSurf_t **drawSurfs, int numDrawSurfs ) {
|
|
if ( !r_screenSpaceParticles.GetBool() || !backEnd.viewDef->viewEntitys ) {
|
|
return;
|
|
}
|
|
|
|
RB_LogComment( "---------- RB_STD_DrawScreenSpaceParticles ----------\n" );
|
|
|
|
for ( int i = 0; i < numDrawSurfs; i++ ) {
|
|
if ( drawSurfs[i]->dsFlags & DSF_SCREEN_SPACE_PARTICLE ) {
|
|
RB_SubmitScreenSpaceParticleSurf( drawSurfs[i] );
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
=============
|
|
RB_STD_DrawView
|
|
|
|
=============
|
|
*/
|
|
void RB_STD_DrawView( void ) {
|
|
drawSurf_t **drawSurfs;
|
|
int numDrawSurfs;
|
|
|
|
RB_LogComment( "---------- RB_STD_DrawView ----------\n" );
|
|
|
|
backEnd.depthFunc = GLS_DEPTHFUNC_EQUAL;
|
|
|
|
drawSurfs = (drawSurf_t **)&backEnd.viewDef->drawSurfs[0];
|
|
numDrawSurfs = backEnd.viewDef->numDrawSurfs;
|
|
|
|
// clear the z buffer, set the projection matrix, etc
|
|
RB_BeginDrawingView();
|
|
|
|
// Draw the sky.
|
|
RB_DrawSkyDome(backEnd.viewDef);
|
|
|
|
// fill the depth buffer and clear color buffer to black except on
|
|
// subviews
|
|
RB_STD_FillDepthBuffer( drawSurfs, numDrawSurfs );
|
|
|
|
RB_STD_DrawScreenSpaceParticles( drawSurfs, numDrawSurfs );
|
|
|
|
// main light renderer
|
|
RB_DXDrawInteractions();
|
|
|
|
// now draw any non-light dependent shading passes
|
|
int processed = RB_STD_DrawShaderPasses( drawSurfs, numDrawSurfs );
|
|
|
|
// fob and blend lights
|
|
RB_STD_FogAllLights();
|
|
|
|
// now draw any post-processing effects using _currentRender
|
|
if ( processed < numDrawSurfs ) {
|
|
RB_STD_DrawShaderPasses( drawSurfs+processed, numDrawSurfs-processed );
|
|
}
|
|
|
|
RB_RenderDebugTools( drawSurfs, numDrawSurfs );
|
|
|
|
}
|