diff --git a/assets/shaders/opengl/default.shader.fs b/assets/shaders/default.shader.fs similarity index 62% rename from assets/shaders/opengl/default.shader.fs rename to assets/shaders/default.shader.fs index 404caae626..cbc700639b 100644 --- a/assets/shaders/opengl/default.shader.fs +++ b/assets/shaders/default.shader.fs @@ -1,54 +1,53 @@ @prism(type='fragment', name='Fast3D Fragment Shader', version='1.0.0', description='Ported shader to prism', author='Emill & Prism Team') -@{GLSL_VERSION} +#version 450 core -@if(core_opengl || opengles) -out vec4 vOutColor; +// layout(binding = {get_binding_index("samplerState", "Sampler", "")}) uniform sampler samplerState; + +layout(std140, binding = @{get_binding_index("frame_count", "Buffer", "ConstantBuffer")}) uniform FrameCount { + int frame_count; +}; +layout(std140, binding = @{get_binding_index("noise_scale", "Buffer", "ConstantBuffer")}) uniform NoiseScale { + float noise_scale; +}; + +@for(i in 0..2) + @if(o_textures[i]) layout(binding = @{get_binding_index("uTex" + to_string(i), "Texture", "Sampled")}) uniform texture2D uTex@{i}; + @if(o_textures[i]) layout(binding = @{get_binding_index("uTexSampl" + to_string(i), "Sampler", "uTex" + to_string(i))}) uniform sampler uTexSampl@{i}; + @if(o_masks[i]) layout(binding = @{get_binding_index("uTexMask" + to_string(i), "Texture", "Sampled")}) uniform texture2D uTexMask@{i}; + @if(o_masks[i]) layout(binding = @{get_binding_index("uTexMaskSampl" + to_string(i), "Sampler", "uTexMask" + to_string(i))}) uniform sampler uTexMaskSampl@{i}; + @if(o_blend[i]) layout(binding = @{get_binding_index("uTexBlend" + to_string(i), "Texture", "Sampled")}) uniform texture2D uTexBlend@{i}; + @if(o_blend[i]) layout(binding = @{get_binding_index("uTexBlendSampl" + to_string(i), "Sampler", "uTexBlend" + to_string(i))}) uniform sampler uTexBlendSampl@{i}; @end @for(i in 0..2) @if(o_textures[i]) - @{attr} vec2 vTexCoord@{i}; + layout(location = @{get_input_location()}) in vec2 vTexCoord@{i}; @for(j in 0..2) @if(o_clamp[i][j]) @if(j == 0) - @{attr} float vTexClampS@{i}; + layout(location = @{get_input_location()}) in float vTexClampS@{i}; @else - @{attr} float vTexClampT@{i}; + layout(location = @{get_input_location()}) in float vTexClampT@{i}; @end @end @end @end @end -@if(o_fog) @{attr} vec4 vFog; -@if(o_grayscale) @{attr} vec4 vGrayscaleColor; +@if(o_fog) layout(location = @{get_input_location()}) in vec4 vFog; +@if(o_grayscale) layout(location = @{get_input_location()}) in vec4 vGrayscaleColor; @for(i in 0..o_inputs) @if(o_alpha) - @{attr} vec4 vInput@{i + 1}; + layout(location = @{get_input_location()}) in vec4 vInput@{i + 1}; @else - @{attr} vec3 vInput@{i + 1}; + layout(location = @{get_input_location()}) in vec3 vInput@{i + 1}; @end @end -@if(o_textures[0]) uniform sampler2D uTex0; -@if(o_textures[1]) uniform sampler2D uTex1; - -@if(o_masks[0]) uniform sampler2D uTexMask0; -@if(o_masks[1]) uniform sampler2D uTexMask1; -@if(o_blend[0]) uniform sampler2D uTexBlend0; -@if(o_blend[1]) uniform sampler2D uTexBlend1; - -uniform int frame_count; -uniform float noise_scale; - -uniform int texture_width[2]; -uniform int texture_height[2]; -uniform int texture_filtering[2]; - -#define TEX_OFFSET(off) @{texture}(tex, texCoord - off / texSize) +#define TEX_OFFSET(off) texture(sampler2D(tex, sampl), texCoord - off / texSize) #define WRAP(x, low, high) mod((x)-(low), (high)-(low)) + (low) float random(in vec3 value) { @@ -63,7 +62,7 @@ vec4 fromLinear(vec4 linearRGB){ return vec4(mix(higher, lower, cutoff), linearRGB.a); } -vec4 filter3point(in sampler2D tex, in vec2 texCoord, in vec2 texSize) { +vec4 filter3point(in texture2D tex, in sampler sampl, in vec2 texCoord, in vec2 texSize) { vec2 offset = fract(texCoord*texSize - vec2(0.5)); offset -= step(1.0, offset.x + offset.y); vec4 c0 = TEX_OFFSET(offset); @@ -72,16 +71,16 @@ vec4 filter3point(in sampler2D tex, in vec2 texCoord, in vec2 texSize) { return c0 + abs(offset.x)*(c1-c0) + abs(offset.y)*(c2-c0); } -vec4 hookTexture2D(in int id, sampler2D tex, in vec2 uv, in vec2 texSize) { +vec4 hookTexture2D(in int id, in texture2D tex, in sampler sampl, in vec2 uv, in vec2 texSize) { @if(o_three_point_filtering) - if(texture_filtering[id] == @{FILTER_THREE_POINT}) { - return filter3point(tex, uv, texSize); - } + // if(texture_filtering[id] == @{FILTER_THREE_POINT}) { + return filter3point(tex, sampl, uv, texSize); + // } @end - return @{texture}(tex, uv); + return texture(sampler2D(tex, sampl), uv); } -#define TEX_SIZE(tex) vec2(texture_width[tex], texture_height[tex]) +layout(location = 0) out vec4 fragColor; void main() { @for(i in 0..2) @@ -89,7 +88,7 @@ void main() { @{s = o_clamp[i][0]} @{t = o_clamp[i][1]} - vec2 texSize@{i} = TEX_SIZE(@{i}); + vec2 texSize@{i} = textureSize(sampler2D(uTex@{i}, uTexSampl@{i}), 0); @if(!s && !t) vec2 vTexCoordAdj@{i} = vTexCoord@{i}; @@ -103,19 +102,15 @@ void main() { @end @end - vec4 texVal@{i} = hookTexture2D(@{i}, uTex@{i}, vTexCoordAdj@{i}, texSize@{i}); + vec4 texVal@{i} = hookTexture2D(@{i}, uTex@{i}, uTexSampl@{i}, vTexCoordAdj@{i}, texSize@{i}); @if(o_masks[i]) - @if(opengles) - vec2 maskSize@{i} = vec2(textureSize(uTexMask@{i}, 0)); - @else - vec2 maskSize@{i} = textureSize(uTexMask@{i}, 0); - @end + vec2 maskSize@{i} = textureSize(sampler2D(uTexMask@{i}, uTexMaskSampl@{i}), 0); - vec4 maskVal@{i} = hookTexture2D(@{i}, uTexMask@{i}, vTexCoordAdj@{i}, maskSize@{i}); + vec4 maskVal@{i} = hookTexture2D(@{i}, uTexMask@{i}, uTexMaskSampl@{i}, vTexCoordAdj@{i}, maskSize@{i}); @if(o_blend[i]) - vec4 blendVal@{i} = hookTexture2D(@{i}, uTexBlend@{i}, vTexCoordAdj@{i}, texSize@{i}); + vec4 blendVal@{i} = hookTexture2D(@{i}, uTexBlend@{i}, uTexBlendSampl@{i}, vTexCoordAdj@{i}, texSize@{i}); @else vec4 blendVal@{i} = vec4(0, 0, 0, 0); @end @@ -200,12 +195,12 @@ void main() { @if(o_invisible) texel.a = 0.0; @end - @{vOutColor} = texel; + fragColor= texel; @else - @{vOutColor} = vec4(texel, 1.0); + fragColor = vec4(texel, 1.0); @end @if(srgb_mode) - @{vOutColor} = fromLinear(@{vOutColor}); + fragColor = fromLinear(fragColor); @end } \ No newline at end of file diff --git a/assets/shaders/default.shader.vs b/assets/shaders/default.shader.vs new file mode 100644 index 0000000000..3a56717699 --- /dev/null +++ b/assets/shaders/default.shader.vs @@ -0,0 +1,78 @@ +@prism(type='fragment', name='Fast3D Fragment Shader', version='1.0.0', description='Ported shader to prism', author='Emill & Prism Team') + +#version 450 core + +// should stay position +layout(location = @{get_vs_input_location("position", "RGBA32Float")}) in vec4 position; + +@for(i in 0..2) + @if(o_textures[i]) + layout(location = @{get_vs_input_location("aTexCoord" + to_string(i), "RG32Float")}) in vec2 aTexCoord@{i}; + layout(location = @{get_output_location()}) out vec2 vTexCoord@{i}; + @for(j in 0..2) + @if(o_clamp[i][j]) + @if(j == 0) + layout(location = @{get_vs_input_location("aTexClampS" + to_string(i), "R32Float")}) in float aTexClampS@{i}; + layout(location = @{get_output_location()}) out float vTexClampS@{i}; + @else + layout(location = @{get_vs_input_location("aTexClampT" + to_string(i), "R32Float")}) in float aTexClampT@{i}; + layout(location = @{get_output_location()}) out float vTexClampT@{i}; + @end + @end + @end + @end +@end + +@if(o_fog) + layout(location = @{get_vs_input_location("aFog", "RGBA32Float")}) in vec4 aFog; + layout(location = @{get_output_location()}) out vec4 vFog; +@end + +@if(o_grayscale) + layout(location = @{get_vs_input_location("aGrayscaleColor", "RGBA32Float")}) in vec4 aGrayscaleColor; + layout(location = @{get_output_location()}) out vec4 vGrayscaleColor; +@end + +@for(i in 0..o_inputs) + @if(o_alpha) + layout(location = @{get_vs_input_location("aInput" + to_string(i+1), "RGBA32Float")}) in vec4 aInput@{i + 1}; + layout(location = @{get_output_location()}) out vec4 vInput@{i + 1}; + @else + layout(location = @{get_vs_input_location("aInput" + to_string(i+1), "RGB32Float")}) in vec3 aInput@{i + 1}; + layout(location = @{get_output_location()}) out vec3 vInput@{i + 1}; + @end +@end + +out gl_PerVertex { + vec4 gl_Position; +}; + +void main() { + @for(i in 0..2) + @if(o_textures[i]) + vTexCoord@{i} = aTexCoord@{i}; + @for(j in 0..2) + @if(o_clamp[i][j]) + @if(j == 0) + vTexClampS@{i} = aTexClampS@{i}; + @else + vTexClampT@{i} = aTexClampT@{i}; + @end + @end + @end + @end + @end + + @if(o_fog) + vFog = aFog; + @end + + @if(o_grayscale) + vGrayscaleColor = aGrayscaleColor; + @end + + @for(i in 0..o_inputs) + vInput@{i + 1} = aInput@{i + 1}; + @end + gl_Position = position; +} diff --git a/assets/shaders/directx/default.shader.hlsl b/assets/shaders/directx/default.shader.hlsl deleted file mode 100644 index 980becb8c9..0000000000 --- a/assets/shaders/directx/default.shader.hlsl +++ /dev/null @@ -1,332 +0,0 @@ -@prism(type='hlsl', name='Fast3D HLSL Shader', version='1.0.0', description='Ported shader to prism', author='Emill & Prism Team') - -@if(o_root_signature) - @if(o_textures[0]) - #define RS "RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | DENY_VERTEX_SHADER_ROOT_ACCESS), CBV(b0, visibility = SHADER_VISIBILITY_PIXEL), DescriptorTable(SRV(t0), visibility = SHADER_VISIBILITY_PIXEL), DescriptorTable(Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL)" - @end - @if(o_textures[1]) - #define RS "RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | DENY_VERTEX_SHADER_ROOT_ACCESS), CBV(b0, visibility = SHADER_VISIBILITY_PIXEL), DescriptorTable(SRV(t1), visibility = SHADER_VISIBILITY_PIXEL), DescriptorTable(Sampler(s1), visibility = SHADER_VISIBILITY_PIXEL)" - @end -@end - -struct PSInput { - float4 position : SV_POSITION; -@for(i in 0..2) - @if(o_textures[i]) - float2 uv@{i} : TEXCOORD@{i}; - @{update_floats(2)} - @for(j in 0..2) - @if(o_clamp[i][j]) - @if(j == 0) - float texClampS@{i} : TEXCLAMPS@{i}; - @else - float texClampT@{i} : TEXCLAMPT@{i}; - @end - @{update_floats(1)} - @end - @end - @end -@end - -@if(o_fog) -float4 fog : FOG; -@{update_floats(4)} -@end -@if(o_grayscale) -float4 grayscale : GRAYSCALE; -@{update_floats(4)} -@end - -@for(i in 0..o_inputs) - @if(o_alpha) - float4 input@{i + 1} : INPUT@{i}; - @{update_floats(4)} - @else - float3 input@{i + 1} : INPUT@{i}; - @{update_floats(3)} - @end -@end -}; - -@if(o_textures[0]) - Texture2D g_texture0 : register(t0); - SamplerState g_sampler0 : register(s0); -@end -@if(o_textures[1]) - Texture2D g_texture1 : register(t1); - SamplerState g_sampler1 : register(s1); -@end - -@if(o_masks[0]) Texture2D g_textureMask0 : register(t2); -@if(o_masks[1]) Texture2D g_textureMask1 : register(t3); - -@if(o_blend[0]) Texture2D g_textureBlend0 : register(t4); -@if(o_blend[1]) Texture2D g_textureBlend1 : register(t5); - -cbuffer PerFrameCB : register(b0) { - uint noise_frame; - float noise_scale; -} - -float random(in float3 value) { - float random = dot(value, float3(12.9898, 78.233, 37.719)); - return frac(sin(random) * 143758.5453); -} - -// 3 point texture filtering -// Original author: ArthurCarvalho -// Based on GLSL implementation by twinaphex, mupen64plus-libretro project. - -@if(o_three_point_filtering && o_textures[0] || o_textures[1]) -cbuffer PerDrawCB : register(b1) { - struct { - uint width; - uint height; - bool linear_filtering; - } textures[2]; -} - -#define TEX_OFFSET(tex, tSampler, texCoord, off, texSize) tex.Sample(tSampler, texCoord - off / texSize) - -float4 tex2D3PointFilter(in Texture2D tex, in SamplerState tSampler, in float2 texCoord, in float2 texSize) { - float2 offset = frac(texCoord * texSize - float2(0.5, 0.5)); - offset -= step(1.0, offset.x + offset.y); - float4 c0 = TEX_OFFSET(tex, tSampler, texCoord, offset, texSize); - float4 c1 = TEX_OFFSET(tex, tSampler, texCoord, float2(offset.x - sign(offset.x), offset.y), texSize); - float4 c2 = TEX_OFFSET(tex, tSampler, texCoord, float2(offset.x, offset.y - sign(offset.y)), texSize); - return c0 + abs(offset.x)*(c1-c0) + abs(offset.y)*(c2-c0); -} -@end - -PSInput VSMain( - float4 position : POSITION -@for(i in 0..2) - @if(o_textures[i]) - , float2 uv@{i} : TEXCOORD@{i} - @end - @for(j in 0..2) - @if(o_clamp[i][j]) - @if(j == 0) - , float texClampS@{i} : TEXCLAMPS@{i} - @else - , float texClampT@{i} : TEXCLAMPT@{i} - @end - @end - @end -@end -@if(o_fog) - , float4 fog : FOG -@end -@if(o_grayscale) - , float4 grayscale : GRAYSCALE -@end -@for(i in 0..o_inputs) - @if(o_alpha) - , float4 input@{i + 1} : INPUT@{i} - @else - , float3 input@{i + 1} : INPUT@{i} - @end -@end -) { - PSInput result; - result.position = position; - @for(i in 0..2) - @if(o_textures[i]) - result.uv@{i} = uv@{i}; - @for(j in 0..2) - @if(o_clamp[i][j]) - @if(j == 0) - result.texClampS@{i} = texClampS@{i}; - @else - result.texClampT@{i} = texClampT@{i}; - @end - @end - @end - @end - @end - - @if(o_fog) - result.fog = fog; - @end - - @if(o_grayscale) - result.grayscale = grayscale; - @end - - @for(i in 0..o_inputs) - @if(o_alpha) - result.input@{i + 1} = input@{i + 1}; - @else - result.input@{i + 1} = float4(input@{i + 1}, 1.0); - @end - @end - - return result; -} - -@if(o_root_signature) - [RootSignature(RS)] -@end - -@if(srgb_mode) - float4 fromLinear(float4 linearRGB){ - bool3 cutoff = linearRGB.rgb < float3(0.0031308, 0.0031308, 0.0031308); - float3 higher = 1.055 * pow(linearRGB.rgb, float3(1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4)) - float3(0.055, 0.055, 0.055); - float3 lower = linearRGB.rgb * float3(12.92, 12.92, 12.92); - return float4(lerp(higher, lower, cutoff), linearRGB.a); - } -@end - -#define MOD(x, y) ((x) - (y) * floor((x)/(y))) -#define WRAP(x, low, high) MOD((x)-(low), (high)-(low)) + (low) - -float4 PSMain(PSInput input, float4 screenSpace : SV_Position) : SV_TARGET { - @for(i in 0..2) - @if(o_textures[i]) - float2 tc@{i} = input.uv@{i}; - @{s = o_clamp[i][0]} - @{t = o_clamp[i][1]} - @if(s || t) - int2 texSize@{i}; - g_texture@{i}.GetDimensions(texSize@{i}.x, texSize@{i}.y); - @if(s && t) - tc@{i} = clamp(tc@{i}, 0.5 / texSize@{i}, float2(input.texClampS@{i}, input.texClampT@{i})); - @elseif(s) - tc@{i} = float2(clamp(tc@{i}.x, 0.5 / texSize@{i}.x, input.texClampS@{i}), tc@{i}.y); - @else - tc@{i} = float2(tc@{i}.x, clamp(tc@{i}.y, 0.5 / texSize@{i}.y, input.texClampT@{i})); - @end - @end - - @if(o_three_point_filtering) - float4 texVal@{i}; - if (textures[@{i}].linear_filtering) { - @if(o_masks[i]) - texVal@{i} = tex2D3PointFilter(g_texture@{i}, g_sampler@{i}, tc@{i}, float2(textures[@{i}].width, textures[@{i}].height)); - float2 maskSize@{i}; - g_textureMask@{i}.GetDimensions(maskSize@{i}.x, maskSize@{i}.y); - float4 maskVal@{i} = tex2D3PointFilter(g_textureMask@{i}, g_sampler@{i}, tc@{i}, maskSize@{i}); - @if(o_blend[i]) - float4 blendVal@{i} = tex2D3PointFilter(g_textureBlend@{i}, g_sampler@{i}, tc@{i}, float2(textures[@{i}].width, textures[@{i}].height)); - @else - float4 blendVal@{i} = float4(0, 0, 0, 0); - @end - - texVal@{i} = lerp(texVal@{i}, blendVal@{i}, maskVal@{i}.a); - @else - texVal@{i} = tex2D3PointFilter(g_texture@{i}, g_sampler@{i}, tc@{i}, float2(textures[@{i}].width, textures[@{i}].height)); - @end - } else { - texVal@{i} = g_texture@{i}.Sample(g_sampler@{i}, tc@{i}); - @if(o_masks[i]) - @if(o_blend[i]) - float4 blendVal@{i} = g_textureBlend@{i}.Sample(g_sampler@{i}, tc@{i}); - @else - float4 blendVal@{i} = float4(0, 0, 0, 0); - @end - texVal@{i} = lerp(texVal@{i}, blendVal@{i}, g_textureMask@{i}.Sample(g_sampler@{i}, tc@{i}).a); - @end - } - @else - float4 texVal@{i} = g_texture@{i}.Sample(g_sampler@{i}, tc@{i}); - @if(o_masks[i]) - @if(o_blend[i]) - float4 blendVal@{i} = g_textureBlend@{i}.Sample(g_sampler@{i}, tc@{i}); - @else - float4 blendVal@{i} = float4(0, 0, 0, 0); - @end - texVal@{i} = lerp(texVal@{i}, blendVal@{i}, g_textureMask@{i}.Sample(g_sampler@{i}, tc@{i}).a); - @end - @end - @end - @end - - @if(o_alpha) - float4 texel; - @else - float3 texel; - @end - - @if(o_2cyc) - @{f_range = 2} - @else - @{f_range = 1} - @end - - @for(c in 0..f_range) - @if(c == 1) - @if(o_alpha) - @if(o_c[c][1][2] == SHADER_COMBINED) - texel.a = WRAP(texel.a, -1.01, 1.01); - @else - texel.a = WRAP(texel.a, -0.51, 1.51); - @end - @end - - @if(o_c[c][0][2] == SHADER_COMBINED) - texel.rgb = WRAP(texel.rgb, -1.01, 1.01); - @else - texel.rgb = WRAP(texel.rgb, -0.51, 1.51); - @end - @end - - @if(!o_color_alpha_same[c] && o_alpha) - texel = float4(@{ - append_formula(o_c[c], o_do_single[c][0], - o_do_multiply[c][0], o_do_mix[c][0], false, false, true, c == 0) - }, @{append_formula(o_c[c], o_do_single[c][1], - o_do_multiply[c][1], o_do_mix[c][1], true, true, true, c == 0) - }); - @else - texel = @{append_formula(o_c[c], o_do_single[c][0], - o_do_multiply[c][0], o_do_mix[c][0], o_alpha, false, - o_alpha, c == 0)}; - @end - @end - - @if(o_texture_edge && o_alpha) - if (texel.a > 0.19) texel.a = 1.0; else discard; - @end - - texel = WRAP(texel, -0.51, 1.51); - texel = clamp(texel, 0.0, 1.0); - // TODO discard if alpha is 0? - @if(o_fog) - @if(o_alpha) - texel = float4(lerp(texel.rgb, input.fog.rgb, input.fog.a), texel.a); - @else - texel = lerp(texel, input.fog.rgb, input.fog.a); - @end - @end - - @if(o_grayscale) - float intensity = (texel.r + texel.g + texel.b) / 3.0; - float3 new_texel = input.grayscale.rgb * intensity; - texel.rgb = lerp(texel.rgb, new_texel, input.grayscale.a); - @end - - @if(o_alpha && o_noise) - float2 coords = screenSpace.xy * noise_scale; - texel.a *= round(saturate(random(float3(floor(coords), noise_frame)) + texel.a - 0.5)); - @end - - @if(o_alpha) - @if(o_alpha_threshold) - if (texel.a < 8.0 / 256.0) discard; - @end - @if(o_invisible) - texel.a = 0.0; - @end - @if(srgb_mode) - return fromLinear(texel); - @else - return texel; - @end - @else - @if(srgb_mode) - return fromLinear(float4(texel, 1.0)); - @else - return float4(texel, 1.0); - @end - @end -} diff --git a/assets/shaders/metal/default.shader.metal b/assets/shaders/metal/default.shader.metal deleted file mode 100644 index a771ba10cc..0000000000 --- a/assets/shaders/metal/default.shader.metal +++ /dev/null @@ -1,284 +0,0 @@ -@prism(type='metal', name='Fast3D Metal Shader', version='1.0.0', description='Ported shader to prism', author='Emill & Prism Team') - -#include -using namespace metal; - -// BEGIN VERTEX SHADER -struct FrameUniforms { - int frameCount; - float noiseScale; -}; - -struct Vertex { - float4 position [[attribute(@{get_vertex_index()})]]; - @{update_floats(4)} - @for(i in 0..2) - @if(o_textures[i]) - float2 texCoord@{i} [[attribute(@{get_vertex_index()})]]; - @{update_floats(2)} - @for(j in 0..2) - @if(o_clamp[i][j]) - @if(j == 0) - float texClampS@{i} [[attribute(@{get_vertex_index()})]]; - @else - float texClampT@{i} [[attribute(@{get_vertex_index()})]]; - @end - @{update_floats(1)} - @end - @end - @end - @end - @if(o_fog) - float4 fog [[attribute(@{get_vertex_index()})]]; - @{update_floats(4)} - @end - @if(o_grayscale) - float4 grayscale [[attribute(@{get_vertex_index()})]]; - @{update_floats(4)} - @end - @for(i in 0..o_inputs) - @if(o_alpha) - float4 input@{i + 1} [[attribute(@{get_vertex_index()})]]; - @{update_floats(4)} - @else - float3 input@{i + 1} [[attribute(@{get_vertex_index()})]]; - @{update_floats(3)} - @end - @end -}; - -struct ProjectedVertex { - @for(i in 0..2) - @if(o_textures[i]) - float2 texCoord@{i}; - @for(j in 0..2) - @if(o_clamp[i][j]) - @if(j == 0) - float texClampS@{i}; - @else - float texClampT@{i}; - @end - @end - @end - @end - @end - @if(o_fog) - float4 fog; - @end - @if(o_grayscale) - float4 grayscale; - @end - @for(i in 0..o_inputs) - @if(o_alpha) - float4 input@{i + 1}; - @else - float3 input@{i + 1}; - @end - @end - float4 position [[position]]; -}; - -vertex ProjectedVertex vertexShader(Vertex in [[stage_in]]) { - ProjectedVertex out; - @for(i in 0..2) - @if(o_textures[i]) - out.texCoord@{i} = in.texCoord@{i}; - @for(j in 0..2) - @if(o_clamp[i][j]) - @if(j == 0) - out.texClampS@{i} = in.texClampS@{i}; - @else - out.texClampT@{i} = in.texClampT@{i}; - @end - @end - @end - @end - @end - @if(o_fog) - out.fog = in.fog; - @end - @if(o_grayscale) - out.grayscale = in.grayscale; - @end - @for(i in 0..o_inputs) - out.input@{i + 1} = in.input@{i + 1}; - @end - out.position = in.position; - return out; -} -// END - BEGIN FRAGMENT SHADER - -float mod(float x, float y) { - return float(x - y * floor(x / y)); -} - -float3 mod(float3 a, float3 b) { - return float3(a.x - b.x * floor(a.x / b.x), a.y - b.y * floor(a.y / b.y), a.z - b.z * floor(a.z / b.z)); -} - -float4 mod(float4 a, float4 b) { - return float4(a.x - b.x * floor(a.x / b.x), a.y - b.y * floor(a.y / b.y), a.z - b.z * floor(a.z / b.z), a.w - b.w * floor(a.w / b.w)); -} - -#define WRAP(x, low, high) mod((x)-(low), (high)-(low)) + (low) -#define TEX_OFFSET(tex, texSmplr, texCoord, off, texSize) tex.sample(texSmplr, texCoord - off / texSize) - -@if(o_three_point_filtering) - float4 filter3point(thread const texture2d tex, thread const sampler texSmplr, thread const float2& texCoord, thread const float2& texSize) { - float2 offset = fract((texCoord * texSize) - float2(0.5)); - offset -= float2(step(1.0, offset.x + offset.y)); - float4 c0 = TEX_OFFSET(tex, texSmplr, texCoord, offset, texSize); - float4 c1 = TEX_OFFSET(tex, texSmplr, texCoord, float2(offset.x - sign(offset.x), offset.y), texSize); - float4 c2 = TEX_OFFSET(tex, texSmplr, texCoord, float2(offset.x, offset.y - sign(offset.y)), texSize); - return c0 + abs(offset.x) * (c1 - c0) + abs(offset.y) * (c2 - c0); - } - - float4 hookTexture2D(thread const texture2d tex, thread const sampler texSmplr, thread const float2& uv, thread const float2& texSize) { - return filter3point(tex, texSmplr, uv, texSize); - } -@else - float4 hookTexture2D(thread const texture2d tex, thread const sampler texSmplr, thread const float2& uv, thread const float2& texSize) { - return tex.sample(texSmplr, uv); - } -@end - -float random(float3 value) { - float random = dot(sin(value), float3(12.9898, 78.233, 37.719)); - return fract(sin(random) * 143758.5453); -} - -fragment float4 fragmentShader(ProjectedVertex in [[stage_in]], constant FrameUniforms &frameUniforms [[buffer(0)]] -@if(o_textures[0]) - , texture2d uTex0 [[texture(0)]], sampler uTex0Smplr [[sampler(0)]] -@end -@if(o_textures[1]) - , texture2d uTex1 [[texture(1)]], sampler uTex1Smplr [[sampler(1)]] -@end -@if(o_masks[0]) - , texture2d uTexMask0 [[texture(2)]] -@end -@if(o_masks[1]) - , texture2d uTexMask1 [[texture(3)]] -@end -@if(o_blend[0]) - , texture2d uTexBlend0 [[texture(4)]] -@end -@if(o_blend[1]) - , texture2d uTexBlend1 [[texture(5)]] -@end -) { - @for(i in 0..2) - @if(o_textures[i]) - @{s = o_clamp[i][0]} - @{t = o_clamp[i][1]} - float2 texSize@{i} = float2(uTex@{i}.get_width(), uTex@{i}.get_height()); - @if(!s && !t) - float2 vTexCoordAdj@{i} = in.texCoord@{i}; - @else - @if(s && t) - float2 vTexCoordAdj@{i} = fast::clamp(in.texCoord@{i}, float2(0.5) / texSize@{i}, float2(in.texClampS@{i}, in.texClampT@{i})); - @elseif(s) - float2 vTexCoordAdj@{i} = float2(fast::clamp(in.texCoord@{i}.x, 0.5 / texSize@{i}.x, in.texClampS@{i}), in.texCoord@{i}.y); - @else - float2 vTexCoordAdj@{i} = float2(in.texCoord@{i}.x, fast::clamp(in.texCoord@{i}.y, 0.5 / texSize@{i}.y, in.texClampT@{i})); - @end - @end - - float4 texVal@{i} = hookTexture2D(uTex@{i}, uTex@{i}Smplr, vTexCoordAdj@{i}, texSize@{i}); - - @if(o_masks[i]) - float2 maskSize@{i} = float2(uTexMask@{i}.get_width(), uTexMask@{i}.get_height()); - float4 maskVal@{i} = hookTexture2D(uTexMask@{i}, uTex@{i}Smplr, vTexCoordAdj@{i}, maskSize@{i}); - @if(o_blend[i]) - float4 blendVal@{i} = hookTexture2D(uTexBlend@{i}, uTex@{i}Smplr, vTexCoordAdj@{i}, texSize@{i}); - @else - float4 blendVal@{i} = float4(0, 0, 0, 0); - @end - - texVal@{i} = mix(texVal@{i}, blendVal@{i}, maskVal@{i}.w); - @end - @end - @end - - @if(o_alpha) - float4 texel; - @else - float3 texel; - @end - - @if(o_2cyc) - @{f_range = 2} - @else - @{f_range = 1} - @end - - @for(c in 0..f_range) - @if(c == 1) - @if(o_alpha) - @if(o_c[c][1][2] == SHADER_COMBINED) - texel.w = WRAP(texel.w, -1.01, 1.01); - @else - texel.w = WRAP(texel.w, -0.51, 1.51); - @end - @end - - @if(o_c[c][0][2] == SHADER_COMBINED) - texel.xyz = WRAP(texel.xyz, -1.01, 1.01); - @else - texel.xyz = WRAP(texel.xyz, -0.51, 1.51); - @end - @end - - @if(!o_color_alpha_same[c] && o_alpha) - texel = float4(@{ - append_formula(o_c[c], o_do_single[c][0], - o_do_multiply[c][0], o_do_mix[c][0], false, false, true, c == 0) - }, @{append_formula(o_c[c], o_do_single[c][1], - o_do_multiply[c][1], o_do_mix[c][1], true, true, true, c == 0) - }); - @else - texel = @{append_formula(o_c[c], o_do_single[c][0], - o_do_multiply[c][0], o_do_mix[c][0], o_alpha, false, - o_alpha, c == 0)}; - @end - @end - - @if(o_texture_edge && o_alpha) - if (texel.w > 0.19) texel.w = 1.0; else discard_fragment(); - @end - - texel = WRAP(texel, -0.51, 1.51); - texel = clamp(texel, 0.0, 1.0); - // TODO discard if alpha is 0? - - @if(o_fog) - @if(o_alpha) - texel = float4(mix(texel.xyz, in.fog.xyz, in.fog.w), texel.w); - @else - texel = mix(texel, in.fog.xyz, in.fog.w); - @end - @end - - @if(o_grayscale) - float intensity = (texel.x + texel.y + texel.z) / 3.0; - float3 new_texel = in.grayscale.xyz * intensity; - texel.xyz = mix(texel.xyz, new_texel, in.grayscale.w); - @end - - @if(o_alpha && o_noise) - float2 coords = screenSpace.xy * noise_scale; - texel.w *= round(saturate(random(float3(floor(coords), noise_frame)) + texel.w - 0.5)); - @end - - @if(o_alpha) - @if(o_alpha_threshold) - if (texel.w < 8.0 / 256.0) discard_fragment(); - @end - @if(o_invisible) - texel.w = 0.0; - @end - return texel; - @else - return float4(texel, 1.0); - @end -} \ No newline at end of file diff --git a/assets/shaders/opengl/default.shader.vs b/assets/shaders/opengl/default.shader.vs deleted file mode 100644 index cf0f62765a..0000000000 --- a/assets/shaders/opengl/default.shader.vs +++ /dev/null @@ -1,79 +0,0 @@ -@prism(type='fragment', name='Fast3D Fragment Shader', version='1.0.0', description='Ported shader to prism', author='Emill & Prism Team') - -@{GLSL_VERSION} - -@{attr} vec4 aVtxPos; - -@for(i in 0..2) - @if(o_textures[i]) - @{attr} vec2 aTexCoord@{i}; - @{out} vec2 vTexCoord@{i}; - @{update_floats(2)} - @for(j in 0..2) - @if(o_clamp[i][j]) - @if(j == 0) - @{attr} float aTexClampS@{i}; - @{out} float vTexClampS@{i}; - @else - @{attr} float aTexClampT@{i}; - @{out} float vTexClampT@{i}; - @end - @{update_floats(1)} - @end - @end - @end -@end - -@if(o_fog) - @{attr} vec4 aFog; - @{out} vec4 vFog; - @{update_floats(4)} -@end - -@if(o_grayscale) - @{attr} vec4 aGrayscaleColor; - @{out} vec4 vGrayscaleColor; - @{update_floats(4)} -@end - -@for(i in 0..o_inputs) - @if(o_alpha) - @{attr} vec4 aInput@{i + 1}; - @{out} vec4 vInput@{i + 1}; - @{update_floats(4)} - @else - @{attr} vec3 aInput@{i + 1}; - @{out} vec3 vInput@{i + 1}; - @{update_floats(3)} - @end -@end - -void main() { - @for(i in 0..2) - @if(o_textures[i]) - vTexCoord@{i} = aTexCoord@{i}; - @for(j in 0..2) - @if(o_clamp[i][j]) - @if(j == 0) - vTexClampS@{i} = aTexClampS@{i}; - @else - vTexClampT@{i} = aTexClampT@{i}; - @end - @end - @end - @end - @end - @if(o_fog) - vFog = aFog; - @end - @if(o_grayscale) - vGrayscaleColor = aGrayscaleColor; - @end - @for(i in 0..o_inputs) - vInput@{i + 1} = aInput@{i + 1}; - @end - gl_Position = aVtxPos; - @if(opengles) - gl_Position.z *= 0.3f; - @end -} \ No newline at end of file diff --git a/libultraship b/libultraship index 5e33d3e7cd..c0096fe449 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit 5e33d3e7cd0396f847923cd6c471eaf324e90351 +Subproject commit c0096fe44978ad0b308d5170797b075db4b2268f diff --git a/src/enhancements/freecam/freecam.cpp b/src/enhancements/freecam/freecam.cpp index 2ada24895f..9066222978 100644 --- a/src/enhancements/freecam/freecam.cpp +++ b/src/enhancements/freecam/freecam.cpp @@ -181,13 +181,13 @@ bool FreecamKeyDown(int virtualKey) { static bool prevKeyState[256] = { false }; // Store previous key states bool isDownNow = false; - if (wnd->GetWindowBackend() == Ship::WindowBackend::FAST3D_SDL_OPENGL) { + if (true) {// (wnd->GetWindowBackend() == Ship::WindowBackend::FAST3D_SDL_OPENGL) { // Use SDL to check key states const uint8_t* keystate = SDL_GetKeyboardState(NULL); isDownNow = keystate[virtualKey] != 0; } #ifdef _WIN32 - else if (wnd->GetWindowBackend() == Ship::WindowBackend::FAST3D_DXGI_DX11) { + else if (false) {// (wnd->GetWindowBackend() == Ship::WindowBackend::FAST3D_DXGI_DX11) { // Use Windows GetKeyState for DirectX SHORT keyState = GetKeyState(virtualKey); isDownNow = (keyState & 0x8000) != 0; @@ -263,7 +263,7 @@ void freecam_keyboard_manager(Camera* camera, Vec3f forwardVector) { } // Keyboard and mouse DX #ifdef _WIN32 - else if (wnd->GetWindowBackend() == Ship::WindowBackend::FAST3D_DXGI_DX11) { + else if (false) { // (wnd->GetWindowBackend() == Ship::WindowBackend::FAST3D_DXGI_DX11) { if (FreecamKeyDown('F')) { fTargetPlayer = !fTargetPlayer; } @@ -298,7 +298,7 @@ void freecam_keyboard_manager(Camera* camera, Vec3f forwardVector) { // Keyboard/mouse OpenGL/SDL } #endif - else if (wnd->GetWindowBackend() == Ship::WindowBackend::FAST3D_SDL_OPENGL) { + else if (true) { // (wnd->GetWindowBackend() == Ship::WindowBackend::FAST3D_SDL_OPENGL) { const uint8_t* keystate = SDL_GetKeyboardState(NULL); if (FreecamKeyDown(SDL_SCANCODE_F)) { fTargetPlayer = !fTargetPlayer; diff --git a/src/port/SpaghettiGui.cpp b/src/port/SpaghettiGui.cpp index 6c703456d4..33ff92674c 100644 --- a/src/port/SpaghettiGui.cpp +++ b/src/port/SpaghettiGui.cpp @@ -12,7 +12,6 @@ #include #include -#include "graphic/Fast3D/backends/gfx_metal.h" #include #include #else diff --git a/src/port/ui/Menu.cpp b/src/port/ui/Menu.cpp index 9c68d2786d..9f97d42d1c 100644 --- a/src/port/ui/Menu.cpp +++ b/src/port/ui/Menu.cpp @@ -90,15 +90,15 @@ void Menu::RemoveSidebarSearch() { } void Menu::UpdateWindowBackendObjects() { - Ship::WindowBackend runningWindowBackend = Ship::Context::GetInstance()->GetWindow()->GetWindowBackend(); + auto runningWindowBackend = Ship::Context::GetInstance()->GetWindow()->GetRendererID(); int32_t configWindowBackendId = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Backend.Id", -1); - if (Ship::Context::GetInstance()->GetWindow()->IsAvailableWindowBackend(configWindowBackendId)) { - configWindowBackend = static_cast(configWindowBackendId); + if (Ship::Context::GetInstance()->GetWindow()->IsAvailableRenderer(configWindowBackendId)) { + configWindowBackend = configWindowBackendId; } else { configWindowBackend = runningWindowBackend; } - availableWindowBackends = Ship::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends(); + availableWindowBackends = Ship::Context::GetInstance()->GetWindow()->GetAvailableRenderers(); for (auto& backend : *availableWindowBackends) { availableWindowBackendsMap[backend] = windowBackendsMap.at(backend); } diff --git a/src/port/ui/Menu.h b/src/port/ui/Menu.h index 6efd056ca7..65188c1685 100644 --- a/src/port/ui/Menu.h +++ b/src/port/ui/Menu.h @@ -44,9 +44,9 @@ class Menu : public GuiWindow { ImGuiTextFilter menuSearch; uint8_t searchSidebarIndex; UIWidgets::Colors defaultThemeIndex; - std::shared_ptr> availableWindowBackends; - std::unordered_map availableWindowBackendsMap; - Ship::WindowBackend configWindowBackend; + std::shared_ptr> availableWindowBackends; + std::unordered_map availableWindowBackendsMap; + int configWindowBackend; std::unordered_map disabledMap; std::vector disabledVector; diff --git a/src/port/ui/MenuTypes.h b/src/port/ui/MenuTypes.h index 653c6955d3..4bd26e6d40 100644 --- a/src/port/ui/MenuTypes.h +++ b/src/port/ui/MenuTypes.h @@ -259,10 +259,17 @@ static const std::unordered_map audioBackendsMa { Ship::AudioBackend::SDL, "SDL" }, }; -static const std::unordered_map windowBackendsMap = { - { Ship::WindowBackend::FAST3D_DXGI_DX11, "DirectX" }, - { Ship::WindowBackend::FAST3D_SDL_OPENGL, "OpenGL" }, - { Ship::WindowBackend::FAST3D_SDL_METAL, "Metal" }, +static const std::unordered_map windowBackendsMap = { + { LLGL::RendererID::OpenGL, "OpenGL" }, + { LLGL::RendererID::OpenGLES, "OpenGL ES" }, + { LLGL::RendererID::WebGL, "WebGL" }, + { LLGL::RendererID::WebGPU, "WebGPU" }, + { LLGL::RendererID::Direct3D9, "Direct3D 9" }, + { LLGL::RendererID::Direct3D10, "Direct3D 10" }, + { LLGL::RendererID::Direct3D11, "Direct3D 11" }, + { LLGL::RendererID::Direct3D12, "Direct3D 12" }, + { LLGL::RendererID::Vulkan, "Vulkan" }, + { LLGL::RendererID::Metal, "Metal" }, }; struct MenuInit { diff --git a/src/port/ui/PortMenu.cpp b/src/port/ui/PortMenu.cpp index 740c605315..4f4d6f13e3 100644 --- a/src/port/ui/PortMenu.cpp +++ b/src/port/ui/PortMenu.cpp @@ -194,7 +194,7 @@ void PortMenu::AddSettings() { // Graphics Settings static int32_t maxFps; const char* tooltip = ""; - if (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == Ship::WindowBackend::FAST3D_DXGI_DX11) { + if (false) { // (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == Ship::WindowBackend::FAST3D_DXGI_DX11) { maxFps = 360; tooltip = "Uses Matrix Interpolation to create extra frames, resulting in smoother graphics. This is " "purely visual and does not impact game logic, execution of glitches etc.\n\nA higher target " @@ -250,6 +250,20 @@ void PortMenu::AddSettings() { .DefaultValue(1)); #endif + AddWidget(path, "Anisotropic Filtering (AF): %d", WIDGET_CVAR_SLIDER_INT) + .CVar(CVAR_ANISOTROPIC_FILTERING) + .Callback([](WidgetInfo& info) { + Ship::Context::GetInstance()->GetWindow()->SetAnisotropicFilteringLevel(CVarGetInteger(CVAR_ANISOTROPIC_FILTERING, 1)); + }) + .Options( + IntSliderOptions() + .Tooltip("Activates Anisotropic Filtering (AF) from 1x up to 16x, to improve the quality of " + "textures at oblique viewing angles.\n" + "Higher sample count will result in sharper textures at angles, but may reduce performance.") + .Min(1) + .Max(16) + .DefaultValue(1)); + AddWidget(path, "Current FPS: %d", WIDGET_CVAR_SLIDER_INT) .CVar("gInterpolationFPS") .Callback([](WidgetInfo& info) { @@ -537,14 +551,16 @@ void PortMenu::InitElement() { "Multi-viewports not supported" } }, { DISABLE_FOR_NOT_DIRECTX, { [](disabledInfo& info) -> bool { - return Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() != - Ship::WindowBackend::FAST3D_DXGI_DX11; + return true; + // return Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() != + // Ship::WindowBackend::FAST3D_DXGI_DX11; }, "Available Only on DirectX" } }, { DISABLE_FOR_DIRECTX, { [](disabledInfo& info) -> bool { - return Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == - Ship::WindowBackend::FAST3D_DXGI_DX11; + return false; + // return Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == + // Ship::WindowBackend::FAST3D_DXGI_DX11; }, "Not Available on DirectX" } }, { DISABLE_FOR_MATCH_REFRESH_RATE_ON, diff --git a/torch b/torch index 5773373b36..bc2736adb1 160000 --- a/torch +++ b/torch @@ -1 +1 @@ -Subproject commit 5773373b3620e4a6bc6c92fdc4690d66741c086d +Subproject commit bc2736adb1b3b3fc7e110cb3a518a7bbe8af65d8