Skip to content
Merged
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
375 changes: 188 additions & 187 deletions levels/avaraline-strict-mode/alf/layout/io.alf

Large diffs are not rendered by default.

422 changes: 213 additions & 209 deletions levels/avaraline-strict-mode/alf/layout/not-nul.alf

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions platform/macos/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,34 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDocumentTypes</key>
<array>
<dict/>
</array>
<key>NSHighResolutionCapable</key>
<true/>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.xml</string>
</array>
<key>UTTypeIcons</key>
<dict>
<key>UTTypeIconBadgeName</key>
<string></string>
</dict>
<key>UTTypeIdentifier</key>
<string>net.avaraline.alf</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>alf</string>
</array>
</dict>
</dict>
</array>
</dict>
</plist>
6 changes: 4 additions & 2 deletions rsrc/aftershock/default.avarascript
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,10 @@
// Material properties:
defaultMaterial.specular = 0
defaultMaterial.shininess = 0
baseMaterial.specular = defaultMaterial.specular
baseMaterial.shininess = defaultMaterial.shininess
defaultMaterial.glow = 0
baseMaterial.specular = 0
baseMaterial.shininess = 0
baseMaterial.glow = 0

// Advanced weapon powers:
grenadePower = 2.05
Expand Down
2 changes: 2 additions & 0 deletions rsrc/default.avarascript
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,10 @@
// Material properties:
defaultMaterial.specular = 0
defaultMaterial.shininess = 0
defaultMaterial.glow = 0
baseMaterial.specular = 0
baseMaterial.shininess = 0
baseMaterial.glow = 0

// Advanced weapon powers:
grenadePower = 2.25
Expand Down
8 changes: 7 additions & 1 deletion rsrc/shaders/hud_vert.glsl
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec4 vertexColor;
layout(location = 2) in vec4 vertexSpecular;
layout(location = 3) in vec3 vertexNormal;
layout(location = 3) in float vertexGlow;
layout(location = 4) in float vertexReserved1;
layout(location = 5) in float vertexReserved2;
layout(location = 6) in float vertexReserved3;
layout(location = 7) in vec3 vertexNormal;

uniform mat4 view;
uniform mat4 proj;
uniform mat4 model;

out vec4 fragmentColor;
out vec4 fragmentSpecular;
out float fragmentGlow;
out vec3 fragmentNormal;

void main() {
vec4 pos = vec4(vertexPosition_modelspace, 1.0);
gl_Position = proj * (pos * model * view);
fragmentColor = vertexColor;
fragmentSpecular = vertexSpecular;
fragmentGlow = vertexGlow;
fragmentNormal = vertexNormal;
}
13 changes: 9 additions & 4 deletions rsrc/shaders/sky_frag.glsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define GROUND_PHI 0.0
#define MAX_LIGHTS 4

in vec3 tex_coord;
Expand Down Expand Up @@ -45,16 +46,20 @@ vec3 apply_fog(vec3 color, vec3 viewDir, float dist) {
}

vec3 draw_celestial(vec3 inColor, float phi, float gradientHeight, vec3 offsetFragPos, int i) {
if (lightCelestialRadius[i] == 0.0 || phi <= 0.0) return inColor;
if (lightCelestialRadius[i] == 0.0 || phi <= GROUND_PHI) return inColor;
float dist = distance(offsetFragPos, lightPos[i]);
float coronaRadius = lightCelestialRadius[i] * (1 + length(lightDir[i]));
//float horizonRadius = coronaRadius * (1 - clamp(phi, 0.0, 1.0));
return mix(
inColor,
mix(
lightColor[i],
lightColor[i] * gradientHeight + horizonColor * (1.0 - gradientHeight),
float(phi < highAlt)
),
float(dist <= lightCelestialRadius[i])
pow(clamp(1 - ((dist - lightCelestialRadius[i]) / (coronaRadius - lightCelestialRadius[i])), 0.0, 1.0), 4)
//clamp(1 - (lightCelestialRadius[i] / coronaRadius), 0.0, 1.0)
//float(dist <= lightCelestialRadius[i])
);
}

