Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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);
Expand All @@ -72,24 +71,24 @@ 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)
@if(o_textures[i])
@{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};
Expand All @@ -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
Expand Down Expand Up @@ -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
}
78 changes: 78 additions & 0 deletions assets/shaders/default.shader.vs
Original file line number Diff line number Diff line change
@@ -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;
}
Loading