Skip to content

Commit

Permalink
fuck you skybox
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Aug 29, 2022
1 parent b200212 commit 0c5ede6
Show file tree
Hide file tree
Showing 16 changed files with 351 additions and 97 deletions.
84 changes: 84 additions & 0 deletions FModel/Extensions/ImGuiExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Numerics;
using ImGuiNET;

namespace FModel.Extensions;

public static class ImGuiExtensions
{
public const float PADDING = 5.0f;
public static ImGuiStylePtr STYLE = ImGui.GetStyle();

public static void DrawFPS()
{
const ImGuiWindowFlags flags =
ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.AlwaysAutoResize |
ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoFocusOnAppearing |
ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoNav;
var viewport = ImGui.GetMainViewport();
var work_pos = viewport.WorkPos;
var work_size = viewport.WorkSize;

ImGui.SetNextWindowPos(new Vector2(work_pos.X + PADDING, work_pos.Y + work_size.Y - PADDING), ImGuiCond.Always, new Vector2(0, 1));
if (ImGui.Begin("FPS Overlay", flags))
{
float framerate = ImGui.GetIO().Framerate;
ImGui.Text($"FPS: {framerate:0} ({1000.0f / framerate:0.##} ms)");
}
ImGui.End();
}

public static void Theme()
{
STYLE.FrameRounding = 4.0f;
STYLE.GrabRounding = 4.0f;

STYLE.Colors[(int) ImGuiCol.Text] = new Vector4(0.95f, 0.96f, 0.98f, 1.00f);
STYLE.Colors[(int) ImGuiCol.TextDisabled] = new Vector4(0.36f, 0.42f, 0.47f, 1.00f);
STYLE.Colors[(int) ImGuiCol.WindowBg] = new Vector4(0.11f, 0.15f, 0.17f, 0.35f);
STYLE.Colors[(int) ImGuiCol.ChildBg] = new Vector4(0.15f, 0.18f, 0.22f, 1.00f);
STYLE.Colors[(int) ImGuiCol.PopupBg] = new Vector4(0.08f, 0.08f, 0.08f, 0.94f);
STYLE.Colors[(int) ImGuiCol.Border] = new Vector4(0.08f, 0.10f, 0.12f, 1.00f);
STYLE.Colors[(int) ImGuiCol.BorderShadow] = new Vector4(0.00f, 0.00f, 0.00f, 0.00f);
STYLE.Colors[(int) ImGuiCol.FrameBg] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f);
STYLE.Colors[(int) ImGuiCol.FrameBgHovered] = new Vector4(0.12f, 0.20f, 0.28f, 1.00f);
STYLE.Colors[(int) ImGuiCol.FrameBgActive] = new Vector4(0.09f, 0.12f, 0.14f, 1.00f);
STYLE.Colors[(int) ImGuiCol.TitleBg] = new Vector4(0.09f, 0.12f, 0.14f, 0.65f);
STYLE.Colors[(int) ImGuiCol.TitleBgActive] = new Vector4(0.08f, 0.10f, 0.12f, 1.00f);
STYLE.Colors[(int) ImGuiCol.TitleBgCollapsed] = new Vector4(0.00f, 0.00f, 0.00f, 0.51f);
STYLE.Colors[(int) ImGuiCol.MenuBarBg] = new Vector4(0.15f, 0.18f, 0.22f, 1.00f);
STYLE.Colors[(int) ImGuiCol.ScrollbarBg] = new Vector4(0.02f, 0.02f, 0.02f, 0.39f);
STYLE.Colors[(int) ImGuiCol.ScrollbarGrab] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f);
STYLE.Colors[(int) ImGuiCol.ScrollbarGrabHovered] = new Vector4(0.18f, 0.22f, 0.25f, 1.00f);
STYLE.Colors[(int) ImGuiCol.ScrollbarGrabActive] = new Vector4(0.09f, 0.21f, 0.31f, 1.00f);
STYLE.Colors[(int) ImGuiCol.CheckMark] = new Vector4(0.28f, 0.56f, 1.00f, 1.00f);
STYLE.Colors[(int) ImGuiCol.SliderGrab] = new Vector4(0.28f, 0.56f, 1.00f, 1.00f);
STYLE.Colors[(int) ImGuiCol.SliderGrabActive] = new Vector4(0.37f, 0.61f, 1.00f, 1.00f);
STYLE.Colors[(int) ImGuiCol.Button] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f);
STYLE.Colors[(int) ImGuiCol.ButtonHovered] = new Vector4(0.28f, 0.56f, 1.00f, 1.00f);
STYLE.Colors[(int) ImGuiCol.ButtonActive] = new Vector4(0.06f, 0.53f, 0.98f, 1.00f);
STYLE.Colors[(int) ImGuiCol.Header] = new Vector4(0.20f, 0.25f, 0.29f, 0.55f);
STYLE.Colors[(int) ImGuiCol.HeaderHovered] = new Vector4(0.26f, 0.59f, 0.98f, 0.80f);
STYLE.Colors[(int) ImGuiCol.HeaderActive] = new Vector4(0.26f, 0.59f, 0.98f, 1.00f);
STYLE.Colors[(int) ImGuiCol.Separator] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f);
STYLE.Colors[(int) ImGuiCol.SeparatorHovered] = new Vector4(0.10f, 0.40f, 0.75f, 0.78f);
STYLE.Colors[(int) ImGuiCol.SeparatorActive] = new Vector4(0.10f, 0.40f, 0.75f, 1.00f);
STYLE.Colors[(int) ImGuiCol.ResizeGrip] = new Vector4(0.26f, 0.59f, 0.98f, 0.25f);
STYLE.Colors[(int) ImGuiCol.ResizeGripHovered] = new Vector4(0.26f, 0.59f, 0.98f, 0.67f);
STYLE.Colors[(int) ImGuiCol.ResizeGripActive] = new Vector4(0.26f, 0.59f, 0.98f, 0.95f);
STYLE.Colors[(int) ImGuiCol.Tab] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f);
STYLE.Colors[(int) ImGuiCol.TabHovered] = new Vector4(0.26f, 0.59f, 0.98f, 0.80f);
STYLE.Colors[(int) ImGuiCol.TabActive] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f);
STYLE.Colors[(int) ImGuiCol.TabUnfocused] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f);
STYLE.Colors[(int) ImGuiCol.TabUnfocusedActive] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f);
STYLE.Colors[(int) ImGuiCol.PlotLines] = new Vector4(0.61f, 0.61f, 0.61f, 1.00f);
STYLE.Colors[(int) ImGuiCol.PlotLinesHovered] = new Vector4(1.00f, 0.43f, 0.35f, 1.00f);
STYLE.Colors[(int) ImGuiCol.PlotHistogram] = new Vector4(0.90f, 0.70f, 0.00f, 1.00f);
STYLE.Colors[(int) ImGuiCol.PlotHistogramHovered] = new Vector4(1.00f, 0.60f, 0.00f, 1.00f);
STYLE.Colors[(int) ImGuiCol.TextSelectedBg] = new Vector4(0.26f, 0.59f, 0.98f, 0.35f);
STYLE.Colors[(int) ImGuiCol.DragDropTarget] = new Vector4(1.00f, 1.00f, 0.00f, 0.90f);
STYLE.Colors[(int) ImGuiCol.NavHighlight] = new Vector4(0.26f, 0.59f, 0.98f, 1.00f);
STYLE.Colors[(int) ImGuiCol.NavWindowingHighlight] = new Vector4(1.00f, 1.00f, 1.00f, 0.70f);
STYLE.Colors[(int) ImGuiCol.NavWindowingDimBg] = new Vector4(0.80f, 0.80f, 0.80f, 0.20f);
STYLE.Colors[(int) ImGuiCol.ModalWindowDimBg] = new Vector4(0.80f, 0.80f, 0.80f, 0.35f);
}
}
11 changes: 10 additions & 1 deletion FModel/FModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
<None Remove="Resources\shader.vert" />
<None Remove="Resources\grid.frag" />
<None Remove="Resources\grid.vert" />
<None Remove="Resources\skybox.frag" />
<None Remove="Resources\skybox.vert" />
</ItemGroup>

