Bump mapping support

This commit is contained in:
Flyinghead 2018-07-02 15:23:47 +02:00
parent 99af84d7fb
commit 69263eddc0
4 changed files with 52 additions and 37 deletions

View File

@ -185,10 +185,10 @@ pixelcvt_next(convYUV_PL,4,1)
pixelcvt_next(convBMP_PL,4,1) pixelcvt_next(convBMP_PL,4,1)
{ {
u16* p_in=(u16*)data; u16* p_in=(u16*)data;
pb->prel(0,ARGB8888(p_in[0])); pb->prel(0,ARGB4444(p_in[0]));
pb->prel(1,ARGB8888(p_in[1])); pb->prel(1,ARGB4444(p_in[1]));
pb->prel(2,ARGB8888(p_in[2])); pb->prel(2,ARGB4444(p_in[2]));
pb->prel(3,ARGB8888(p_in[3])); pb->prel(3,ARGB4444(p_in[3]));
} }
pixelcvt_end; pixelcvt_end;
//twiddled //twiddled
@ -263,10 +263,10 @@ pixelcvt_next(convYUV_TW,2,2)
pixelcvt_next(convBMP_TW,2,2) pixelcvt_next(convBMP_TW,2,2)
{ {
u16* p_in=(u16*)data; u16* p_in=(u16*)data;
pb->prel(0,0,ARGB8888(p_in[0])); pb->prel(0,0,ARGB4444(p_in[0]));
pb->prel(0,1,ARGB8888(p_in[1])); pb->prel(0,1,ARGB4444(p_in[1]));
pb->prel(1,0,ARGB8888(p_in[2])); pb->prel(1,0,ARGB4444(p_in[2]));
pb->prel(1,1,ARGB8888(p_in[3])); pb->prel(1,1,ARGB4444(p_in[3]));
} }
pixelcvt_end; pixelcvt_end;

View File

@ -158,7 +158,8 @@ __forceinline
gp->tsp.ShadInstr, gp->tsp.ShadInstr,
gp->pcw.Offset, gp->pcw.Offset,
gp->tsp.FogCtrl, gp->tsp.FogCtrl,
gp->pcw.Gouraud)]; gp->pcw.Gouraud,
gp->tcw.PixelFmt == 4)];
if (CurrentShader->program == -1) if (CurrentShader->program == -1)
CompilePipelineShader(CurrentShader); CompilePipelineShader(CurrentShader);

View File

