Skip to content

Commit

Permalink
Disintegration effect
Browse files Browse the repository at this point in the history
  • Loading branch information
SomaZ committed Nov 8, 2019
1 parent f212f36 commit a2e0b54
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 25 deletions.
57 changes: 54 additions & 3 deletions codemp/rd-rend2/glsl/generic.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ uniform vec3 u_ModelLightDir;
uniform float u_PortalRange;
#endif

#if defined(USE_RGBAGEN) || defined(USE_DEFORM_VERTEXES)
uniform vec4 u_Disintegration; // origin, threshhold
#endif

#if defined(USE_VERTEX_ANIMATION)
uniform float u_VertexLerp;
#elif defined(USE_SKELETAL_ANIMATION)
Expand Down Expand Up @@ -173,6 +177,21 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)

return pos - lightPos * dot( pos, ground ) + groundDist;
}

case DEFORM_DISINTEGRATION:
{
vec3 delta = u_Disintegration.xyz - pos;
float distance = dot(delta, delta);
if ( distance < u_Disintegration.w )
{
return normal * vec3(2.0, 2.0, 0.5) + pos;
}
else if ( distance < u_Disintegration.w + 50 )
{
return normal * vec3(1.0, 1.0, 0.0) + pos;
}
return pos - normal * 0.01;
}
}
}

Expand Down Expand Up @@ -264,7 +283,39 @@ vec4 CalcColor(vec3 position, vec3 normal)

color.rgb = clamp(u_DirectedLight * incoming + u_AmbientLight, 0.0, 1.0);
}

else if (u_ColorGen == CGEN_DISINTEGRATION_1)
{
vec3 delta = u_Disintegration.xyz - position;
float distance = dot(delta, delta);
if (distance < u_Disintegration.w)
{
color *= 0.0;
}
else if (distance < u_Disintegration.w + 60.0)
{
color *= vec4(0.0, 0.0, 0.0, 1.0);
}
else if (distance < u_Disintegration.w + 150.0)
{
color *= vec4(0.435295, 0.435295, 0.435295, 1.0);
}
else if (distance < u_Disintegration.w + 180.0)
{
color *= vec4(0.6862745, 0.6862745, 0.6862745, 1.0);
}
return color;
}
else if (u_ColorGen == CGEN_DISINTEGRATION_2)
{
vec3 delta = u_Disintegration.xyz - position;
float distance = dot(delta, delta);
if (distance < u_Disintegration.w)
{
color *= 0.0;
}
return color;
}

vec3 viewer = u_LocalViewOrigin - position;

