website logo
Auteur
avatar
thellier

Forum » » Création-Développement » » Oui on peut faire du bump mapping avec Warp3D/Os4


Posté : 22-11-2012 14:21 icone du post

Suite à mon posts sur le fil "Dungeon Crawler Os4 "

"Sur le bumping je pense qu il y a peut etre moyen avec un WaRp3D OS4 cad un v5
avec le multitexturing on peut multiplier un pixel texture par une valeur
donc si la tex contient les normales on doit pouvoir les mettre dans la direction de la lampe "

Depuis ce post je teste le truc ...
Et après nombre compilations/crash/modifs et retests ça marche enfin
http://thellier.free.fr/cowbump.png

C'est basé sur le principe exposé ici mais avec une méthode un peu différente puisque j'utilise les vertex-normals
http://nehe.gamedev.net/article/bump_mapping/25006/

MA METHODE DE BUMPING WARP3D:
-----------------------------------------------------------
Utiliser le multitexturing du vrai Warp3D/OS4 (Pas Wazp3D)
2 passes de texturing :

Texturing0:
tex 0 contient une normal map
Mettre les vertex-normals dans la couleur des points et faire un
dotproduct(couleur,tex)
cad dotproduct(normal,normalmap)
=> on obtient des valeurs de noir-gris-blanc selon l'angle du dotproduct() cad une lightmap

Texturing1:
tex 1 contient la tex habituelle
Faire un W3D_MODULATE de la tex

Voilà

La salle applaudit

Alain Thellier

Notes:
1) comme on utilise la couleur des points on perd un eventuel éclairage normal et coloré (stocké dans la couleur des points) ... à améliorer ...
2) on utilise les vertex-normals qui sont pas dans la direction de la lampe
3) ne pas se fier aux FPS du grab y a une tonne de débug
3) qques parties cruciales du code :

/*==================================================================*/
typedef struct _Point3D
{
float x,y,z;
float color[4];
float u,v,w;
float u1,v1,w1;
float nx,ny,nz;
} Point3D;
----------------------------------------------------------------------------- -------------------------------------------------------
/* Warp3D V5 for Os4 ppc only implement W3D_InterleavedArray() not W3D_Vertex/TexCoord/ColorPointer() */
#ifdef OS4
#define ARRAYFORMAT (W3D_VFORMAT_COLOR|W3D_VFORMAT_TCOORD_0)
#define ARRAYFORMAT2 (W3D_VFORMAT_COLOR|W3D_VFORMAT_TCOORD_0|W3D_VFORMAT_TCOORD_1)
format=ARRAYFORMAT;
if(MAT->MapMode=='B') format=ARRAYFORMAT2; /* bump mapping */
W3D_InterleavedArray(S->context,VertexPointer,stride,format,W3D_TEXCOORD_NOR MALIZED);
#else
TexCoordPointer =(void *)&(P->u);
ColorPointer =(void *)&(P->color);
off_v=(UWORD)( (ULONG)&(P->v) - (ULONG)&(P->u));
off_w=(UWORD)( (ULONG)&(P->w) - (ULONG)&(P->u));
result=W3D_VertexPointer(S->context,VertexPointer,stride,W3D_VERTEX_F_F_F, 0);
result=W3D_TexCoordPointer(S->context,TexCoordPointer,stride,0, off_v, off_w,W3D_TEXCOORD_NORMALIZED);
result=W3D_ColorPointer(S->context,ColorPointer,stride,W3D_COLOR_FLOAT ,W3D_CMODE_RGBA,0);
#endif
----------------------------------------------------------------------------- -------------------------------------------------------
if(MAT->MapMode=='B') /* bump mapping */
{
P->color[0]=((P->nx+1.0)/2.0);
P->color[1]=((P->ny+1.0)/2.0);
P->color[2]=((P->nz+1.0)/2.0);
P->color[3]=1.0;
P->u1=P->u;
P->v1=P->v;
P->w1=P->w;

}
----------------------------------------------------------------------------- --------------------------------------------------------
#ifdef OS4
W3D_SetState(S->context, W3D_MULTITEXTURE, W3D_ENABLE);
NumTMU = W3D_Query(S->context,W3D_Q_NUM_TMU,0);
REM(bind texs)
NLOOP(NumTMU)
{
if(n==0)
W3D_BindTexture(S->context,0, bumptex);
if(n==1)
W3D_BindTexture(S->context,1, state->tex);
if(n>1)
W3D_BindTexture(S->context,n,NULL);
}

REM(all tmus)
NLOOP(NumTMU)
{
if(n==0)
result=W3D_SetTextureBlendTags(S->context,
W3D_BLEND_STAGE, 0,
W3D_COLOR_ARG_A, W3D_ARG_TEXTURE_COLOR,
W3D_COLOR_ARG_B, W3D_ARG_DIFFUSE_COLOR,
W3D_COLOR_COMBINE, W3D_COMBINE_DOT3RGB,
TAG_DONE);

if(n==1)
result=W3D_SetTextureBlendTags(S->context,
W3D_BLEND_STAGE, 1,
W3D_ENV_MODE, state->TexEnvMode,
TAG_DONE);

if(n>1)
result=W3D_SetTextureBlendTags(S->context,
W3D_BLEND_STAGE,n,
W3D_COLOR_COMBINE,W3D_COMBINE_DISABLED,
W3D_ALPHA_COMBINE,W3D_COMBINE_DISABLED,
TAG_DONE);

if(result!=W3D_SUCCESS)
{printf("Cant SetTextureBlend%ld (error %ld)\n",n,result);}
}

result=W3D_SetTextureBlend(S->context,NULL);
if(result!= W3D_SUCCESS)
{printf("Cant SetTextureBlend (error %ld)\n",result);}


Cet article provient de Le site des utilisateurs francophones actuels et futurs d'AmigaOS 4.x
https://amiga-ng.org/viewtopic.php?topic=1414&forum=14