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
25 changes: 25 additions & 0 deletions Game.Assets/hl2/shaders/screenspaceeffect_gl460.vs
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
#version 460
// STATIC: "VERTEXCOLOR" "0..1"
// STATIC: "TRANSFORMVERTS" "0..1"

layout(location = 0) in vec3 v_Position;
layout(location = 2) in vec4 v_Color;
layout(location = 10) in vec2 v_TexCoord;

layout(std140, binding = 0) uniform source_matrices {
mat4 viewMatrix;
mat4 projectionMatrix;
mat4 modelMatrix;
};

out vec2 vs_BaseTexCoord;
out vec4 vs_TexCoord0;
out vec4 vs_TexCoord1;
out vec4 vs_TexCoord2;
out vec4 vs_Color0;

void main()
{
#if TRANSFORMVERTS
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(v_Position, 1.0);
#else
gl_Position = vec4(v_Position, 1.0);
#endif
vs_BaseTexCoord = vec2(v_TexCoord.x, 1.0 - v_TexCoord.y);
vs_TexCoord0 = vec4(vs_BaseTexCoord, 0.0, 1.0);
vs_TexCoord1 = vec4(0.0, 0.0, 0.0, 1.0);
vs_TexCoord2 = vs_TexCoord0;
#if VERTEXCOLOR
vs_Color0 = v_Color;
#else
vs_Color0 = vec4(1.0);
#endif
}
40 changes: 32 additions & 8 deletions Source.ShaderAPI.Gl46/ShaderSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,18 +467,42 @@ private void ProcessSource(StringBuilder sb, string source, int fileIndex, int s
}
}

private unsafe uint CompileShader(int glType, ReadOnlySpan<char> name, ReadOnlySpan<char> defines, string typeName) {
using IFileHandle? handle = FileSystem.Open($"shaders/{name}", FileOpenOptions.Read, "game");
private byte[]? LoadVcs(ReadOnlySpan<char> name) {
int ext = name.LastIndexOf("_gl");
if (ext < 0)
return null;

using IFileHandle? handle = FileSystem.Open($"shaders/fxc/{name[..ext]}.vcs", FileOpenOptions.Read, "game");
if (handle == null)
return 0;
return null;

Span<byte> source = stackalloc byte[(int)handle.Stream.Length];
handle.Stream.Read(source);
byte[] vcs = new byte[handle.Stream.Length];
handle.Stream.ReadExactly(vcs);
string? source = VcsTranslator.Load(vcs);
if (source == null) {
Warning($"WARNING: Failed to translate shader shaders/fxc/{name[..ext]}.vcs\n");
return null;
}
return Encoding.ASCII.GetBytes(source);
}

private unsafe uint CompileShader(int glType, ReadOnlySpan<char> name, ReadOnlySpan<char> defines, string typeName) {
using IFileHandle? handle = FileSystem.Open($"shaders/{name}", FileOpenOptions.Read, "game");
List<string> sourceFiles = [];
byte[]? built = BuildShaderSource(source, defines, new string(name), sourceFiles);
if (built == null)
return 0;
byte[]? built;
if (handle == null) {
if ((built = LoadVcs(name)) == null)
return 0;
sourceFiles.Add(new(name));
}
else {
Span<byte> source = stackalloc byte[(int)handle.Stream.Length];
handle.Stream.Read(source);

built = BuildShaderSource(source, defines, new string(name), sourceFiles);
if (built == null)
return 0;
}

uint pShader = glCreateShader(glType);
int len = built.Length;
Expand Down
Loading
Loading