Skip to content

Commit

Permalink
Bump mapping support
Browse files Browse the repository at this point in the history
  • Loading branch information
flyinghead committed Jul 2, 2018
1 parent 99af84d commit 69263ed
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 38 deletions.
18 changes: 9 additions & 9 deletions core/rend/TexCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ pixelcvt_next(convYUV_PL,4,1)
pixelcvt_next(convBMP_PL,4,1)
{
u16* p_in=(u16*)data;
pb->prel(0,ARGB8888(p_in[0]));
pb->prel(1,ARGB8888(p_in[1]));
pb->prel(2,ARGB8888(p_in[2]));
pb->prel(3,ARGB8888(p_in[3]));
pb->prel(0,ARGB4444(p_in[0]));
pb->prel(1,ARGB4444(p_in[1]));
pb->prel(2,ARGB4444(p_in[2]));
pb->prel(3,ARGB4444(p_in[3]));
}
pixelcvt_end;
//twiddled
Expand Down Expand Up @@ -263,10 +263,10 @@ pixelcvt_next(convYUV_TW,2,2)
pixelcvt_next(convBMP_TW,2,2)
{
u16* p_in=(u16*)data;
pb->prel(0,0,ARGB8888(p_in[0]));
pb->prel(0,1,ARGB8888(p_in[1]));
pb->prel(1,0,ARGB8888(p_in[2]));
pb->prel(1,1,ARGB8888(p_in[3]));
pb->prel(0,0,ARGB4444(p_in[0]));
pb->prel(0,1,ARGB4444(p_in[1]));
pb->prel(1,0,ARGB4444(p_in[2]));
pb->prel(1,1,ARGB4444(p_in[3]));
}
pixelcvt_end;

Expand Down Expand Up @@ -451,4 +451,4 @@ void vramlock_Unlock_block(vram_block* block);
vram_block* vramlock_Lock_32(u32 start_offset32,u32 end_offset32,void* userdata);
vram_block* vramlock_Lock_64(u32 start_offset64,u32 end_offset64,void* userdata);

void vram_LockedWrite(u32 offset64);
void vram_LockedWrite(u32 offset64);
3 changes: 2 additions & 1 deletion core/rend/gles/gldraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ __forceinline
gp->tsp.ShadInstr,
gp->pcw.Offset,
gp->tsp.FogCtrl,
gp->pcw.Gouraud)];
gp->pcw.Gouraud,
gp->tcw.PixelFmt == 4)];

if (CurrentShader->program == -1)
CompilePipelineShader(CurrentShader);
Expand Down
64 changes: 39 additions & 25 deletions core/rend/gles/gles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ const char* PixelPipelineShader =
#define pp_Offset %d \n\
#define pp_FogCtrl %d \n\
#define pp_Gouraud %d \n\
#define pp_BumpMap %d \n\
#define PI 3.1415926 \n\
\n"
#ifndef GLES
"\
Expand Down Expand Up @@ -258,15 +260,22 @@ void main() \n\
#endif\n\
#if pp_Texture==1 \n\
{ \n\
lowp vec4 texcol=" TEXLOOKUP "(tex,vtx_uv); \n\
\n\
#if pp_IgnoreTexA==1 \n\
texcol.a=1.0; \n\
#endif\n\
\n\
#if cp_AlphaTest == 1 \n\
if (cp_AlphaTestValue>texcol.a) discard;\n\
#endif \n\
lowp vec4 texcol=" TEXLOOKUP "(tex, vtx_uv); \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\
texcol.a=1.0; \n\
#endif\n\
\n\
#if cp_AlphaTest == 1 \n\
if (cp_AlphaTestValue>texcol.a) discard;\n\
#endif \n\
#endif \n\
#if pp_ShadInstr==0 \n\
{ \n\
color=texcol; \n\
Expand All @@ -289,7 +298,7 @@ void main() \n\
} \n\
#endif\n\
\n\
#if pp_Offset==1 \n\
#if pp_Offset==1 && pp_BumpMap == 0 \n\
{ \n\
color.rgb+=vtx_offs.rgb; \n\
if (pp_FogCtrl==1) \n\
Expand Down Expand Up @@ -777,7 +786,7 @@ GLuint gl_CompileAndLink(const char* VertexShader, const char* FragmentShader)

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_FogCtrl, bool pp_Gouraud)
u32 pp_FogCtrl, bool pp_Gouraud, bool pp_BumpMap)
{
u32 rv=0;

Expand All @@ -790,6 +799,7 @@ int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode,
rv<<=1; rv|=pp_Offset;
rv<<=2; rv|=pp_FogCtrl;
rv<<=1; rv|=pp_Gouraud;
rv<<=1; rv|=pp_BumpMap;

return rv;
}
Expand All @@ -804,7 +814,7 @@ bool CompilePipelineShader( PipelineShader* s)

