Skip to content

Commit a0f7656

Browse files
authored
Merge pull request #181 from cortex-command-community/gpu-primitives
GPU primitives
2 parents c9fdec0 + 09f9469 commit a0f7656

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+12982
-7889
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8181

8282
- New `Attachable` INI and Lua (R/W) properties `InheritsVelWhenDetached` and `InheritsAngularVelWhenDetached`, which determine how much of these velocities an attachable inherits from its parent when detached. Defaults to 1.
8383

84+
- New GPU Renderer using OpenGL+Raylib, draw now takes 0ms in pretty much every instance.
85+
86+
- New Z Order for scene layers and primitives: Background layer sits at z=100, Terrain Background at z=50, Terrain color and MO color at z=0, GUIs sit at z=-100, allowed z range is [-200, +200], in the future this'll be expanded to MO draw as well.
8487
- Added Lua-accessible bitmap manipulation functions to `MOSprite`s:
8588
```
8689
GetSpritePixelIndex(int x, int y, int whichFrame) - Returns the color index of the pixel at the given coordinate on the given frame of the sprite ((0, 0) is the upper left corner!)
@@ -103,6 +106,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
103106

104107
- New `SceneMan` function `CastAllMOsRay(startVector, rayVector, table ignoreMOIDs, ignoreTeam, ignoreMaterial, bool ignoreAllTerrain, int skip)` which returns an iterator with pointers to all the non-ignored MOs met along the ray.
105108

109+
- New parameter `depth` for all primitives sets draw depth of the drawn primitive. The default depth is -75.0 (lower numbers draw on top, higher numbers in the back).
110+
111+
- New `DrawDepth` enum for default draw depths:
112+
- `Default` = 0.0f (Main draw depth for MOs)
113+
- `GUI` = -100.0f (Draw Depth of GUI elements)
114+
- `Primitive` = -75.0f (Default Primitive draw depth)
115+
- `TerrainBackground` = 50.0f (Draw Depth of Terrain Background layer)
116+
- `Background` = 100.0f (Draw Depth of Background layer)
117+
106118
- Added scaling capability to Bitmap primitives.
107119
New draw bindings with argument for scale are:
108120
```
@@ -168,6 +180,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
168180

169181
- `InheritsVel` and its ilk have been uncapped, allowing users to set them outside of 0-1.
170182

183+
- Lua renamed `SceneLayer`->`StaticSceneLayer` due to changed SLBackground base class.
184+
171185
- `Scene` Lua functions `AddNavigatableArea(areaName)` and `ClearNavigatableAreas()` have been renamed/corrected to `AddNavigableArea(areaName)` and `ClearNavigableAreas()`, respectively.
172186

173187
- `MOSRotating` Lua function `AddWound` now additionally accepts the format `MOSRotating:AddWound(AEmitter* woundToAdd, const Vector& parentOffsetToSet, bool checkGibWoundLimit, bool isEntryWound, bool isExitWound)`, allowing modders to specify added wounds as entry- or exit wounds, for the purpose of not playing multiple burst sounds on the same frame. These new arguments are optional.
@@ -204,6 +218,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
204218

205219
- Fixed an issue where internal Lua functions OriginalDoFile, OriginalLoadFile, and OriginalRequire were polluting the global namespace. They have now been made inaccessible.
206220

221+
- Fixed the palette being mangled to 6bit/color on load.
222+
223+
- Fixed allegro not loading alpha of image with alpha by using SDL_image instead.
207224
- Fixed `MOSprite:UnRotateOffset()` giving the wrong results on HFLipped sprites.
208225

209226
- Various fixes and improvements to inventory management when dual-wielding or carrying a shield, to stop situations where the actor unexpectedly puts their items away.

Data/Base.rte/Shaders/Background.frag

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
#version 130
1+
#version 330
2+
#extension GL_KHR_blend_equation_advanced: enable
3+
#extension GL_ARB_sample_shading: enable
24

35
in vec2 textureUV;
46
in vec4 vertexColor;
57

8+
#ifdef GL_KHR_blend_equation_advanced
9+
layout(blend_support_all_equations) out;
10+
#endif
611
out vec4 FragColor;
7-
812
uniform sampler2D rteTexture;
913
uniform sampler2D rtePalette;
10-
uniform vec4 rteColor;
11-
uniform bool drawMasked;
14+
uniform vec4 rteColor = vec4(1.0);
15+
uniform bool rteBlendInvert = false;
16+
uniform bool drawMasked = false;
1217

1318

