Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Commander shields #4107

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion data/base/audio/audio.json
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@
{ "fileName": "scream.ogg", "loop": false, "range": 1800, "volume": 100 },
{ "fileName": "scream2.ogg", "loop": false, "range": 1800, "volume": 100 },
{ "fileName": "scream3.ogg", "loop": false, "range": 1800, "volume": 100 },
{ "fileName": "silence.ogg", "loop": false, "range": 1800, "volume": 100 }
{ "fileName": "silence.ogg", "loop": false, "range": 1800, "volume": 100 },
{ "fileName": "shield-hit.ogg", "loop": false, "range": 1800, "volume": 70 }
]
},
"Extra": {
Expand Down
Binary file added data/base/audio/sfx/misc/shield-hit.ogg
Binary file not shown.
31 changes: 29 additions & 2 deletions data/base/shaders/tcmask_instanced.frag
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ uniform int tcmask; // whether a tcmask texture exists for the model
uniform int normalmap; // whether a normal map exists for the model
uniform int specularmap; // whether a specular map exists for the model
uniform int hasTangents; // whether tangents were calculated for model
uniform int shieldEffect;
uniform float graphicsCycle; // a periodically cycling value for special effects

uniform vec4 sceneColor; //emissive light
Expand Down Expand Up @@ -74,6 +75,11 @@ out vec4 FragColor;
#include "pointlights.frag"
#endif

float random(vec2 uv)
{
return fract(sin(dot(uv.xy, vec2(12.9898, 78.233))) * 43758.5453123);
}

float getShadowMapDepthComp(vec2 base_uv, float u, float v, vec2 shadowMapSizeInv, int cascadeIndex, float z)
{
vec2 uv = base_uv + vec2(u, v) * shadowMapSizeInv;
Expand Down Expand Up @@ -300,6 +306,13 @@ vec3 blendAddEffectLighting(vec3 a, vec3 b) {
return min(a + b, vec3(1.0));
}

vec4 applyShieldFuzzEffect(vec4 color) {
float cycle = 0.66 + 0.66 * graphicsCycle;
vec3 col = vec3(random(vec2(color.x * cycle, color.y * cycle)));
col.b *= 1.5;
return vec4(col, color.a / 6.0);
}

void main()
{
// unpack inputs
Expand Down Expand Up @@ -418,8 +431,22 @@ void main()
}

#ifdef NEWGL
FragColor = fragColour;
if (shieldEffect == 1)
{
FragColor = applyShieldFuzzEffect(fragColour);
}
else
{
FragColor = fragColour;
}
#else
gl_FragColor = fragColour;
if (shieldEffect == 1)
{
gl_FragColor = applyShieldFuzzEffect(fragColour);
}
else
{
gl_FragColor = fragColour;
}
#endif
}
21 changes: 20 additions & 1 deletion data/base/shaders/vk/tcmask_instanced.frag
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ layout(location = 0) out vec4 FragColor;

#include "pointlights.glsl"

float random(vec2 uv)
{
return fract(sin(dot(uv.xy, vec2(12.9898, 78.233))) * 43758.5453123);
}

float getShadowMapDepthComp(vec2 base_uv, float u, float v, vec2 shadowMapSizeInv, int cascadeIndex, float z)
{
vec2 uv = base_uv + vec2(u, v) * shadowMapSizeInv;
Expand Down Expand Up @@ -268,6 +273,13 @@ vec3 blendAddEffectLighting(vec3 a, vec3 b) {
return min(a + b, vec3(1.0));
}

vec4 applyShieldFuzzEffect(vec4 color) {
float cycle = 0.66 + 0.66 * graphicsCycle;
vec3 col = vec3(random(vec2(color.x * cycle, color.y * cycle)));
col.b *= 1.5;
return vec4(col, color.a / 6.0);
}

void main()
{
// unpack inputs
Expand Down Expand Up @@ -381,5 +393,12 @@ void main()
fragColour = mix(fragColour, vec4(fogColor.xyz, fragColour.w), fogFactor);
}

FragColor = fragColour;
if (shieldEffect == 1)
{
FragColor = applyShieldFuzzEffect(fragColour);
}
else
{
FragColor = fragColour;
}
}
1 change: 1 addition & 0 deletions data/base/shaders/vk/tcmask_instanced.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ layout(std140, set = 1, binding = 0) uniform meshuniforms
int normalmap;
int specularmap;
int hasTangents;
int shieldEffect;
};