sprintf(pshader,PixelPipelineShader,
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);

Expand Down Expand Up @@ -890,19 +900,23 @@ bool gl_create_resources()
{
forl(pp_Gouraud,1)
{
dshader=&gl.pogram_table[GetProgramID(cp_AlphaTest,pp_ClipTestMode,pp_Texture,pp_UseAlpha,pp_IgnoreTexA,
pp_ShadInstr,pp_Offset,pp_FogCtrl,(bool)pp_Gouraud)];

dshader->cp_AlphaTest = cp_AlphaTest;
dshader->pp_ClipTestMode = pp_ClipTestMode-1;
dshader->pp_Texture = pp_Texture;
dshader->pp_UseAlpha = pp_UseAlpha;
dshader->pp_IgnoreTexA = pp_IgnoreTexA;
dshader->pp_ShadInstr = pp_ShadInstr;
dshader->pp_Offset = pp_Offset;
dshader->pp_FogCtrl = pp_FogCtrl;
dshader->pp_Gouraud = pp_Gouraud;
dshader->program = -1;
forl(pp_BumpMap,1)
{
dshader=&gl.pogram_table[GetProgramID(cp_AlphaTest,pp_ClipTestMode,pp_Texture,pp_UseAlpha,pp_IgnoreTexA,
pp_ShadInstr,pp_Offset,pp_FogCtrl, (bool)pp_Gouraud, (bool)pp_BumpMap)];

dshader->cp_AlphaTest = cp_AlphaTest;
dshader->pp_ClipTestMode = pp_ClipTestMode-1;
dshader->pp_Texture = pp_Texture;
dshader->pp_UseAlpha = pp_UseAlpha;
dshader->pp_IgnoreTexA = pp_IgnoreTexA;
dshader->pp_ShadInstr = pp_ShadInstr;
dshader->pp_Offset = pp_Offset;
dshader->pp_FogCtrl = pp_FogCtrl;
dshader->pp_Gouraud = pp_Gouraud;
dshader->pp_BumpMap = pp_BumpMap;
dshader->program = -1;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/rend/gles/gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct PipelineShader
//
u32 cp_AlphaTest; s32 pp_ClipTestMode;
u32 pp_Texture, pp_UseAlpha, pp_IgnoreTexA, pp_ShadInstr, pp_Offset, pp_FogCtrl;
bool pp_Gouraud;
bool pp_Gouraud, pp_BumpMap;
};


Expand All @@ -85,7 +85,7 @@ struct gl_ctx

} modvol_shader;

PipelineShader pogram_table[3072];
PipelineShader pogram_table[6144];
struct
{
GLuint program,scale,depth_scale;
Expand Down Expand Up @@ -122,7 +122,7 @@ void BindRTT(u32 addy, u32 fbw, u32 fbh, u32 channels, u32 fmt);
void ReadRTTBuffer();
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_FogCtrl, bool pp_Gouraud);
u32 pp_FogCtrl, bool pp_Gouraud, bool pp_BumpMap);

bool CompilePipelineShader(PipelineShader* s);
#define TEXTURE_LOAD_ERROR 0
Expand Down

0 comments on commit 69263ed

Please sign in to comment.