1419
vec4 texture2DAA(sampler2D tex, vec2 uv) {
@@ -25,5 +30,9 @@ void main() {
2530
if (red==0 && drawMasked) {
2631
discard;
2732
}
28-
FragColor = texture2DAA(rtePalette, vec2(red * rteColor.r * vertexColor.r, 0.0)) * vec4(vec3(1.0), rteColor.a * vertexColor.a);
33+
if (!rteBlendInvert) {
34+
FragColor = texture2DAA(rtePalette, vec2(red * vertexColor.r, 0.0)) * vec4(rteColor.rgb, rteColor.a * vertexColor.a);
35+
} else {
36+
FragColor = vec4(vec3(1.0), 0.0) - (texture2DAA(rtePalette, vec2(red * vertexColor.r, 0.0)) * vec4(rteColor.rgb, -rteColor.a * vertexColor.a));
37+
}
2938
}

Data/Base.rte/Shaders/Blit8.vert

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ in vec4 rteVertexColor;
66

77
out vec2 textureUV;
88
out vec4 vertexColor;
9-
//uniform mat4 rteModelViewProjection;
9+
uniform mat4 rteView;
1010
uniform mat4 rteProjection;
1111

1212
void main() {
13-
gl_Position = rteProjection * vec4(rteVertexPosition, 1.0);
13+
gl_Position = rteProjection * rteView * vec4(rteVertexPosition, 1.0);
1414
textureUV = rteVertexTexUV;
1515
vertexColor = rteVertexColor;
1616
}

Data/Base.rte/Shaders/Dissolve.frag

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#version 130
2+
3+
in vec2 textureUV;
4+
in vec4 vertexColor;
5+
6+
out vec4 FragColor;
7+
8+
uniform sampler2D rteTexture;
9+
uniform sampler2D rtePalette;
10+
uniform vec4 rteColor;
11+
12+
// Pseudo random number generator.
13+
float hash( vec2 a )
14+
{
15+
return fract( sin( a.x * 3433.8 + a.y * 3843.98 ) * 45933.8 );
16+
}
17+
18+
// Value noise courtesy of BigWingz
19+
// check his youtube channel he has
20+
// a video of this one.
21+
// Succint version by FabriceNeyret
22+
float noise( vec2 U )
23+
{
24+
vec2 id = floor( U );
25+
U = fract( U );
26+
U *= U * ( 3. - 2. * U );
27+
28+
vec2 A = vec2( hash(id), hash(id + vec2(0,1)) );
29+
vec2 B = vec2( hash(id + vec2(1,0)), hash(id + vec2(1,1)) );
30+
vec2 C = mix( A, B, U.x);
31+
32+
return mix( C.x, C.y, U.y );
33+
}
34+
35+
vec4 texture2DAA(sampler2D tex, vec2 uv) {
36+
vec2 texsize = vec2(textureSize(tex, 0));
37+
vec2 uv_texspace = uv * texsize;
38+
vec2 seam = floor(uv_texspace + .5);
39+
uv_texspace = (uv_texspace - seam) / fwidth(uv_texspace) + seam;
40+
uv_texspace = clamp(uv_texspace, seam - .5, seam + .5);
41+
return texture(tex, uv_texspace / texsize);
42+
}
43+
44+
void main() {
45+
if (noise(gl_FragCoord.xy + textureUV) < 0.5) {
46+
discard;
47+
}
48+
float red = texture2D(rteTexture, textureUV).r;
49+
vec4 color = texture2DAA(rtePalette, vec2(red * vertexColor.r, 0.0)) * vec4(rteColor.rgb, rteColor.a * vertexColor.a);
50+
51+
FragColor = color;
52+
}

Data/Base.rte/Shaders/PostProcess.vert

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ in vec4 rteVertexColor;
77
out vec2 textureUV;
88
out vec4 vertexColor;
99

10-
uniform mat4 rteModel;
10+
uniform mat4 rteView;
1111
uniform mat4 rteProjection;
1212

1313
void main() {
14-
gl_Position = rteProjection * rteModel * vec4(rteVertexPosition, 1.0);
14+
gl_Position = rteProjection * rteView * vec4(rteVertexPosition, 1.0);
1515
vertexColor = rteVertexColor;
1616
textureUV = rteVertexTexUV;
1717
}

Data/Base.rte/Shaders/ScreenBlit.vert

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ in vec2 rteVertexTexUV;
55

66
out vec2 textureUV;
77

8-
uniform mat4 rteModel;
8+
uniform mat4 rteView;
99
uniform mat4 rteProjection;
1010

1111
void main() {
12-
gl_Position = rteProjection * rteModel * vec4(rteVertexPosition, 1.0);
12+
gl_Position = rteProjection * rteView * vec4(rteVertexPosition, 1.0);
1313
textureUV = rteVertexTexUV;
1414
}

Data/Base.rte/Shaders/Shaders.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ AddShader = Shader
1717
PresetName = Background
1818
VertexShader = Base.rte/Shaders/Blit8.vert
1919
FragmentShader = Base.rte/Shaders/Background.frag
20+
21+
AddShader = Shader
22+
PresetName = Dissolve
23+
VertexShader = Base.rte/Shaders/Blit8.vert
24+
FragmentShader = Base.rte/Shaders/Dissolve.frag

RTEA.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@
801801
<ClInclude Include="Source\Renderer\GLCheck.h" />
802802
<ClInclude Include="Source\System\InputMapping.h" />
803803
<ClInclude Include="Source\System\InputScheme.h" />
804-
<ClInclude Include="Source\System\GraphicalPrimitive.h" />
804+
<ClInclude Include="Source\Renderer\GraphicalPrimitive.h" />
805805
<ClInclude Include="Source\System\Gamepad.h" />
806806
<ClInclude Include="Source\Menus\InventoryMenuGUI.h" />
807807
<ClInclude Include="Source\System\PieQuadrant.h" />
@@ -1324,7 +1324,7 @@
13241324
<ClCompile Include="Source\Renderer\GLCheck.cpp" />
13251325
<ClCompile Include="Source\System\InputMapping.cpp" />
13261326
<ClCompile Include="Source\System\InputScheme.cpp" />
1327-
<ClCompile Include="Source\System\GraphicalPrimitive.cpp" />
1327+
<ClCompile Include="Source\Renderer\GraphicalPrimitive.cpp" />
13281328
<ClCompile Include="Source\System\PieQuadrant.cpp" />
13291329
<ClCompile Include="Source\System\Semver200\Semver200_comparator.cpp" />
13301330
<ClCompile Include="Source\System\Semver200\Semver200_modifier.cpp" />

RTEA.vcxproj.filters

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@
499499
<ClInclude Include="Source\Entities\Activity.h">
500500
<Filter>Entities</Filter>
501501
</ClInclude>
502-
<ClInclude Include="Source\System\GraphicalPrimitive.h">
503-
<Filter>System</Filter>
502+
<ClInclude Include="Source\Renderer\GraphicalPrimitive.h">
503+
<Filter>Renderer</Filter>
504504
</ClInclude>
505505
<ClInclude Include="Source\Menus\TitleScreen.h">
506506
<Filter>Menus</Filter>
@@ -1080,8 +1080,8 @@
10801080
<ClCompile Include="Source\Entities\Activity.cpp">
10811081
<Filter>Entities</Filter>
10821082
</ClCompile>
1083-
<ClCompile Include="Source\System\GraphicalPrimitive.cpp">
1084-
<Filter>System</Filter>
1083+
<ClCompile Include="Source\Renderer\GraphicalPrimitive.cpp">
1084+
<Filter>Renderer</Filter>
10851085
</ClCompile>
10861086
<ClCompile Include="Source\Menus\TitleScreen.cpp">
10871087
<Filter>Menus</Filter>

Source/Entities/PieMenu.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ void PieMenu::Draw(BITMAP* targetBitmap, const Vector& targetPos) const {
636636
Vector drawPos;
637637
CalculateDrawPosition(targetBitmap, targetPos, drawPos);
638638

639+
rlZDepth(c_GuiDepth);
639640
if (m_EnabledState != EnabledState::Disabled) {
640641
if (m_DrawBackgroundTransparent) {
641642
g_FrameMan.SetTransTableFromPreset(TransparencyPreset::MoreTrans);
@@ -646,6 +647,7 @@ void PieMenu::Draw(BITMAP* targetBitmap, const Vector& targetPos) const {
646647
DrawTexture(g_GLResourceMan.GetStaticTextureFromBitmap(m_BGBitmap), drawPos.GetFloorIntX() - m_BGBitmap->w / 2, drawPos.GetFloorIntY() - m_BGBitmap->h / 2, {255, 255, 255, 255});
647648
}
648649
}
650+
rlZDepth(c_DefaultDrawDepth);
649651

650652
if (m_EnabledState == EnabledState::Enabled) {
651653
DrawPieIcons(targetBitmap, drawPos);

0 commit comments

Comments
 (0)