1 change: 1 addition & 0 deletions data/base/wrf/audio.wrf
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ file WAV "scream.ogg"
file WAV "scream2.ogg"
file WAV "scream3.ogg"
file WAV "silence.ogg"
file WAV "shield-hit.ogg"
directory "audio/extra"
file WAV "lndgzne.ogg"
file WAV "nmedeted.ogg"
Expand Down
18 changes: 16 additions & 2 deletions data/mp/stats/brain.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,27 @@
"name": "Command Turret",
"ranks": [ "Rookie", "Green", "Trained", "Regular", "Professional", "Veteran", "Elite", "Special", "Hero" ],
"thresholds": [ 0, 12, 24, 36, 48, 60, 72, 84, 96 ],
"turret": "CommandTurret1"
"turret": "CommandTurret1",
"initialShieldPointsPercent": 10,
"additiveShieldPointsPercent": 5,
"initialShieldRegenTime": 32,
"shieldRegenTimeDec": 2,
"initialShieldInterruptRegenTime": 2000,
"shieldInterruptRegenTimeDec": 100,
"shieldPointsPerStep": 4
},
"ZNULLBRAIN": {
"id": "ZNULLBRAIN",
"name": "Z NULL BRAIN",
"ranks": [ "Rookie", "Green", "Trained", "Regular", "Professional", "Veteran", "Elite", "Special", "Hero" ],
"thresholds": [ 0, 2, 4, 6, 8, 10, 12, 14, 16 ],
"turret": "ZNULLWEAPON"
"turret": "ZNULLWEAPON",
"initialShieldPointsPercent": 10,
"additiveShieldPointsPercent": 5,
"initialShieldRegenTime": 32,
"shieldRegenTimeDec": 2,
"initialShieldInterruptRegenTime": 2000,
"shieldInterruptRegenTimeDec": 100,
"shieldPointsPerStep": 4
}
}
1 change: 1 addition & 0 deletions lib/ivis_opengl/gfx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ namespace gfx_api
int normalMap;
int specularMap;
int hasTangents;
int shieldEffect;
};

