Skip to content

Commit

Permalink
Custom deform for human buildings.
Browse files Browse the repository at this point in the history
  • Loading branch information
gimhael committed Mar 31, 2015
1 parent e570876 commit 6568fab
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 3 deletions.
11 changes: 11 additions & 0 deletions main/glsl/deformVertexes_vp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ void DeformVertex( inout vec4 pos,
work.xyz = pos.xyz * parms.xyz;
} else if( cmd == DSTEP_LOAD_NORM ) {
work.xyz = normal.xyz * parms.xyz;
} else if( cmd == DSTEP_LOAD_COLOR ) {
work.xyz = color.xyz * parms.xyz;
} else if( cmd == DSTEP_LOAD_TC ) {
work.xyz = vec3(st, 1.0) * parms.xyz;
} else if( cmd == DSTEP_LOAD_VEC ) {
Expand All @@ -103,6 +105,8 @@ void DeformVertex( inout vec4 pos,
} else if( cmd == DSTEP_MODIFY_NORM ) {
normal.xyz += (parms.x + parms.y * work.a) * work.xyz;
normal = normalize(normal);
} else if( cmd == DSTEP_MODIFY_COLOR ) {
color.xyz += (parms.x + parms.y * work.a) * work.xyz;
} else if( cmd == DSTEP_SIN ) {
work.a = sin( 2.0 * M_PI * (parms.x + parms.y * (work.x + work.y + work.z) + parms.z * time) );
} else if( cmd == DSTEP_SQUARE ) {
Expand All @@ -116,6 +120,13 @@ void DeformVertex( inout vec4 pos,
} else if( cmd == DSTEP_NOISE ) {
//work = pnoise(vec4(parms.y * work.xyz, parms.z * time));
work = noise4(vec4(parms.y * work.xyz, parms.z * time));
} else if( cmd == DSTEP_ROTGROW ) {
if(work.z > parms.x * time)
work.a = 0.0;
else {
work.a = parms.y * atan(pos.y, pos.x) + parms.z * time;
work.a = 0.5 * sin(work.a) + 0.5;
}
} else
break;
}
Expand Down
18 changes: 18 additions & 0 deletions main/scripts/buildables.shader
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,21 @@ models/buildables/trapper
glowMap models/buildables/trapper/trapper_g
}

models/buildables/humanSpawning
{
deformVertexes rotgrow 5.0 3.0 2.0
cull disable
{
map models/buildables/telenode/rep_cyl
blendfunc add
rgbGen lightingDiffuse
tcMod scroll 0.2 0
}
{
map models/buildables/telenode/lines2
blendfunc add
rgbGen identity
tcMod scroll 0 0.2
}
}

3 changes: 3 additions & 0 deletions src/engine/renderer/gl_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,19 @@ std::string GLShaderManager::BuildGPUShaderText( const char *mainShaderName,
AddGLSLDefine( bufferExtra, "DSTEP_NONE", DSTEP_NONE);
AddGLSLDefine( bufferExtra, "DSTEP_LOAD_POS", DSTEP_LOAD_POS);
AddGLSLDefine( bufferExtra, "DSTEP_LOAD_NORM", DSTEP_LOAD_NORM);
AddGLSLDefine( bufferExtra, "DSTEP_LOAD_COLOR", DSTEP_LOAD_COLOR);
AddGLSLDefine( bufferExtra, "DSTEP_LOAD_TC", DSTEP_LOAD_TC);
AddGLSLDefine( bufferExtra, "DSTEP_LOAD_VEC", DSTEP_LOAD_VEC);
AddGLSLDefine( bufferExtra, "DSTEP_MODIFY_POS", DSTEP_MODIFY_POS);
AddGLSLDefine( bufferExtra, "DSTEP_MODIFY_NORM", DSTEP_MODIFY_NORM);
AddGLSLDefine( bufferExtra, "DSTEP_MODIFY_COLOR", DSTEP_MODIFY_COLOR);
AddGLSLDefine( bufferExtra, "DSTEP_SIN", DSTEP_SIN);
AddGLSLDefine( bufferExtra, "DSTEP_SQUARE", DSTEP_SQUARE);
AddGLSLDefine( bufferExtra, "DSTEP_TRIANGLE", DSTEP_TRIANGLE);
AddGLSLDefine( bufferExtra, "DSTEP_SAWTOOTH", DSTEP_SAWTOOTH);
AddGLSLDefine( bufferExtra, "DSTEP_INVERSE_SAWTOOTH", DSTEP_INVERSE_SAWTOOTH);
AddGLSLDefine( bufferExtra, "DSTEP_NOISE", DSTEP_NOISE);
AddGLSLDefine( bufferExtra, "DSTEP_ROTGROW", DSTEP_ROTGROW);

float fbufWidthScale = Q_recip( ( float ) glConfig.vidWidth );
float fbufHeightScale = Q_recip( ( float ) glConfig.vidHeight );
Expand Down
26 changes: 26 additions & 0 deletions src/engine/renderer/gl_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,32 @@ class u_DeformParms :
deformOfs++;
break;

case DEFORM_ROTGROW:
deformParms[ deformOfs ][ 0 ] = 1.0f;
deformParms[ deformOfs ][ 1 ] = 1.0f;
deformParms[ deformOfs ][ 2 ] = 1.0f;
deformParms[ deformOfs ][ 3 ] = DSTEP_LOAD_POS;
deformOfs++;

deformParms[ deformOfs ][ 0 ] = ds->moveVector[0];
deformParms[ deformOfs ][ 1 ] = ds->moveVector[1];
deformParms[ deformOfs ][ 2 ] = ds->moveVector[2];
deformParms[ deformOfs ][ 3 ] = DSTEP_ROTGROW;
deformOfs++;

deformParms[ deformOfs ][ 0 ] = 1.0f;
deformParms[ deformOfs ][ 1 ] = 1.0f;
deformParms[ deformOfs ][ 2 ] = 1.0f;
deformParms[ deformOfs ][ 3 ] = DSTEP_LOAD_COLOR;
deformOfs++;

deformParms[ deformOfs ][ 0 ] = -1.0f;
deformParms[ deformOfs ][ 1 ] = 1.0f;
deformParms[ deformOfs ][ 2 ] = 0.0f;
deformParms[ deformOfs ][ 3 ] = DSTEP_MODIFY_COLOR;
deformOfs++;
break;

default:
break;
}
Expand Down
8 changes: 6 additions & 2 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,8 @@ static inline void halfToFloat( const f16vec4_t in, vec4_t out )
DEFORM_WAVE,
DEFORM_NORMALS,
DEFORM_BULGE,
DEFORM_MOVE
DEFORM_MOVE,
DEFORM_ROTGROW
} deform_t;