@ -201,6 +201,8 @@ const char* PixelPipelineShader =
#define pp_Offset %d \n\ #define pp_Offset %d \n\
#define pp_FogCtrl %d \n\ #define pp_FogCtrl %d \n\
#define pp_Gouraud %d \n\ #define pp_Gouraud %d \n\
#define pp_BumpMap %d \n\
#define PI 3.1415926 \n\
\n" \n"
#ifndef GLES #ifndef GLES
"\ "\
@ -258,8 +260,14 @@ void main() \n\
#endif\n\ #endif\n\
#if pp_Texture==1 \n\ #if pp_Texture==1 \n\
{ \n\ { \n\
lowp vec4 texcol=" TEXLOOKUP "(tex,vtx_uv); \n\ lowp vec4 texcol=" TEXLOOKUP "(tex, vtx_uv); \n\
\n\ \n\
#if pp_BumpMap == 1 \n\
float s = PI / 2.0 * (texcol.a * 15.0 * 16.0 + texcol.r * 15.0) / 255.0; \n\
float r = 2.0 * PI * (texcol.g * 15.0 * 16.0 + texcol.b * 15.0) / 255.0; \n\
texcol.a = clamp(vtx_offs.a + vtx_offs.r * sin(s) + vtx_offs.g * cos(s) * cos(r - 2.0 * PI * vtx_offs.b), 0.0, 1.0); \n\
texcol.rgb = vec3(1.0, 1.0, 1.0); \n\
#else\n\
#if pp_IgnoreTexA==1 \n\ #if pp_IgnoreTexA==1 \n\
texcol.a=1.0; \n\ texcol.a=1.0; \n\
#endif\n\ #endif\n\
@ -267,6 +275,7 @@ void main() \n\
#if cp_AlphaTest == 1 \n\ #if cp_AlphaTest == 1 \n\
if (cp_AlphaTestValue>texcol.a) discard;\n\ if (cp_AlphaTestValue>texcol.a) discard;\n\
#endif \n\ #endif \n\
#endif \n\
#if pp_ShadInstr==0 \n\ #if pp_ShadInstr==0 \n\
{ \n\ { \n\
color=texcol; \n\ color=texcol; \n\
@ -289,7 +298,7 @@ void main() \n\
} \n\ } \n\
#endif\n\ #endif\n\
\n\ \n\
#if pp_Offset==1 \n\ #if pp_Offset==1 && pp_BumpMap == 0 \n\
{ \n\ { \n\
color.rgb+=vtx_offs.rgb; \n\ color.rgb+=vtx_offs.rgb; \n\
if (pp_FogCtrl==1) \n\ if (pp_FogCtrl==1) \n\
@ -777,7 +786,7 @@ GLuint gl_CompileAndLink(const char* VertexShader, const char* FragmentShader)
int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode, int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode,
u32 pp_Texture, u32 pp_UseAlpha, u32 pp_IgnoreTexA, u32 pp_ShadInstr, u32 pp_Offset, u32 pp_Texture, u32 pp_UseAlpha, u32 pp_IgnoreTexA, u32 pp_ShadInstr, u32 pp_Offset,
u32 pp_FogCtrl, bool pp_Gouraud) u32 pp_FogCtrl, bool pp_Gouraud, bool pp_BumpMap)
{ {
u32 rv=0; u32 rv=0;
@ -790,6 +799,7 @@ int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode,
rv<<=1; rv|=pp_Offset; rv<<=1; rv|=pp_Offset;
rv<<=2; rv|=pp_FogCtrl; rv<<=2; rv|=pp_FogCtrl;
rv<<=1; rv|=pp_Gouraud; rv<<=1; rv|=pp_Gouraud;
rv<<=1; rv|=pp_BumpMap;
return rv; return rv;
} }
@ -804,7 +814,7 @@ bool CompilePipelineShader( PipelineShader* s)
sprintf(pshader,PixelPipelineShader, sprintf(pshader,PixelPipelineShader,
s->cp_AlphaTest,s->pp_ClipTestMode,s->pp_UseAlpha, s->cp_AlphaTest,s->pp_ClipTestMode,s->pp_UseAlpha,
s->pp_Texture,s->pp_IgnoreTexA,s->pp_ShadInstr,s->pp_Offset,s->pp_FogCtrl, s->pp_Gouraud); s->pp_Texture,s->pp_IgnoreTexA,s->pp_ShadInstr,s->pp_Offset,s->pp_FogCtrl, s->pp_Gouraud, s->pp_BumpMap);
s->program=gl_CompileAndLink(vshader, pshader); s->program=gl_CompileAndLink(vshader, pshader);
@ -889,9 +899,11 @@ bool gl_create_resources()
forl(pp_Offset,1) forl(pp_Offset,1)
{ {
forl(pp_Gouraud,1) forl(pp_Gouraud,1)
{
forl(pp_BumpMap,1)
{ {
dshader=&gl.pogram_table[GetProgramID(cp_AlphaTest,pp_ClipTestMode,pp_Texture,pp_UseAlpha,pp_IgnoreTexA, dshader=&gl.pogram_table[GetProgramID(cp_AlphaTest,pp_ClipTestMode,pp_Texture,pp_UseAlpha,pp_IgnoreTexA,
pp_ShadInstr,pp_Offset,pp_FogCtrl,(bool)pp_Gouraud)]; pp_ShadInstr,pp_Offset,pp_FogCtrl, (bool)pp_Gouraud, (bool)pp_BumpMap)];
dshader->cp_AlphaTest = cp_AlphaTest; dshader->cp_AlphaTest = cp_AlphaTest;
dshader->pp_ClipTestMode = pp_ClipTestMode-1; dshader->pp_ClipTestMode = pp_ClipTestMode-1;
@ -902,6 +914,7 @@ bool gl_create_resources()
dshader->pp_Offset = pp_Offset; dshader->pp_Offset = pp_Offset;
dshader->pp_FogCtrl = pp_FogCtrl; dshader->pp_FogCtrl = pp_FogCtrl;
dshader->pp_Gouraud = pp_Gouraud; dshader->pp_Gouraud = pp_Gouraud;
dshader->pp_BumpMap = pp_BumpMap;
dshader->program = -1; dshader->program = -1;
} }
} }
@ -912,6 +925,7 @@ bool gl_create_resources()
} }
} }
} }
}
char vshader[8192]; char vshader[8192];
sprintf(vshader, VertexShaderSource, 1); sprintf(vshader, VertexShaderSource, 1);

View File

@ -59,7 +59,7 @@ struct PipelineShader
// //
u32 cp_AlphaTest; s32 pp_ClipTestMode; u32 cp_AlphaTest; s32 pp_ClipTestMode;
u32 pp_Texture, pp_UseAlpha, pp_IgnoreTexA, pp_ShadInstr, pp_Offset, pp_FogCtrl; u32 pp_Texture, pp_UseAlpha, pp_IgnoreTexA, pp_ShadInstr, pp_Offset, pp_FogCtrl;
bool pp_Gouraud; bool pp_Gouraud, pp_BumpMap;
}; };
@ -85,7 +85,7 @@ struct gl_ctx
} modvol_shader; } modvol_shader;
PipelineShader pogram_table[3072]; PipelineShader pogram_table[6144];
struct struct
{ {
GLuint program,scale,depth_scale; GLuint program,scale,depth_scale;
@ -122,7 +122,7 @@ void BindRTT(u32 addy, u32 fbw, u32 fbh, u32 channels, u32 fmt);
void ReadRTTBuffer(); void ReadRTTBuffer();
int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode, int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode,
u32 pp_Texture, u32 pp_UseAlpha, u32 pp_IgnoreTexA, u32 pp_ShadInstr, u32 pp_Offset, u32 pp_Texture, u32 pp_UseAlpha, u32 pp_IgnoreTexA, u32 pp_ShadInstr, u32 pp_Offset,
u32 pp_FogCtrl, bool pp_Gouraud); u32 pp_FogCtrl, bool pp_Gouraud, bool pp_BumpMap);
bool CompilePipelineShader(PipelineShader* s); bool CompilePipelineShader(PipelineShader* s);
#define TEXTURE_LOAD_ERROR 0 #define TEXTURE_LOAD_ERROR 0