From ad0d73d8f069abb8b76df66e97655dbf7201cda5 Mon Sep 17 00:00:00 2001 From: aliaspider Date: Sat, 16 Apr 2016 22:38:13 +0100 Subject: [PATCH] (3DS) refactor shaders. simplify texture combiner usage. --- gfx/drivers/ctr_gfx.c | 31 +++++------------ gfx/drivers/ctr_sprite.gsh | 70 +++++++++++++++----------------------- gfx/drivers/ctr_sprite.vsh | 44 +++++++++++++----------- 3 files changed, 62 insertions(+), 83 deletions(-) diff --git a/gfx/drivers/ctr_gfx.c b/gfx/drivers/ctr_gfx.c index c602898f1e..1f488d764c 100644 --- a/gfx/drivers/ctr_gfx.c +++ b/gfx/drivers/ctr_gfx.c @@ -338,19 +338,12 @@ static void* ctr_init(const video_info_t* video, GPU_SetTextureEnable(GPU_TEXUNIT0); - GPU_SetTexEnv(0, - GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, 0), - GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, 0), - GPU_TEVOPERANDS(0, 0, 0), - GPU_TEVOPERANDS(0, 0, 0), - GPU_MODULATE, GPU_MODULATE, - 0xFFFFFFFF); - - GPU_SetTexEnv(1, GPU_PREVIOUS,GPU_PREVIOUS, 0, 0, 0, 0, 0); - GPU_SetTexEnv(2, GPU_PREVIOUS,GPU_PREVIOUS, 0, 0, 0, 0, 0); - GPU_SetTexEnv(3, GPU_PREVIOUS,GPU_PREVIOUS, 0, 0, 0, 0, 0); - GPU_SetTexEnv(4, GPU_PREVIOUS,GPU_PREVIOUS, 0, 0, 0, 0, 0); - GPU_SetTexEnv(5, GPU_PREVIOUS,GPU_PREVIOUS, 0, 0, 0, 0, 0); + GPU_SetTexEnv(0, GPU_TEXTURE0, GPU_TEXTURE0, 0, 0, GPU_REPLACE, GPU_REPLACE, 0); + GPU_SetTexEnv(1, GPU_PREVIOUS, GPU_PREVIOUS, 0, 0, 0, 0, 0); + GPU_SetTexEnv(2, GPU_PREVIOUS, GPU_PREVIOUS, 0, 0, 0, 0, 0); + GPU_SetTexEnv(3, GPU_PREVIOUS, GPU_PREVIOUS, 0, 0, 0, 0, 0); + GPU_SetTexEnv(4, GPU_PREVIOUS, GPU_PREVIOUS, 0, 0, 0, 0, 0); + GPU_SetTexEnv(5, GPU_PREVIOUS, GPU_PREVIOUS, 0, 0, 0, 0, 0); ctrGuSetAttributeBuffers(2, VIRT_TO_PHYS(ctr->menu.frame_coords), @@ -615,15 +608,9 @@ static bool ctr_frame(void* data, const void* frame, /* restore */ if (ctr->rgb32) { - GPU_SetTexEnv(0, - GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, 0), - GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, 0), - GPU_TEVOPERANDS(0, 0, 0), - GPU_TEVOPERANDS(0, 0, 0), - GPU_MODULATE, GPU_MODULATE, - 0xFFFFFFFF); - GPU_SetTexEnv(1, GPU_PREVIOUS,GPU_PREVIOUS, 0, 0, 0, 0, 0); - GPU_SetTexEnv(2, GPU_PREVIOUS,GPU_PREVIOUS, 0, 0, 0, 0, 0); + GPU_SetTexEnv(0, GPU_TEXTURE0, GPU_TEXTURE0, 0, 0, GPU_REPLACE, GPU_REPLACE, 0); + GPU_SetTexEnv(1, GPU_PREVIOUS, GPU_PREVIOUS, 0, 0, 0, 0, 0); + GPU_SetTexEnv(2, GPU_PREVIOUS, GPU_PREVIOUS, 0, 0, 0, 0, 0); } if (ctr->menu_texture_enable) diff --git a/gfx/drivers/ctr_sprite.gsh b/gfx/drivers/ctr_sprite.gsh index 4750f79872..8309157aa3 100644 --- a/gfx/drivers/ctr_sprite.gsh +++ b/gfx/drivers/ctr_sprite.gsh @@ -1,65 +1,51 @@ -; Uniforms -;.fvec scale_vector -;.alias viewport_scale scale_vector.yxyx -;.alias texture_scale scale_vector.zwzw .gsh -.fvec c0_ +.entry main_gsh -.constf c20_(1.0, 1.0, 1.0, 1.0) -.constf c21_(0.0, 0.0, 0.0, 0.0) -.constf c22_(0.0, 1.0, 0.0, 1.0) -.constf c23_(0.0, 0.0, -1.0, 1.0) +; Constants +.constf _01N1 (0.0, 1.0, -1.0, 1.0) +.alias _0000 _01N1.xxxx +.alias _1111 _01N1.yyyy +.alias _0101 _01N1.xyxy +.alias _N1N1 _01N1.zwzw ; Inputs .alias sprite_coords v0 .alias tex_size v1 +.alias top_left sprite_coords.xyxy +.alias bottom_right sprite_coords.zwzw -.out o0_ position -.out o1_ color -.out o2_ texcoord0 +; Outputs +.out pos position +.out texcoord texcoord0 -.entry main_gsh .proc main_gsh setemit 0 - mov o0_.xy, v0 - - mov o0_.zw, c23_.zwzw - mov o1_, c20_ - - mov o2_, v1 + mov pos.xy, top_left.xy + mov pos.zw, _N1N1 + mov texcoord.xy, tex_size.xy emit setemit 1 - mov o0_.x, v0 - mov o0_.y, v0.zwzw - - mov o0_.zw, c23_.zwzw - mov o1_, c20_ - - mov o2_.x, v1.zwzw - mov o2_.yzw, v1.xyxy + mov pos.x, top_left.x + mov pos.y, bottom_right.y + mov pos.zw, _N1N1 + mov texcoord.x, tex_size.z + mov texcoord.y, tex_size.y emit setemit 2, prim inv - mov o0_.xy, v0.zw - - mov o0_.zw, c23_.zwzw - mov o1_, c20_ - - mov o2_, v1_.zwzw + mov pos.xy, bottom_right.xy + mov pos.zw, _N1N1 + mov texcoord.xy, tex_size.zw emit setemit 1, prim - mov o0_.x, v0.zwzw - mov o0_.y, v0 - - mov o0_.zw, c23_.zwzw - mov o1_, c20_ - - mov o2_.x, v1 - mov o2_.yzw, v1.zwzw + mov pos.x, bottom_right.x + mov pos.y, top_left.y + mov pos.zw, _N1N1 + mov texcoord.x, tex_size.x + mov texcoord.y, tex_size.w emit - end .end diff --git a/gfx/drivers/ctr_sprite.vsh b/gfx/drivers/ctr_sprite.vsh index 0fd1113098..fc1a5259a6 100644 --- a/gfx/drivers/ctr_sprite.vsh +++ b/gfx/drivers/ctr_sprite.vsh @@ -1,27 +1,33 @@ -; Uniforms -;.fvec scale_vector -;.alias viewport_scale scale_vector.yxyx -;.alias texture_scale scale_vector.zwzw -.fvec c0_ +;.vsh +.entry main_vsh -.constf c20_(1.0, 1.0, 1.0, 1.0) -.constf c21_(0.0, 0.0, 0.0, 0.0) -.constf c22_(0.0, 1.0, 0.0, 1.0) -.constf c23_(0.0, 0.0, -1.0, 1.0) +; Uniforms +.fvec scale_vector +.alias viewport_scale scale_vector.yxyx +.alias texture_scale scale_vector.zwzw + +; Constants +.constf _01N1 (0.0, 1.0, -1.0, 1.0) +.alias _0000 _01N1.xxxx +.alias _1111 _01N1.yyyy +.alias _0101 _01N1.xyxy ; Inputs -;.alias pos v0 -;.alias tex_coord v1 +.alias pos_in v0 +.alias texcoord_in v1 -.out o0_ position -.out o1_ texcoord0 +; Output +.out pos position +.out texcoord texcoord0 +.out color color -.entry main_vsh .proc main_vsh - mul r0, c0_.yxyx, v0.yxwz - add o0_, c20_, r0 - mul r1.zw, c0_.zwzw, v1.xyxy - mov r1.xy, c21_ - add o1_, c22_, r1 + + mul r0, viewport_scale, pos_in.yxwz + add pos, _1111, r0 + mul r1.zw, texture_scale, texcoord_in.xyxy + mov r1.xy, _0000 + add texcoord, _0101, r1 + end .end