typedef enum
Expand All @@ -803,15 +804,18 @@ static inline void halfToFloat( const f16vec4_t in, vec4_t out )
DSTEP_LOAD_POS,
DSTEP_LOAD_NORM,
DSTEP_LOAD_TC,
DSTEP_LOAD_COLOR,
DSTEP_LOAD_VEC,
DSTEP_MODIFY_POS,
DSTEP_MODIFY_NORM,
DSTEP_MODIFY_COLOR,
DSTEP_SIN,
DSTEP_SQUARE,
DSTEP_TRIANGLE,
DSTEP_SAWTOOTH,
DSTEP_INVERSE_SAWTOOTH,
DSTEP_NOISE
DSTEP_NOISE,
DSTEP_ROTGROW
} deformStep_t;

typedef enum
Expand Down
22 changes: 22 additions & 0 deletions src/engine/renderer/tr_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2876,6 +2876,7 @@ deformVertexes wave <spread> <waveform> <base> <amplitude> <phase> <frequency>
deformVertexes normal <frequency> <amplitude>
deformVertexes move <vector> <waveform> <base> <amplitude> <phase> <frequency>
deformVertexes bulge <bulgeWidth> <bulgeHeight> <bulgeSpeed>
deformVertexes rotgrow <growSpeed> <rotSlices> <rotSpeed>
deformVertexes autoSprite
deformVertexes autoSprite2
===============
Expand Down Expand Up @@ -3025,6 +3026,27 @@ static void ParseDeform( char **text )
return;
}

if ( !Q_stricmp( token, "rotgrow" ) )
{
int i;

for ( i = 0; i < 3; i++ )
{
token = COM_ParseExt2( text, qfalse );

if ( token[ 0 ] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing deformVertexes parm in shader '%s'\n", shader.name );
return;
}

ds->moveVector[ i ] = atof( token );
}

ds->deformation = DEFORM_ROTGROW;
return;
}

if ( !Q_stricmp( token, "sprite" ) )
{
shader.autoSpriteMode = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/gamelogic/cgame/cg_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ static void CG_RegisterGraphics( void )
(RegisterShaderFlags_t) RSF_DEFAULT);
cgs.media.redBuildShader = trap_R_RegisterShader("gfx/misc/redbuild",
(RegisterShaderFlags_t) RSF_DEFAULT);
cgs.media.humanSpawningShader = trap_R_RegisterShader("models/buildables/telenode/rep_cyl",
cgs.media.humanSpawningShader = trap_R_RegisterShader("models/buildables/humanSpawning",
(RegisterShaderFlags_t) RSF_DEFAULT);

for ( i = 0; i < 8; i++ )
Expand Down

0 comments on commit 6568fab

Please sign in to comment.