ioquake / ioq3

The ioquake3 community effort to continue supporting/developing id's Quake III Arena
https://www.ioquake3.org/
GNU General Public License v2.0
2.34k stars 522 forks source link

Changes to OpenGL2 Renderer's ComputeShaderColors Function Broke My Particles #619

Closed WHS-Phoenix closed 7 months ago

WHS-Phoenix commented 7 months ago

I recently ported my mod's engine changes into IOQuake3, and I'm having trouble with the OpenGL2 renderer. I've been using a particle system that relies on a single entity entrypoint into the renderer using an rgbGen exactvertex shader keyword, then colorizing the particles using internally computed values to assign to the vertex color array using RB_AddQuadStamp. For OpenGL1 I was able to pretty much just copy and paste the logic in from Quake 3 1.32b's source code. OpenGL2, however, changed the entire logic for ComputeShaderColors.

This:

    case CGEN_EXACT_VERTEX:
        Com_Memcpy( tess.svars.colors, tess.vertexColors, tess.numVertexes * sizeof( tess.vertexColors[0] ) );
        break;

Changed to this:

    case CGEN_EXACT_VERTEX:
    case CGEN_EXACT_VERTEX_LIT:

        baseColor[0] = 
        baseColor[1] =
        baseColor[2] = 
        baseColor[3] = 0.0f;

        vertColor[0] =
        vertColor[1] =
        vertColor[2] = overbright;
        vertColor[3] = 1.0f;

        break;

This causes the color values in my particle logic to go nowhere as prior they were read from tess.vertexColors and copied into tess.svars.colors. In OpenGL2's function no color values are set at all. This causes null values to be computed across my particles, making them flash red and black. I would attempt to revert the color logic, however something tells me this change was done for a reason and there might be a better way. In addition, the shaderCommands_t struct was changed and vertexColors is no longer an element. Any help would be appreciated.

zturtleman commented 7 months ago

The rocket trail sprites (smokePuff shader) use rgbGen vertex and are not broken. I didn't tested exactVertex right now but it probably works.

tess.color (unsigned short [4]) is set in RB_AddQuadStampExt(). tess.color becomes attr_Color in the GLSL shaders. vertColor becomes a multiplier for the vertex color (attr_Color) in the GLSL shaders.

https://github.com/ioquake/ioq3/blob/78359180a447f1292787b8a8ebaa6405c6f87eed/code/renderergl2/glsl/generic_vp.glsl#L162

https://github.com/ioquake/ioq3/blob/78359180a447f1292787b8a8ebaa6405c6f87eed/code/renderergl2/glsl/lightall_vp.glsl#L218

RB_AddQuadStamp() in the opengl2 renderer expects color to be float[4] in the range of 0.0 to 1.0. The opengl1 renderer expects color to be byte[4] in the range 0 to 255.

This code is used to convert sprite byte color from 0-255 to 0.0-1.0 range for opengl2's RB_AddQuadStamp().

    float           colors[4];
    VectorScale4(ent->e.shaderRGBA, 1.0f / 255.0f, colors);
    RB_AddQuadStamp( ent->e.origin, left, up, colors );
WHS-Phoenix commented 7 months ago

I adapted your conversion and it works flawlessly! My particles look better than ever. The last thing I would have expected was a simple normalization to be at fault. Thanks!