Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/c2d/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ typedef enum
C2D_TintSolid, ///< Plain solid tint color
C2D_TintMult, ///< Tint color multiplied by texture color
C2D_TintLuma, ///< Tint color multiplied by grayscale converted texture color
C2D_TintAdd, ///< Tint color added to the texture color
C2D_TintSub, ///< Tint color subtracted from the texture color
C2D_TintOneMinusAdd, ///< 1 - Texture.rgb + tint color
C2D_TintOneMinusSub, ///< 1 - Texture.rgb - tint color
} C2D_TintMode;

typedef struct
Expand Down
70 changes: 70 additions & 0 deletions source/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,18 @@ bool C2D_SetTintMode(C2D_TintMode mode)
case C2D_TintLuma:
new_mode = C2DiF_Mode_ImageLuma;
break;
case C2D_TintAdd:
new_mode = C2DiF_Mode_ImageAdd;
break;
case C2D_TintSub:
new_mode = C2DiF_Mode_ImageSub;
break;
case C2D_TintOneMinusAdd:
new_mode = C2DiF_Mode_ImageOMAdd;
break;
case C2D_TintOneMinusSub:
new_mode = C2DiF_Mode_ImageOMSub;
break;
}

ctx->flags = (ctx->flags &~ C2DiF_TintMode_Mask) | (new_mode << (C2DiF_TintMode_Shift - C2DiF_Mode_Shift));
Expand Down Expand Up @@ -714,6 +726,64 @@ void C2Di_Update(void)
C3D_TexEnvFunc(env, C3D_RGB, GPU_INTERPOLATE);
break;
}
case C2DiF_Mode_ImageAdd:
case C2DiF_Mode_ImageOMAdd:
{
// Use texenv to blend the color source with the addition-tinted version of it,
// according to a parameter that is passed through with the help of proctex.
proctex = C2DiF_ProcTex_Blend;

// texenv0 = texclr + vtxcolor
// texenv0 = (1-texclr) + vtxcolor
env = C3D_GetTexEnv(0);
C3D_TexEnvInit(env);
C3D_TexEnvSrc(env, C3D_RGB, GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR);
if (mode == C2DiF_Mode_ImageOMAdd){ // if OM set to ONE MINUS
C3D_TexEnvOpRgb(env, GPU_TEVOP_RGB_ONE_MINUS_SRC_COLOR, GPU_TEVOP_RGB_SRC_COLOR, GPU_TEVOP_RGB_ONE_MINUS_SRC_ALPHA);
}
C3D_TexEnvFunc(env, C3D_RGB, GPU_ADD);

// texenv1.rgb = mix(texclr.rgb, texenv0.rgb, vtx.blend.y);
env = C3D_GetTexEnv(1);
C3D_TexEnvInit(env);
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_PREVIOUS, GPU_TEXTURE3);
C3D_TexEnvOpRgb(env, GPU_TEVOP_RGB_SRC_COLOR, GPU_TEVOP_RGB_SRC_COLOR, GPU_TEVOP_RGB_ONE_MINUS_SRC_ALPHA);
C3D_TexEnvFunc(env, C3D_RGB, GPU_INTERPOLATE);

// Reset unused texenv stages
C3D_TexEnvInit(C3D_GetTexEnv(2));
C3D_TexEnvInit(C3D_GetTexEnv(3));
break;
}
case C2DiF_Mode_ImageSub:
case C2DiF_Mode_ImageOMSub:
{
// Use texenv to blend the color source with the subtraction-tinted version of it,
// according to a parameter that is passed through with the help of proctex.
proctex = C2DiF_ProcTex_Blend;

// texenv0 = texclr - vtxcolor
// texenv0 = (1-texclr) - vtxcolor
env = C3D_GetTexEnv(0);
C3D_TexEnvInit(env);
C3D_TexEnvSrc(env, C3D_RGB, GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR);
if (mode == C2DiF_Mode_ImageOMSub){ // if OM set to ONE MINUS
C3D_TexEnvOpRgb(env, GPU_TEVOP_RGB_ONE_MINUS_SRC_COLOR, GPU_TEVOP_RGB_SRC_COLOR, GPU_TEVOP_RGB_ONE_MINUS_SRC_ALPHA);
}
C3D_TexEnvFunc(env, C3D_RGB, GPU_SUBTRACT);

// texenv1.rgb = mix(texclr.rgb, texenv0.rgb, vtx.blend.y);
env = C3D_GetTexEnv(1);
C3D_TexEnvInit(env);
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_PREVIOUS, GPU_TEXTURE3);
C3D_TexEnvOpRgb(env, GPU_TEVOP_RGB_SRC_COLOR, GPU_TEVOP_RGB_SRC_COLOR, GPU_TEVOP_RGB_ONE_MINUS_SRC_ALPHA);
C3D_TexEnvFunc(env, C3D_RGB, GPU_INTERPOLATE);

// Reset unused texenv stages
C3D_TexEnvInit(C3D_GetTexEnv(2));
C3D_TexEnvInit(C3D_GetTexEnv(3));
break;
}
}

if (proctex && proctex != (ctx->flags & C2DiF_ProcTex_Mask))
Expand Down
4 changes: 4 additions & 0 deletions source/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ enum
C2DiF_Mode_ImageSolid = 3 << C2DiF_Mode_Shift,
C2DiF_Mode_ImageMult = 4 << C2DiF_Mode_Shift,
C2DiF_Mode_ImageLuma = 5 << C2DiF_Mode_Shift,
C2DiF_Mode_ImageAdd = 6 << C2DiF_Mode_Shift,
C2DiF_Mode_ImageSub = 7 << C2DiF_Mode_Shift,
C2DiF_Mode_ImageOMAdd = 8 << C2DiF_Mode_Shift,
C2DiF_Mode_ImageOMSub = 9 << C2DiF_Mode_Shift,

C2DiF_ProcTex_Shift = 12,
C2DiF_ProcTex_Mask = 0xf << C2DiF_ProcTex_Shift,
Expand Down