Skip to content

Commit 02f82d0

Browse files
Implement 1-Texture ADD & SUB for image tint
Makes the texture use 1-RGB mode instead of RGB mode for ADD and SUB if the tint function is called with `C2D_TintOneMinusAdd` or `C2D_TintOneMinusSub`
1 parent 0d65548 commit 02f82d0

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

include/c2d/base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ typedef enum
3939
C2D_TintLuma, ///< Tint color multiplied by grayscale converted texture color
4040
C2D_TintAdd, ///< Tint color added to the texture color
4141
C2D_TintSub, ///< Tint color subtracted from the texture color
42+
C2D_TintOneMinusAdd, ///< 1 - Texture.rgb + tint color
43+
C2D_TintOneMinusSub, ///< 1 - Texture.rgb - tint color
4244
} C2D_TintMode;
4345

4446
typedef struct

source/base.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ bool C2D_SetTintMode(C2D_TintMode mode)
335335
case C2D_TintSub:
336336
new_mode = C2DiF_Mode_ImageSub;
337337
break;
338+
case C2D_TintOneMinusAdd:
339+
new_mode = C2DiF_Mode_ImageOMAdd;
340+
break;
341+
case C2D_TintOneMinusSub:
342+
new_mode = C2DiF_Mode_ImageOMSub;
343+
break;
338344
}
339345

340346
ctx->flags = (ctx->flags &~ C2DiF_TintMode_Mask) | (new_mode << (C2DiF_TintMode_Shift - C2DiF_Mode_Shift));
@@ -721,21 +727,26 @@ void C2Di_Update(void)
721727
break;
722728
}
723729
case C2DiF_Mode_ImageAdd:
730+
case C2DiF_Mode_ImageOMAdd:
724731
{
725732
// Use texenv to blend the color source with the addition-tinted version of it,
726733
// according to a parameter that is passed through with the help of proctex.
727734
proctex = C2DiF_ProcTex_Blend;
728735

729736
// texenv0 = texclr + vtxcolor
737+
// texenv0 = (1-texclr) + vtxcolor
730738
env = C3D_GetTexEnv(0);
731739
C3D_TexEnvInit(env);
732-
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR);
740+
C3D_TexEnvSrc(env, C3D_RGB, GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR);
741+
if (mode == C2DiF_Mode_ImageOMAdd){ // if OM set to ONE MINUS
742+
C3D_TexEnvOpRgb(env, GPU_TEVOP_RGB_ONE_MINUS_SRC_COLOR, GPU_TEVOP_RGB_SRC_COLOR, GPU_TEVOP_RGB_ONE_MINUS_SRC_ALPHA);
743+
}
733744
C3D_TexEnvFunc(env, C3D_RGB, GPU_ADD);
734745

735746
// texenv1.rgb = mix(texclr.rgb, texenv0.rgb, vtx.blend.y);
736747
env = C3D_GetTexEnv(1);
737748
C3D_TexEnvInit(env);
738-
C3D_TexEnvSrc(env, C3D_RGB, GPU_TEXTURE0, GPU_PREVIOUS, GPU_TEXTURE3);
749+
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_PREVIOUS, GPU_TEXTURE3);
739750
C3D_TexEnvOpRgb(env, GPU_TEVOP_RGB_SRC_COLOR, GPU_TEVOP_RGB_SRC_COLOR, GPU_TEVOP_RGB_ONE_MINUS_SRC_ALPHA);
740751
C3D_TexEnvFunc(env, C3D_RGB, GPU_INTERPOLATE);
741752

@@ -745,21 +756,26 @@ void C2Di_Update(void)
745756
break;
746757
}
747758
case C2DiF_Mode_ImageSub:
759+
case C2DiF_Mode_ImageOMSub:
748760
{
749761
// Use texenv to blend the color source with the subtraction-tinted version of it,
750762
// according to a parameter that is passed through with the help of proctex.
751763
proctex = C2DiF_ProcTex_Blend;
752764

753765
// texenv0 = texclr - vtxcolor
766+
// texenv0 = (1-texclr) - vtxcolor
754767
env = C3D_GetTexEnv(0);
755768
C3D_TexEnvInit(env);
756-
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR);
769+
C3D_TexEnvSrc(env, C3D_RGB, GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR);
770+
if (mode == C2DiF_Mode_ImageOMSub){ // if OM set to ONE MINUS
771+
C3D_TexEnvOpRgb(env, GPU_TEVOP_RGB_ONE_MINUS_SRC_COLOR, GPU_TEVOP_RGB_SRC_COLOR, GPU_TEVOP_RGB_ONE_MINUS_SRC_ALPHA);
772+
}
757773
C3D_TexEnvFunc(env, C3D_RGB, GPU_SUBTRACT);
758774

759775
// texenv1.rgb = mix(texclr.rgb, texenv0.rgb, vtx.blend.y);
760776
env = C3D_GetTexEnv(1);
761777
C3D_TexEnvInit(env);
762-
C3D_TexEnvSrc(env, C3D_RGB, GPU_TEXTURE0, GPU_PREVIOUS, GPU_TEXTURE3);
778+
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_PREVIOUS, GPU_TEXTURE3);
763779
C3D_TexEnvOpRgb(env, GPU_TEVOP_RGB_SRC_COLOR, GPU_TEVOP_RGB_SRC_COLOR, GPU_TEVOP_RGB_ONE_MINUS_SRC_ALPHA);
764780
C3D_TexEnvFunc(env, C3D_RGB, GPU_INTERPOLATE);
765781

source/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ enum
5757
C2DiF_Mode_ImageLuma = 5 << C2DiF_Mode_Shift,
5858
C2DiF_Mode_ImageAdd = 6 << C2DiF_Mode_Shift,
5959
C2DiF_Mode_ImageSub = 7 << C2DiF_Mode_Shift,
60+
C2DiF_Mode_ImageOMAdd = 8 << C2DiF_Mode_Shift,
61+
C2DiF_Mode_ImageOMSub = 9 << C2DiF_Mode_Shift,
6062

6163
C2DiF_ProcTex_Shift = 12,
6264
C2DiF_ProcTex_Mask = 0xf << C2DiF_ProcTex_Shift,

0 commit comments

Comments
 (0)