Skip to content

Commit

Permalink
Allow Soft Particles for player-weapons after all, fix issue properly
Browse files Browse the repository at this point in the history
The previous commit didn't fix the issue for the pistol and only was a
workaround anyway. So I reverted that and fixed the issue properly.

The underlying issue is that the particle's material sets the
texture matrix (with "translate" or "scale" or whatever), and the soft
particle rendering code (and shader) didn't take the texture matrix
into account.
Now it does, in a similar way as the interaction shader code.

Fixes dhewm/dhewm3-sdk#36
  • Loading branch information
DanielGibson committed Jul 29, 2024
1 parent 227071b commit cef1178
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
7 changes: 6 additions & 1 deletion neo/renderer/draw_arb2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,12 @@ const char* softpartVShader = "!!ARBvp1.0 \n"
"OPTION ARB_position_invariant; \n"
"# NOTE: unlike the TDM shader, the following lines use .texcoord and .color \n"
"# instead of .attrib[8] and .attrib[3], to make it work with non-nvidia drivers \n"
"MOV result.texcoord, vertex.texcoord; \n"
"# Furthermore, I added support for a texture matrix \n"
"PARAM defaultTexCoord = { 0, 0.5, 0, 1 }; \n"
"MOV result.texcoord, defaultTexCoord; \n"
"# program.env[12] is PP_DIFFUSE_MATRIX_S, 13 is PP_DIFFUSE_MATRIX_T \n"
"DP4 result.texcoord.x, vertex.texcoord, program.env[12]; \n"
"DP4 result.texcoord.y, vertex.texcoord, program.env[13]; \n"
"MOV result.color, vertex.color; \n"
"END \n";

Expand Down
31 changes: 31 additions & 0 deletions neo/renderer/draw_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,37 @@ void RB_STD_T_RenderShaderPasses( const drawSurf_t *surf ) {
printf("XX mat: %s, src_blend = %s dest_blend = %s radius = %g\n", shader->GetName(), srcblendstr, dstblend, surf->particle_radius);
#endif

// DG: some particle materials (at least the muzzle flash in dentonmod) set the
// texture matrix (with scroll, translate, scale, centerScale, shear or rotate).
// Support that like in R_SetDrawInteraction() (the soft particle shader only
// uses one texture, so I set the diffuse matrix for it)
idVec4 texMatrix[2];
if ( pStage->texture.hasMatrix ) {
texMatrix[0][0] = regs[pStage->texture.matrix[0][0]];
texMatrix[0][1] = regs[pStage->texture.matrix[0][1]];
texMatrix[0][2] = 0;
texMatrix[0][3] = regs[pStage->texture.matrix[0][2]];

texMatrix[1][0] = regs[pStage->texture.matrix[1][0]];
texMatrix[1][1] = regs[pStage->texture.matrix[1][1]];
texMatrix[1][2] = 0;
texMatrix[1][3] = regs[pStage->texture.matrix[1][2]];

// we attempt to keep scrolls from generating incredibly large texture values, but
// center rotations and center scales can still generate offsets that need to be > 1
if ( texMatrix[0][3] < -40 || texMatrix[0][3] > 40 ) {
texMatrix[0][3] -= (int)texMatrix[0][3];
}
if ( texMatrix[1][3] < -40 || texMatrix[1][3] > 40 ) {
texMatrix[1][3] -= (int)texMatrix[1][3];
}
} else {
texMatrix[0].Set( 1, 0, 0, 0 );
texMatrix[1].Set( 0, 1, 0, 0 );
}
qglProgramEnvParameter4fvARB( GL_VERTEX_PROGRAM_ARB, PP_DIFFUSE_MATRIX_S, texMatrix[0].ToFloatPtr() );
qglProgramEnvParameter4fvARB( GL_VERTEX_PROGRAM_ARB, PP_DIFFUSE_MATRIX_T, texMatrix[1].ToFloatPtr() );

// program.env[23] is the particle radius, given as { radius, 1/(faderange), 1/radius }
float fadeRange = 1.0f;
// fadeRange is the particle diameter for alpha blends (like smoke), but the particle radius for additive
Expand Down
4 changes: 1 addition & 3 deletions neo/renderer/tr_light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1443,9 +1443,7 @@ static void R_AddAmbientDrawsurfs( viewEntity_t *vEntity ) {
float particle_radius = -1.0f; // Default = disallow softening, but allow modelDepthHack if specified in the decl.
if ( r_useSoftParticles.GetBool() && r_enableDepthCapture.GetInteger() != 0
&& !shader->ReceivesLighting() // don't soften surfaces that are meant to be solid
&& tr.viewDef->renderView.viewID >= 0 // Skip during "invisible" rendering passes (e.g. lightgem)
// don't apply to particles spawned at the player-weapon (like muzzle flash)
&& !vEntity->weaponDepthHack ) // to fix https://github.com/dhewm/dhewm3-sdk/issues/36
&& tr.viewDef->renderView.viewID >= 0 ) // Skip during "invisible" rendering passes (e.g. lightgem)
{
const idRenderModelPrt* prt = dynamic_cast<const idRenderModelPrt*>( def->parms.hModel ); // yuck.
if ( prt )
Expand Down

0 comments on commit cef1178

Please sign in to comment.