Expand Down Expand Up @@ -105,7 +110,7 @@ void main()
float(phi > highAlt)
),
groundColor + spec(viewDir),
float(phi <= 0.0)
float(phi <= GROUND_PHI)
),
1.0
);
Expand All @@ -119,7 +124,7 @@ void main()
mix(
-dot(camPos, vec3(0, 1, 0)) / dot(-viewDir, vec3(0, 1, 0)),
maxHazeDist,
float(phi >= 0.0)
float(phi >= GROUND_PHI)
),
maxHazeDist
);
Expand Down
11 changes: 8 additions & 3 deletions rsrc/shaders/world_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
in vec4 fragmentColor;
in vec3 fragmentSpecular;
in float fragmentShininess;
in float fragmentGlow;
in vec3 fragmentNormal;
in vec3 fragPos;

Expand Down Expand Up @@ -81,9 +82,13 @@ float noise() {

vec4 light_color(vec3 viewDir) {
return mix(
ambient * vec4(ambientColor, 1.0) * fragmentColor,
vec4((ambient * ambientColor) + diffuse() + spec(viewDir), 1.0) * fragmentColor,
float(lightsActive)
mix(
ambient * vec4(ambientColor, 1.0) * fragmentColor,
vec4((ambient * ambientColor) + diffuse() + spec(viewDir), 1.0) * fragmentColor,
float(lightsActive)
),
fragmentColor,
float(fragmentGlow > 0.0)
);
}

Expand Down
9 changes: 8 additions & 1 deletion rsrc/shaders/world_vert.glsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec4 vertexColor;
layout(location = 2) in vec4 vertexSpecular;
layout(location = 3) in vec3 vertexNormal;
layout(location = 3) in float vertexGlow;
layout(location = 4) in float vertexReserved1;
layout(location = 5) in float vertexReserved2;
layout(location = 6) in float vertexReserved3;
layout(location = 7) in vec3 vertexNormal;

uniform float maxShininess;
uniform float maxGlow;
uniform mat4 model;
uniform mat4 view;
uniform mat4 proj;
Expand All @@ -12,6 +17,7 @@ uniform mat3 normalTransform;
out vec4 fragmentColor;
out vec3 fragmentSpecular;
out float fragmentShininess;
out float fragmentGlow;
out vec3 fragmentNormal;
out vec3 fragPos;

Expand All @@ -21,6 +27,7 @@ void main() {
fragmentColor = vertexColor;
fragmentSpecular = vertexSpecular.rgb;
fragmentShininess = vertexSpecular.a * maxShininess;
fragmentGlow = vertexGlow * maxGlow;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should either fix this line to just use the raw vertexGlow (and remove maxGlow from the shader entirely), or go ahead and replace the single 32-bit float in the vertex array with four uint8_t's similar to how specular/shininess are stored and follow that pattern. That would mean 3 uint8_t's would be "reserved" for additional material properties in the future.

I don't love that plan, but ultimately, it's occupying exactly the same amount of space as it is currently.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...it also occurs to me that maybe simply reordering the layout of the struct would rectify the issue I was seeing. If I put all the floats at the beginning and the uint8_t's at the end, I don't believe I'll have the same padding issues.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually what am I saying, it's an array of these vertices, there will still be padding issues unless I reserve the padding explicitly.

fragmentNormal = vertexNormal * normalTransform;
fragPos = (pos * model).xyz;
}
34 changes: 33 additions & 1 deletion src/bsp/CBSPPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ void CBSPPart::IBSPPart(short resId) {
original = baseMaterial;
current = baseMaterial;
nlohmann::json const &mat = doc["materials"][i];
ARGBColor color = ARGBColor(0x00ffffff); // Default to invisible "white."
ARGBColor color = defaultMaterial.GetColor();
ARGBColor spec = defaultMaterial.GetSpecular().WithA(defaultMaterial.GetShininess());
uint8_t glow = defaultMaterial.GetGlow();

if (mat.find("base") != mat.end()) {
color = ARGBColor::Parse(mat["base"])
Expand Down Expand Up @@ -137,6 +138,13 @@ void CBSPPart::IBSPPart(short resId) {
spec = baseMaterial.GetSpecular().WithA(baseMaterial.GetShininess());
}
current = current.WithSpecular(spec).WithShininess(spec.GetA());

glow = mat.value<uint8_t>("glow", 0);
original = original.WithGlow(glow);
if (glow == defaultMaterial.GetGlow()) {
glow = baseMaterial.GetGlow();
}
current = current.WithGlow(glow);
materialTable.push_back(MaterialRecord(original, current));
}

Expand Down Expand Up @@ -476,6 +484,30 @@ void CBSPPart::ReplaceShininessForColor(ARGBColor origColor, uint8_t newShinines
if (shininessReplaced && vData) vData->Replace(*this);
}

void CBSPPart::ReplaceGlowForColor(ARGBColor origColor, uint8_t newGlow) {
bool glowReplaced = false;
for (auto &material : materialTable) {
if (material.original.GetColor() == origColor) {
material.current = material.current.WithGlow(newGlow);
glowReplaced = true;
}
}
// (No need to check for alpha here.)
if (glowReplaced && vData) vData->Replace(*this);
}

void CBSPPart::ReplaceAllGlow(uint8_t newGlow) {
bool glowReplaced = false;
for (auto &material : materialTable) {
if (material.current.GetGlow() != newGlow) {
glowReplaced = true;
}
material.current = material.current.WithGlow(newGlow);
}
// (No need to check for alpha here.)
if (glowReplaced && vData) vData->Replace(*this);
}

void CBSPPart::ReplaceMaterial(Material origMaterial, Material newMaterial) {
bool materialReplaced = false;
for (auto &material : materialTable) {
Expand Down
2 changes: 2 additions & 0 deletions src/bsp/CBSPPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ class CBSPPart {
virtual void ReplaceMaterialForColor(ARGBColor origColor, Material newMaterial);
virtual void ReplaceSpecularForColor(ARGBColor origColor, ARGBColor newSpecular);
virtual void ReplaceShininessForColor(ARGBColor origColor, uint8_t newShininess);
virtual void ReplaceGlowForColor(ARGBColor origColor, uint8_t newGlow);
virtual void ReplaceAllGlow(uint8_t newGlow);
virtual void ReplaceMaterial(Material origMaterial, Material newMaterial);
virtual void ReplaceAllMaterials(Material newMaterial);

Expand Down
10 changes: 10 additions & 0 deletions src/game/CScout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ CScout::CScout(CAbstractPlayer *thePlayer, short theTeam, ARGBColor longTeamColo
partCount = 1;
LoadPart(0, kScoutBSP);
partList[0]->ReplaceColor(*ColorManager::getMarkerColor(0), longTeamColor);
for (CSmartPart **thePart = partList; *thePart; thePart++) {
(*thePart)->ReplaceSpecularForColor(*ColorManager::getMarkerColor(0), ARGBColor(0x333333));
(*thePart)->ReplaceShininessForColor(*ColorManager::getMarkerColor(0), 4);
(*thePart)->ReplaceSpecularForColor(*ColorManager::getMarkerColor(1), ARGBColor(0x454545));
(*thePart)->ReplaceShininessForColor(*ColorManager::getMarkerColor(1), 8);
(*thePart)->ReplaceSpecularForColor(*ColorManager::getMarkerColor(2), ARGBColor(0xa6a6a6));
(*thePart)->ReplaceShininessForColor(*ColorManager::getMarkerColor(2), 48);
(*thePart)->ReplaceSpecularForColor(*ColorManager::getMarkerColor(3), ARGBColor(0x808080));
(*thePart)->ReplaceShininessForColor(*ColorManager::getMarkerColor(3), 24);
}

hitSoundId = 220;

Expand Down
1 change: 1 addition & 0 deletions src/game/CSmart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ long CSmart::Arm(CSmartPart *aPart) {
shields = FIX3(100);

partList[0]->ReplaceColor(*ColorManager::getMarkerColor(1), ColorManager::getMissileArmedColor());
partList[0]->ReplaceGlowForColor(*ColorManager::getMarkerColor(1), 16);
targetIdent = 0;
targetPart = NULL;

Expand Down
2 changes: 1 addition & 1 deletion src/game/CWorldShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ class CWorldShader {


CWorldShader();
virtual void Reset();
void Reset();
};
32 changes: 32 additions & 0 deletions src/level/LevelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Material GetDefaultMaterial() {
defaultMaterial = defaultMaterial.WithSpecular(*specular);
}
defaultMaterial = defaultMaterial.WithShininessVar(iDefaultMaterialShininess);
defaultMaterial = defaultMaterial.WithGlowVar(iDefaultMaterialGlow);
return defaultMaterial;
}

Expand All @@ -87,6 +88,7 @@ Material GetBaseMaterial() {
baseMaterial = baseMaterial.WithSpecular(*specular);
}
baseMaterial = baseMaterial.WithShininessVar(iBaseMaterialShininess);
baseMaterial = baseMaterial.WithGlowVar(iBaseMaterialGlow);
return baseMaterial;
}

Expand Down Expand Up @@ -153,6 +155,8 @@ struct ALFWalker: pugi::xml_tree_walker {
attr = "material.0.specular";
} else if (attr.compare("material.shininess") == 0) {
attr = "material.0.shininess";
} else if (attr.compare("material.glow") == 0) {
attr = "material.0.glow";
}
// XML attributes can't have brackets, so we turn light.0.i into light[0].i
std::regex subscript("\\.(\\d+)");
Expand Down Expand Up @@ -274,6 +278,14 @@ struct ALFWalker: pugi::xml_tree_walker {
palette[3] = palette[3].WithShininessVar(iBaseMaterialShininess);
}

if (!node.attribute("baseMaterial.glow").empty()) {
// When baseMaterial properties are set, apply it to all mats.
palette[0] = palette[0].WithGlowVar(iBaseMaterialGlow);
palette[1] = palette[1].WithGlowVar(iBaseMaterialGlow);
palette[2] = palette[2].WithGlowVar(iBaseMaterialGlow);
palette[3] = palette[3].WithGlowVar(iBaseMaterialGlow);
}

if (!node.attribute("material.specular").empty()) {
const std::optional<ARGBColor> color = ReadColorVar("material[0].specular");
if (color) {
Expand Down Expand Up @@ -328,6 +340,26 @@ struct ALFWalker: pugi::xml_tree_walker {
if (!node.attribute("material.3.shininess").empty()) {
palette[3] = palette[3].WithShininessVar("material[3].shininess");
}

if (!node.attribute("material.glow").empty()) {
palette[0] = palette[0].WithGlowVar("material[0].glow");
}

if (!node.attribute("material.0.glow").empty()) {
palette[0] = palette[0].WithGlowVar("material[0].glow");
}

if (!node.attribute("material.1.glow").empty()) {
palette[1] = palette[1].WithGlowVar("material[1].glow");
}

if (!node.attribute("material.2.glow").empty()) {
palette[2] = palette[2].WithGlowVar("material[2].glow");
}

if (!node.attribute("material.3.glow").empty()) {
palette[3] = palette[3].WithGlowVar("material[3].glow");
}

if (!node.attribute("x").empty() && !node.attribute("z").empty() &&
!node.attribute("w").empty() && !node.attribute("d").empty()) {
Expand Down
2 changes: 2 additions & 0 deletions src/level/LevelLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ enum {
// Materials
iDefaultMaterialSpecular,
iDefaultMaterialShininess,
iDefaultMaterialGlow,
iBaseMaterialSpecular,
iBaseMaterialShininess,
iBaseMaterialGlow,

// Advanced weapons
iGrenadePower,
Expand Down
Loading