if (u_AlphaGen == AGEN_LIGHTING_SPECULAR)
Expand Down Expand Up @@ -422,7 +473,7 @@ float CalcFog(in vec3 viewOrigin, in vec3 position, in vec4 fogPlane, in float d
void main()
{
vec4 color = texture(u_DiffuseMap, var_DiffuseTex);

color.a *= var_Color.a;
#if defined(USE_ALPHA_TEST)
if (u_AlphaTestType == ALPHA_TEST_GT0)
{
Expand Down Expand Up @@ -451,7 +502,7 @@ void main()
color *= vec4(1.0) - u_FogColorMask * fog;
#endif

out_Color = color * var_Color;
out_Color = vec4(color.rgb * var_Color.rgb, color.a);

#if defined(USE_GLOW_BUFFER)
out_Glow = out_Color;
Expand Down
47 changes: 45 additions & 2 deletions codemp/rd-rend2/glsl/lightall.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ uniform vec4 u_DiffuseTexOffTurb;
uniform mat4 u_ModelViewProjectionMatrix;
uniform vec4 u_BaseColor;
uniform vec4 u_VertColor;
uniform vec4 u_Disintegration;
uniform mat4 u_ModelMatrix;
uniform int u_ColorGen;

#if defined(USE_VERTEX_ANIMATION)
uniform float u_VertexLerp;
Expand Down Expand Up @@ -95,6 +97,44 @@ out vec4 var_LightDir;
out vec4 var_PrimaryLightDir;
#endif

vec4 CalcColor(vec3 position)
{
vec4 color = vec4(1.0);
if (u_ColorGen == CGEN_DISINTEGRATION_1)
{
vec3 delta = u_Disintegration.xyz - position;
float distance = dot(delta, delta);
if (distance < u_Disintegration.w)
{
color = vec4(0.0);
}
else if (distance < u_Disintegration.w + 60.0)
{
color = vec4(0.0, 0.0, 0.0, 1.0);
}
else if (distance < u_Disintegration.w + 150.0)
{
color = vec4(0.435295, 0.435295, 0.435295, 1.0);
}
else if (distance < u_Disintegration.w + 180.0)
{
color = vec4(0.6862745, 0.6862745, 0.6862745, 1.0);
}
return color;
}
else if (u_ColorGen == CGEN_DISINTEGRATION_2)
{
vec3 delta = u_Disintegration.xyz - position;
float distance = dot(delta, delta);
if (distance < u_Disintegration.w)
{
color = vec4(0.0);
}
return color;
}
return color;
}

#if defined(USE_TCGEN) || defined(USE_LIGHTMAP)
vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3 TCGenVector1)
{
Expand Down Expand Up @@ -164,7 +204,6 @@ float CalcLightAttenuation(in bool isPoint, float normDist)
return clamp(attenuation, 0.0, 1.0);
}


void main()
{
#if defined(USE_VERTEX_ANIMATION)
Expand Down Expand Up @@ -231,6 +270,8 @@ void main()
var_TexCoords.xy = texCoords;
#endif

vec4 disintegration = CalcColor(position);

gl_Position = u_ModelViewProjectionMatrix * vec4(position, 1.0);

position = (u_ModelMatrix * vec4(position, 1.0)).xyz;
Expand Down Expand Up @@ -276,6 +317,7 @@ void main()
var_Color.rgb *= u_DirectedLight * (attenuation * NL) + u_AmbientLight;
#endif
}
var_Color *= disintegration;

#if defined(USE_PRIMARY_LIGHT) || defined(USE_SHADOWMAP)
var_PrimaryLightDir.xyz = u_PrimaryLightOrigin.xyz - (position * u_PrimaryLightOrigin.w);
Expand Down Expand Up @@ -638,6 +680,7 @@ void main()
#endif

vec4 diffuse = texture(u_DiffuseMap, texCoords);
diffuse.a *= var_Color.a;
#if defined(USE_ALPHA_TEST)
if (u_AlphaTestType == ALPHA_TEST_GT0)
{
Expand Down Expand Up @@ -781,7 +824,7 @@ void main()
out_Color.rgb = diffuse.rgb * lightColor;
#endif

out_Color.a = diffuse.a * var_Color.a;
out_Color.a = diffuse.a;

#if defined(USE_GLOW_BUFFER)
out_Glow = out_Color;
Expand Down
33 changes: 23 additions & 10 deletions codemp/rd-rend2/tr_glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ static uniformInfo_t uniformsInfo[] =
{ "u_BaseColor", GLSL_VEC4, 1 },
{ "u_VertColor", GLSL_VEC4, 1 },

{ "u_DlightInfo", GLSL_VEC4, 1 },
{ "u_LightForward", GLSL_VEC3, 1 },
{ "u_LightUp", GLSL_VEC3, 1 },
{ "u_LightRight", GLSL_VEC3, 1 },
{ "u_LightOrigin", GLSL_VEC4, 1 },
{ "u_ModelLightDir", GLSL_VEC3, 1 },
{ "u_LightRadius", GLSL_FLOAT, 1 },
{ "u_AmbientLight", GLSL_VEC3, 1 },
{ "u_DirectedLight", GLSL_VEC3, 1 },
{ "u_DlightInfo", GLSL_VEC4, 1 },
{ "u_LightForward", GLSL_VEC3, 1 },
{ "u_LightUp", GLSL_VEC3, 1 },
{ "u_LightRight", GLSL_VEC3, 1 },
{ "u_LightOrigin", GLSL_VEC4, 1 },
{ "u_ModelLightDir", GLSL_VEC3, 1 },
{ "u_LightRadius", GLSL_FLOAT, 1 },
{ "u_AmbientLight", GLSL_VEC3, 1 },
{ "u_DirectedLight", GLSL_VEC3, 1 },
{ "u_Disintegration", GLSL_VEC4, 1 },

{ "u_PortalRange", GLSL_FLOAT, 1 },

Expand Down Expand Up @@ -273,6 +274,7 @@ static size_t GLSL_GetShaderHeader(
"#define DEFORM_BULGE_UNIFORM %i\n"
"#define DEFORM_MOVE %i\n"
"#define DEFORM_PROJECTION_SHADOW %i\n"
"#define DEFORM_DISINTEGRATION %i\n"
"#define WF_NONE %i\n"
"#define WF_SIN %i\n"
"#define WF_SQUARE %i\n"
Expand All @@ -287,6 +289,7 @@ static size_t GLSL_GetShaderHeader(
DEFORM_BULGE_UNIFORM,
DEFORM_MOVE,
DEFORM_PROJECTION_SHADOW,
DEFORM_DISINTEGRATION,
GF_NONE,
GF_SIN,
GF_SQUARE,
Expand Down Expand Up @@ -319,8 +322,12 @@ static size_t GLSL_GetShaderHeader(
va("#ifndef colorGen_t\n"
"#define colorGen_t\n"
"#define CGEN_LIGHTING_DIFFUSE %i\n"
"#define CGEN_DISINTEGRATION_1 %i\n"
"#define CGEN_DISINTEGRATION_2 %i\n"
"#endif\n",
CGEN_LIGHTING_DIFFUSE));
CGEN_LIGHTING_DIFFUSE,
CGEN_DISINTEGRATION_1,
CGEN_DISINTEGRATION_2));

Q_strcat(dest, size,
va("#ifndef alphaGen_t\n"
Expand Down Expand Up @@ -2401,6 +2408,12 @@ shaderProgram_t *GLSL_GetGenericShaderProgram(int stage)
if ( pStage->alphaTestType != ALPHA_TEST_NONE )
shaderAttribs |= GENERICDEF_USE_ALPHA_TEST;

if (backEnd.currentEntity->e.renderfx & (RF_DISINTEGRATE1 | RF_DISINTEGRATE2))
shaderAttribs |= GENERICDEF_USE_RGBAGEN;

if (backEnd.currentEntity->e.renderfx & RF_DISINTEGRATE2)
shaderAttribs |= GENERICDEF_USE_DEFORM_VERTEXES;

switch (pStage->rgbGen)
{
case CGEN_LIGHTING_DIFFUSE:
Expand Down
6 changes: 5 additions & 1 deletion codemp/rd-rend2/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ typedef enum {
DEFORM_TEXT4,
DEFORM_TEXT5,
DEFORM_TEXT6,
DEFORM_TEXT7
DEFORM_TEXT7,
DEFORM_DISINTEGRATION
} deform_t;

// deformVertexes types that can be handled by the GPU
Expand Down Expand Up @@ -571,6 +572,8 @@ typedef enum {
CGEN_FOG, // standard fog
CGEN_CONST, // fixed color
CGEN_LIGHTMAPSTYLE, // lightmap style
CGEN_DISINTEGRATION_1,
CGEN_DISINTEGRATION_2
} colorGen_t;

typedef enum {
Expand Down Expand Up @@ -1225,6 +1228,7 @@ typedef enum
UNIFORM_LIGHTRADIUS,
UNIFORM_AMBIENTLIGHT,
UNIFORM_DIRECTEDLIGHT,
UNIFORM_DISINTEGRATION,

UNIFORM_PORTALRANGE,

Expand Down
Loading

0 comments on commit a2e0b54

Please sign in to comment.