Skip to content

Commit a3b3c06

Browse files
authored
Merge pull request #119 from MilchRatchet/dev-collision-vis
Improved collision visualization
2 parents f75ddf4 + 8591341 commit a3b3c06

8 files changed

Lines changed: 70 additions & 7 deletions

File tree

LibReplanetizer/Models/Collision.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ public Collision(FileStream fs, int collisionPointer)
104104
uint f1 = totalVertexCount + b0;
105105
uint f2 = totalVertexCount + b1;
106106
uint f3 = totalVertexCount + b2;
107-
indexList.Add(f1);
108107
indexList.Add(f2);
108+
indexList.Add(f1);
109109
indexList.Add(f3);
110110

111111
if (f < rCount)
112112
{
113113
int rOffset = vOffset + 4 + (12 * vertexCount) + (faceCount * 4) + f;
114114
uint f4 = totalVertexCount + collision[rOffset];
115-
indexList.Add(f1);
116115
indexList.Add(f3);
116+
indexList.Add(f1);
117117
indexList.Add(f4);
118118
collisionType[collision[rOffset]] = b3;
119119
}

Replanetizer/Renderer/CollisionRenderer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ public override void Render(RendererPayload payload)
114114
shaderTable.collisionShader.UseShader();
115115
GL.PolygonMode(TriangleFace.FrontAndBack, PolygonMode.Fill);
116116

117+
GL.Enable(EnableCap.CullFace);
118+
GL.CullFace(TriangleFace.Back);
119+
117120
for (int i = 0; i < numCollisions; i++)
118121
{
119122
if (!payload.visibility.chunks[i]) continue;
@@ -122,6 +125,8 @@ public override void Render(RendererPayload payload)
122125
GL.DrawElements(PrimitiveType.Triangles, indexCount[i], DrawElementsType.UnsignedInt, 0);
123126
}
124127

128+
GL.Disable(EnableCap.CullFace);
129+
125130
GLUtil.CheckGlError("CollisionRenderer");
126131
}
127132

Replanetizer/Renderer/LevelRenderer.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,30 @@ public override void Render(RendererPayload payload)
268268
1.0f - levelVariables.fogFarIntensity / 255.0f);
269269
}
270270

271+
shaderTable.colorShader.UseShader();
272+
shaderTable.colorShader.SetUniform1(UniformName.useFog, (useFog) ? 1 : 0);
273+
274+
if (useFog && levelVariables != null)
275+
{
276+
shaderTable.colorShader.SetUniform4(UniformName.fogColor, levelVariables.fogColor);
277+
shaderTable.colorShader.SetUniform4(UniformName.fogParams, levelVariables.fogNearDistance / 1024.0f,
278+
1024.0f / (levelVariables.fogFarDistance - levelVariables.fogNearDistance),
279+
1.0f - levelVariables.fogNearIntensity / 255.0f,
280+
1.0f - levelVariables.fogFarIntensity / 255.0f);
281+
}
282+
283+
shaderTable.collisionShader.UseShader();
284+
shaderTable.collisionShader.SetUniform1(UniformName.useFog, (useFog) ? 1 : 0);
285+
286+
if (useFog && levelVariables != null)
287+
{
288+
shaderTable.collisionShader.SetUniform4(UniformName.fogColor, levelVariables.fogColor);
289+
shaderTable.collisionShader.SetUniform4(UniformName.fogParams, levelVariables.fogNearDistance / 1024.0f,
290+
1024.0f / (levelVariables.fogFarDistance - levelVariables.fogNearDistance),
291+
1.0f - levelVariables.fogNearIntensity / 255.0f,
292+
1.0f - levelVariables.fogFarIntensity / 255.0f);
293+
}
294+
271295
dirLightsBuffer.Update(lights);
272296
dirLightsBuffer.Bind();
273297