<ItemGroup>
Expand All @@ -110,6 +112,8 @@
<EmbeddedResource Include="Resources\shader.vert" />
<EmbeddedResource Include="Resources\grid.frag" />
<EmbeddedResource Include="Resources\grid.vert" />
<EmbeddedResource Include="Resources\skybox.frag" />
<EmbeddedResource Include="Resources\skybox.vert" />
</ItemGroup>

<ItemGroup>
Expand All @@ -132,7 +136,6 @@
<PackageReference Include="Silk.NET.Input" Version="2.16.0" />
<PackageReference Include="Silk.NET.OpenGL" Version="2.16.0" />
<PackageReference Include="Silk.NET.OpenGL.Extensions.ImGui" Version="2.16.0" />
<PackageReference Include="Silk.NET.Windowing" Version="2.16.0" />
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.0" />
<PackageReference Include="SkiaSharp.Svg" Version="1.60.0" />
</ItemGroup>
Expand Down Expand Up @@ -202,6 +205,12 @@
<Resource Include="Resources\go_to_directory.png" />
<Resource Include="Resources\approaching_storm_cubemap.dds" />
<Resource Include="Resources\npcleftside.png" />
<Resource Include="Resources\nx.png" />
<Resource Include="Resources\ny.png" />
<Resource Include="Resources\nz.png" />
<Resource Include="Resources\px.png" />
<Resource Include="Resources\py.png" />
<Resource Include="Resources\pz.png" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion FModel/Resources/grid.frag
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ vec4 grid(vec3 fragPos, float scale) {
float line = min(grid.x, grid.y);
float minimumz = min(derivative.y, 1) * 0.1;
float minimumx = min(derivative.x, 1) * 0.1;
vec4 color = vec4(0.149, 0.149, 0.188, 1.0 - min(line, 1.0));
vec4 color = vec4(0.102, 0.102, 0.129, 1.0 - min(line, 1.0));
if(abs(fragPos.x) < minimumx)
color.z = 1.0;
if(abs(fragPos.z) < minimumz)
Expand Down
Binary file added FModel/Resources/nx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added FModel/Resources/ny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added FModel/Resources/nz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added FModel/Resources/px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added FModel/Resources/py.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added FModel/Resources/pz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions FModel/Resources/skybox.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 330 core

in vec3 fPos;

uniform samplerCube cubemap;

out vec4 FragColor;

void main()
{
FragColor = texture(cubemap, fPos);
}
16 changes: 16 additions & 0 deletions FModel/Resources/skybox.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#version 330 core

layout (location = 0) in vec3 vPos;

uniform mat4 uView;
uniform mat4 uProjection;

out vec3 fPos;

void main()
{
fPos = vPos;
vec4 pos = uProjection * uView * vec4(vPos, 1.0);

gl_Position = pos.xyww;
}
8 changes: 4 additions & 4 deletions FModel/Views/Snooper/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public class Model : IDisposable

private Shader _shader;

public string Name;
public uint[] Indices;
public float[] Vertices;
public Section[] Sections;
public readonly string Name;
public readonly uint[] Indices;
public readonly float[] Vertices;
public readonly Section[] Sections;

public Model(string name, CBaseMeshLod lod, CMeshVertex[] vertices)
{
Expand Down
10 changes: 5 additions & 5 deletions FModel/Views/Snooper/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class Section : IDisposable
// private Texture _metallicMap;
private Texture _emissionMap;

public string Name;
public int Index;
public uint FacesCount;
public int FirstFaceIndex;
public CMaterialParams Parameters;
public readonly string Name;
public readonly int Index;
public readonly uint FacesCount;
public readonly int FirstFaceIndex;
public readonly CMaterialParams Parameters;

public Section(string name, int index, uint facesCount, int firstFaceIndex, CMeshSection section)
{
Expand Down
115 changes: 115 additions & 0 deletions FModel/Views/Snooper/Skybox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using Silk.NET.OpenGL;

namespace FModel.Views.Snooper;

public class Skybox : IDisposable
{
private uint _handle;
private GL _gl;

private BufferObject<uint> _ebo;
private BufferObject<float> _vbo;
private VertexArrayObject<float, uint> _vao;

private string[] _textures = { "nx", "ny", "nz", "px", "py", "pz" };

private Texture _cubeMap;
private Shader _shader;

public readonly uint[] Indices = { 0, 1, 3, 1, 2, 3 };
public readonly float[] Vertices = {
//X Y Z
-0.5f, -0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
-0.5f, 0.5f, -0.5f,
-0.5f, -0.5f, -0.5f,

-0.5f, -0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, -0.5f, 0.5f,

-0.5f, 0.5f, 0.5f,
-0.5f, 0.5f, -0.5f,
-0.5f, -0.5f, -0.5f,
-0.5f, -0.5f, -0.5f,
-0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,

0.5f, 0.5f, 0.5f,
0.5f, 0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
0.5f, -0.5f, 0.5f,
0.5f, 0.5f, 0.5f,

-0.5f, -0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
0.5f, -0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
-0.5f, -0.5f, 0.5f,
-0.5f, -0.5f, -0.5f,

-0.5f, 0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, 0.5f, -0.5f
};

public Skybox() {}

public void Setup(GL gl)
{
_gl = gl;

_handle = _gl.CreateProgram();

_cubeMap = new Texture(_gl, _textures);
_shader = new Shader(_gl, "skybox.vert", "skybox.frag");

_ebo = new BufferObject<uint>(_gl, Indices, BufferTargetARB.ElementArrayBuffer);
_vbo = new BufferObject<float>(_gl, Vertices, BufferTargetARB.ArrayBuffer);
_vao = new VertexArrayObject<float, uint>(_gl, _vbo, _ebo);

_vao.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 3, 0); // position
}

public void Bind(Camera camera)
{
_gl.DepthFunc(DepthFunction.Lequal);

_vao.Bind();

_cubeMap.Bind(TextureUnit.Texture0);
_shader.Use();

var view = camera.GetViewMatrix();
view.M41 = 0;
view.M42 = 0;
view.M43 = 0;
_shader.SetUniform("uView", view);
_shader.SetUniform("uProjection", camera.GetProjectionMatrix());

_shader.SetUniform("cubemap", 0);

_gl.DrawArrays(PrimitiveType.Triangles, 0, 36);

_gl.DepthFunc(DepthFunction.Less);
}

public void Dispose()
{
_ebo.Dispose();
_vbo.Dispose();
_vao.Dispose();
_shader.Dispose();
_gl.DeleteProgram(_handle);
}
}
Loading

0 comments on commit 0c5ede6

Please sign in to comment.