// interleaved vertex data
Expand Down
5 changes: 3 additions & 2 deletions lib/ivis_opengl/gfx_api_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ static const std::map<SHADER_MODE, program_data> shader_to_file_table =
// per-frame global uniforms
"ProjectionMatrix", "ViewMatrix", "ModelUVLightmapMatrix", "ShadowMapMVPMatrix", "lightPosition", "sceneColor", "ambient", "diffuse", "specular", "fogColor", "ShadowMapCascadeSplits", "ShadowMapSize", "fogEnd", "fogStart", "graphicsCycle", "fogEnabled", "PointLightsPosition", "PointLightsColorAndEnergy", "bucketOffsetAndSize", "PointLightsIndex", "bucketDimensionUsed", "viewportWidth", "viewportHeight",
// per-mesh uniforms
"tcmask", "normalmap", "specularmap", "hasTangents"
"tcmask", "normalmap", "specularmap", "hasTangents", "shieldEffect",
},
{
{"shadowMap", 4},
Expand All @@ -860,7 +860,7 @@ static const std::map<SHADER_MODE, program_data> shader_to_file_table =
// per-frame global uniforms
"ProjectionMatrix", "ViewMatrix", "ModelUVLightmapMatrix", "ShadowMapMVPMatrix", "lightPosition", "sceneColor", "ambient", "diffuse", "specular", "fogColor", "ShadowMapCascadeSplits", "ShadowMapSize", "fogEnd", "fogStart", "graphicsCycle", "fogEnabled", "PointLightsPosition", "PointLightsColorAndEnergy", "bucketOffsetAndSize", "PointLightsIndex", "bucketDimensionUsed", "viewportWidth", "viewportHeight",
// per-mesh uniforms
"tcmask", "normalmap", "specularmap", "hasTangents",
"tcmask", "normalmap", "specularmap", "hasTangents", "shieldEffect",
},
{
{"shadowMap", 4}
Expand Down Expand Up @@ -2123,6 +2123,7 @@ void gl_pipeline_state_object::set_constants(const gfx_api::Draw3DShapeInstanced
setUniforms(24, cbuf.normalMap);
setUniforms(25, cbuf.specularMap);
setUniforms(26, cbuf.hasTangents);
setUniforms(27, cbuf.shieldEffect);
}

void gl_pipeline_state_object::set_constants(const gfx_api::Draw3DShapeInstancedDepthOnlyGlobalUniforms& cbuf)
Expand Down
25 changes: 16 additions & 9 deletions lib/ivis_opengl/piedraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,11 @@ bool InstancedMeshRenderer::Draw3DShape(iIMDShape *shape, int frame, PIELIGHT te
tshape.stretch = stretchDepth;
tshape.modelMatrix = modelMatrix;

if (pieFlag & pie_SHIELD)
{
tshape.modelMatrix = glm::scale(tshape.modelMatrix, glm::vec3(pie_SHIELD_FACTOR, pie_SHIELD_FACTOR, pie_SHIELD_FACTOR));
}

if (pieFlag & pie_HEIGHT_SCALED) // construct
{
tshape.modelMatrix = glm::scale(tshape.modelMatrix, glm::vec3(1.0f, (float)pieFlagData / (float)pie_RAISE_SCALE, 1.0f));
Expand Down Expand Up @@ -1463,15 +1468,15 @@ bool InstancedMeshRenderer::DrawAll(uint64_t currentGameFrame, const glm::mat4&
}

template<SHADER_MODE shader, typename Draw3DInstancedPSO>
static void drawInstanced3dShapeTemplated_Inner(ShaderOnce& globalsOnce, const gfx_api::Draw3DShapeInstancedGlobalUniforms& globalUniforms, const iIMDShape * shape, gfx_api::buffer* instanceDataBuffer, size_t instanceBufferOffset, size_t instance_count, gfx_api::texture* lightmapTexture)
static void drawInstanced3dShapeTemplated_Inner(ShaderOnce& globalsOnce, const gfx_api::Draw3DShapeInstancedGlobalUniforms& globalUniforms, const iIMDShape * shape, gfx_api::buffer* instanceDataBuffer, size_t instanceBufferOffset, size_t instance_count, gfx_api::texture* lightmapTexture, bool shieldEffect)
{
const auto& textures = shape->getTextures();
auto* tcmask = textures.tcmaskpage != iV_TEX_INVALID ? &pie_Texture(textures.tcmaskpage) : nullptr;
auto* normalmap = textures.normalpage != iV_TEX_INVALID ? &pie_Texture(textures.normalpage) : nullptr;
auto* specularmap = textures.specularpage != iV_TEX_INVALID ? &pie_Texture(textures.specularpage) : nullptr;

gfx_api::Draw3DShapeInstancedPerMeshUniforms meshUniforms {
tcmask ? 1 : 0, normalmap != nullptr, specularmap != nullptr, shape->buffers[VBO_TANGENT] != nullptr
tcmask ? 1 : 0, normalmap != nullptr, specularmap != nullptr, shape->buffers[VBO_TANGENT] != nullptr, shieldEffect ? 1 : 0
};

gfx_api::buffer* pTangentBuffer = (shape->buffers[VBO_TANGENT] != nullptr) ? shape->buffers[VBO_TANGENT] : getZeroedVertexBuffer(shape->vertexCount * 4 * sizeof(gfx_api::gfxFloat));
Expand Down Expand Up @@ -1525,43 +1530,45 @@ static void drawInstanced3dShapeDepthOnly(ShaderOnce& globalsOnce, const gfx_api
template<SHADER_MODE shader, typename AdditivePSO, typename AdditiveNoDepthWRTPSO, typename AlphaPSO, typename AlphaNoDepthWRTPSO, typename PremultipliedPSO, typename PremultipliedNoDepthWRTPSO, typename OpaquePSO>
static void drawInstanced3dShapeTemplated(ShaderOnce& globalsOnce, const gfx_api::Draw3DShapeInstancedGlobalUniforms& globalUniforms, const iIMDShape * shape, int pieFlag, gfx_api::buffer* instanceDataBuffer, size_t instanceBufferOffset, size_t instance_count, gfx_api::texture* lightmapTexture)
{
bool shieldEffect = pieFlag & pie_SHIELD;

/* Set tranlucency */
if (pieFlag & pie_ADDITIVE)
{
if (!(pieFlag & pie_NODEPTHWRITE))
{
return drawInstanced3dShapeTemplated_Inner<shader, AdditivePSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
return drawInstanced3dShapeTemplated_Inner<shader, AdditivePSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture, shieldEffect);
}
else
{
return drawInstanced3dShapeTemplated_Inner<shader, AdditiveNoDepthWRTPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
return drawInstanced3dShapeTemplated_Inner<shader, AdditiveNoDepthWRTPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture, shieldEffect);
}
}
else if (pieFlag & pie_TRANSLUCENT)
{
if (!(pieFlag & pie_NODEPTHWRITE))
{
return drawInstanced3dShapeTemplated_Inner<shader, AlphaPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
return drawInstanced3dShapeTemplated_Inner<shader, AlphaPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture, shieldEffect);
}
else
{
return drawInstanced3dShapeTemplated_Inner<shader, AlphaNoDepthWRTPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
return drawInstanced3dShapeTemplated_Inner<shader, AlphaNoDepthWRTPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture, shieldEffect);
}
}
else if (pieFlag & pie_PREMULTIPLIED)
{
if (!(pieFlag & pie_NODEPTHWRITE))
{
return drawInstanced3dShapeTemplated_Inner<shader, PremultipliedPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
return drawInstanced3dShapeTemplated_Inner<shader, PremultipliedPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture, shieldEffect);
}
else
{
return drawInstanced3dShapeTemplated_Inner<shader, PremultipliedNoDepthWRTPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
return drawInstanced3dShapeTemplated_Inner<shader, PremultipliedNoDepthWRTPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture, shieldEffect);
}
}
else
{
return drawInstanced3dShapeTemplated_Inner<shader, OpaquePSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
return drawInstanced3dShapeTemplated_Inner<shader, OpaquePSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture, shieldEffect);
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/ivis_opengl/pietypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ using nonstd::nullopt;
#define pie_PREMULTIPLIED 0x200
#define pie_NODEPTHWRITE 0x400
#define pie_FORCELIGHT 0x800
#define pie_SHIELD 0x1000

#define pie_RAISE_SCALE 256
#define pie_SHIELD_FACTOR 1.125f

enum LIGHTING_TYPE
{
Expand Down
1 change: 1 addition & 0 deletions lib/sound/audio_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ static AUDIO_ID_MAP asAudioID[] =
{ID_SOUND_BARB_SCREAM2, "scream2.ogg"},
{ID_SOUND_BARB_SCREAM3, "scream3.ogg"},
{ID_SOUND_OF_SILENCE, "silence.ogg"},
{ID_SOUND_SHIELD_HIT, "shield-hit.ogg"},

/* Extra */
{ID_SOUND_LANDING_ZONE, "lndgzne.ogg"},
Expand Down
1 change: 1 addition & 0 deletions lib/sound/audio_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ enum INGAME_AUDIO
ID_SOUND_BARB_SCREAM2,
ID_SOUND_BARB_SCREAM3,
ID_SOUND_OF_SILENCE,
ID_SOUND_SHIELD_HIT,

/* Extra */

Expand Down
Loading
Loading