Replanetizer/Replanetizer.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@
8484
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
8585
</None>
8686
<None Update="Shaders\collisionshaderfs.glsl">
87-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
87+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
8888
</None>
8989
<None Update="Shaders\collisionshadervs.glsl">
90-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
90+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9191
</None>
9292
<None Update="Shaders\colorshaderfs.glsl">
93-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
93+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9494
</None>
9595
<None Update="Shaders\colorshadervs.glsl">
96-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
96+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9797
</None>
9898
<None Update="Shaders\fs.glsl">
9999
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

Replanetizer/Shaders/collisionshaderfs.glsl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
// Interpolated values from the vertex shaders
44
in vec4 diffuseColors;
5+
in float fogBlend;
56

67
// Ouput data
7-
out vec4 color;
8+
layout(location = 0) out vec4 color;
9+
10+
uniform vec4 fogColor;
811

912
void main() {
1013
color = diffuseColors / 255.0f;
14+
color.xyz = (fogColor.xyz - color.xyz) * fogBlend + color.xyz;
1115
}

Replanetizer/Shaders/collisionshadervs.glsl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,27 @@ layout(location = 1) in vec4 vertexColors;
66

77
// Output data ; will be interpolated for each fragment.
88
out vec4 diffuseColors;
9+
out float fogBlend;
910

1011
// Values that stay constant for the whole mesh.
1112
uniform mat4 worldToView;
13+
uniform int useFog;
14+
uniform vec4 fogParams;
1215

1316
void main() {
1417
// Output position of the vertex, in clip space : MVP * position
1518
gl_Position = worldToView * vec4(vertexPosition_modelspace, 1.0f);
1619

1720
// UV of the vertex. No special space for this one.
1821
diffuseColors = vertexColors;
22+
23+
fogBlend = 0.0f;
24+
25+
if (useFog == 1) {
26+
float depth = gl_Position.w - fogParams.x;
27+
28+
depth = clamp(depth * fogParams.y, 0.0f, 1.0f);
29+
30+
fogBlend = fogParams.z + depth * fogParams.w;
31+
}
1932
}

Replanetizer/Shaders/colorshaderfs.glsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Interpolated values from the vertex shaders
44
//in vec2 UV;
55
in vec4 DiffuseColor;
6+
in float fogBlend;
67

78
// Ouput data
89
layout(location = 0) out vec4 color;
@@ -12,8 +13,11 @@ layout(location = 1) out int id;
1213
uniform sampler2D mainTexture;
1314
uniform int levelObjectType;
1415
uniform int levelObjectNumber;
16+
uniform vec4 fogColor;
1517

1618
void main() {
1719
color = vec4(DiffuseColor.rgb, 1.0f);
1820
id = (levelObjectType << 24) | levelObjectNumber;
21+
22+
color.xyz = (fogColor.xyz - color.xyz) * fogBlend + color.xyz;
1923
}

Replanetizer/Shaders/colorshadervs.glsl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,29 @@ layout(location = 0) in vec3 vertexPosition_modelspace;
55

66
// Output data ; will be interpolated for each fragment.
77
out vec4 DiffuseColor;
8+
out float fogBlend;
89

910
// Values that stay constant for the whole mesh.
1011
uniform mat4 worldToView;
1112
uniform mat4 modelToWorld;
1213
uniform vec4 incolor;
14+
uniform int useFog;
15+
uniform vec4 fogParams;
1316

1417
void main() {
1518
// Output position of the vertex, in clip space : MVP * position
1619
gl_Position = worldToView * (modelToWorld * vec4(vertexPosition_modelspace, 1.0f));
1720

1821
// UV of the vertex. No special space for this one.
1922
DiffuseColor = incolor;
23+
24+
fogBlend = 0.0f;
25+
26+
if (useFog == 1) {
27+
float depth = gl_Position.w - fogParams.x;
28+
29+
depth = clamp(depth * fogParams.y, 0.0f, 1.0f);
30+
31+
fogBlend = fogParams.z + depth * fogParams.w;
32+
}
2033
}

0 commit comments

Comments
 (0)