Thsfx

From ProjectWiki
(Difference between revisions)
Jump to: navigation, search
(New page: <big>NDS special effect library</big> __TOC__ ==What is this?== This is a simple library for controlling special effects functions in the form of macros for the Nintendo DS's sprite and ba...)
 
 
(17 intermediate revisions by 6 users not shown)
Line 5: Line 5:
  
 
==Where do i get it?==
 
==Where do i get it?==
 +
Currently the sources for this are part of [http://blea.ch/wiki/index.php/Category:LIBTHDS LibThds]. The source can be downloaded via SVN (see libthds page) or directly from the svn httpd:<br>
 +
* [http://svn.blea.ch/thdslib/trunk/thdslib/source/arm9/include/thsfx.h thsfx.h]
  
==Functions==
+
Okay I'm convinced. Let's put it to atcion.
'''thSfxEnable'''
+
This enables special effects on the specified screen.
+
* s - screen 0 ~ 1
+
* t - type of effect. See ''Effects Types'' below.
+
* a - First target layer for blending/alpha or fade effects. See ''Layer List'' below.
+
* b - Second target layer, which should be of lower priority than the first.
+
<source lang="c">
+
#define thSfxEnable(s, t, a, b) (REG_BLDCNT(s) = ((a)+((b)<<8)+((t)<<6)))
+
</source>
+
 
+
'''thSfxSetBrightness'''
+
Sets fade effect amount. For this effect only the first target set by ''thSfxEnable'' is relevant "For each pixel each R, G, B intensities are calculated separately:"<br>
+
I = I1st + (31-I1st)*EVY  ;For Brightness Increase
+
I = I1st - (I1st)*EVY      ;For Brightness Decrease
+
  
* s - screen 0 ~ 1
+
==Examples==
* b - fade amount 0 ~ 31. 0 = no fade, 31 = fully faded (EVY)
+
'''Fadeout'''<br>
 +
Fade screen 0 to black.
 
<source lang="c">
 
<source lang="c">
#define thSfxSetBrightness(s, b) (REG_BLDY(s) = (b))
+
thSfxEnable(0, SFX_BRIGHTDEC, SFX_BG0|SFX_BG1|SFX_BG2|SFX_BG3|SFX_OBJ|SFX_BD, SFX_NONE);
 +
int fade=0;
 +
do {
 +
  thSfxSetBrightness(0, fade);
 +
  swiWaitForVBlank();
 +
} while(++fade<=SFX_MAX);
 
</source>
 
</source>
  
'''thSfxSetAlphaBlend'''
+
'''Fade to White'''<br>
Sets blend amount. "For this effect, the top-most non-transparent pixel must be selected as 1st Target, and the next-lower non-transparent pixel must be selected as 2nd Target, if so - and only if so, then color intensities of 1st and 2nd Target are mixed together by using the parameters ''set by thSfxSetAlphaBlend'', for each pixel each R, G, B intensities are calculated separately:"<br>
+
Fade screen 1 to White slowly.
Formula for resulting blend:
+
I = MIN(31, I1st*EVA + I2nd*EVB)
+
 
+
* s - screen 0 ~ 1
+
* a - target a coefficient (EVA)
+
* b - target b coefficient (EVB)
+
//blend max coef value == 31
+
 
<source lang="c">
 
<source lang="c">
#define thSfxSetAlphaBlend(s, a, b) (REG_BLDALPHA(s)=(a)+((b)<<8))
+
thSfxEnable(1, SFX_BRIGHTINC, SFX_BG0|SFX_BG1|SFX_BG2|SFX_BG3|SFX_OBJ|SFX_BD, SFX_NONE);
 +
int fade=0;
 +
do {
 +
  thSfxSetBrightness(1, fade>>2);
 +
  swiWaitForVBlank();
 +
} while(++fade<=(SFX_MAX<<2));
 
</source>
 
</source>
  
'''Layer list'''
+
'''Blend backgrounds with sprites'''<br>
Here is a list of layer definitions, they may be or'd together in which case the topmost pixel of each target will be used.
+
Blend sprites evenly with backgrounds
 
<source lang="c">
 
<source lang="c">
#define SFX_BG0 1
+
thSfxEnable(0, SFX_BRIGHTINC, SFX_OBJ, SFX_BG0|SFX_BG1|SFX_BG2|SFX_BG3|SFX_BD);
#define SFX_BG1 2
+
thSfxSetAlphaBlend(0, 15, 15);
#define SFX_BG2 4
+
#define SFX_BG3 8
+
#define SFX_OBJ 16
+
#define SFX_BD  32
+
 
</source>
 
</source>
  
'''Effects Types'''
+
[[Category:NDS]]
<source lang="c">
+
[[Category:C]]
#define SFX_NONE 0
+
[[Category:LIBTHDS]]
#define SFX_ALPHA 1
+
#define SFX_BRIGHTINC 2
+
#define SFX_BRIGHTDEC 3
+
</source>
+
 
+
'''Misc Macros''
+
These functions may be used to obtain the registers for special effects control.
+
* s - screen 0 ~ 1
+
<source lang="c">
+
#define REG_BLDCNT(s)  (*(uint16 *)(0x04000050+((s)*0x1000)))
+
#define REG_BLDALPHA(s) (*(uint16 *)(0x04000052+((s)*0x1000)))
+
#define REG_BLDY(s) (*(uint16 *)(0x04000054+((s)*0x1000)))
+
</source>
+

Latest revision as of 14:16, 13 August 2011

NDS special effect library

Contents

What is this?

This is a simple library for controlling special effects functions in the form of macros for the Nintendo DS's sprite and background hardware. These functions are available for both screens.

Where do i get it?

Currently the sources for this are part of LibThds. The source can be downloaded via SVN (see libthds page) or directly from the svn httpd:

Okay I'm convinced. Let's put it to atcion.

Examples

Fadeout
Fade screen 0 to black.

thSfxEnable(0, SFX_BRIGHTDEC, SFX_BG0|SFX_BG1|SFX_BG2|SFX_BG3|SFX_OBJ|SFX_BD, SFX_NONE);
int fade=0;
do {
  thSfxSetBrightness(0, fade);
  swiWaitForVBlank();
} while(++fade<=SFX_MAX);

Fade to White
Fade screen 1 to White slowly.

thSfxEnable(1, SFX_BRIGHTINC, SFX_BG0|SFX_BG1|SFX_BG2|SFX_BG3|SFX_OBJ|SFX_BD, SFX_NONE);
int fade=0;
do {
  thSfxSetBrightness(1, fade>>2);
  swiWaitForVBlank();
} while(++fade<=(SFX_MAX<<2));

Blend backgrounds with sprites
Blend sprites evenly with backgrounds

thSfxEnable(0, SFX_BRIGHTINC, SFX_OBJ, SFX_BG0|SFX_BG1|SFX_BG2|SFX_BG3|SFX_BD);
thSfxSetAlphaBlend(0, 15, 15);
Personal tools
irssi scripts
eggdrop scripts