Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shaders fail to load on any update after 1.8.0-beta.4 #2576

Open
BronsonCarder opened this issue Dec 23, 2024 · 4 comments
Open

Shaders fail to load on any update after 1.8.0-beta.4 #2576

BronsonCarder opened this issue Dec 23, 2024 · 4 comments

Comments

@BronsonCarder
Copy link

BronsonCarder commented Dec 23, 2024

What happened?

I'm using the Hysteria Shaders in a very large modpack, and for every update you've released since 1.8.0-beta.4, the shaders will fail to load on startup. When I press the shader toggle key it then says "shaders disabled." I press the shader toggle key again, and sometimes it will load the shaders and be fine for the rest of that play session. It is, as far as I can tell, completely stable on 1.8.0-beta.4.

It has a button to "copy info." Here is that information:
Shader program linking failed, see log for details

And the major thing that stands out in the log is this line, repeated over and over and over again:
[08:54:11] [Render thread/INFO]: OpenGL debug message: id=1282, source=API, type=ERROR, severity=HIGH, message='GL_INVALID_OPERATION error generated. object is not successfully linked, or is not a program object.'

I will provide the whole log, but it's over 22,000 lines, most of it being that.

The best way to reproduce this would be to simply download my modpack BottomlessThought's Realism, and update Sodium and Iris (you shouldn't need to mess with any of the extras, I usually recommend people add on a few extra patrix things and physics mod pro, but the error occurs without these).
Most likely culprits include Distant Horizons, No Cubes, the Physics Mod, and the Patrix ResourcePack.

Screenshots

No response

Log output

latest.log

Minecraft Version

Minecraft 1.21.1

Iris Version

1.8.1

Operating System

Windows 10

What is your GPU?

Nvidia RTX 2060 Super

Additional context

[08:54:11] [Render thread/INFO]: OpenGL debug message: id=1282, source=API, type=ERROR, severity=HIGH, message='GL_INVALID_OPERATION error generated. <program> object is not successfully linked, or is not a program object.'

@GeForceLegend
Copy link

The log says

[08:53:19] [Render thread/WARN]: Error encountered when linking program containing VS terrain_solid and FS terrain_solid. Log output:
[08:53:19] [Render thread/WARN]: Link info
---------
error: interpolation modifier mismatch for varying parameter (named tbn) between shader stages

But tbn in gbuffers_terrain is flat in and flat out as below lines, does Iris' patcher ignores flat in certain shader stage?
https://github.com/nvb-uy/Hysteria/blob/main/shaders/program/gbuffer/solid.glsl#L26
https://github.com/nvb-uy/Hysteria/blob/main/shaders/program/gbuffer/solid.glsl#L186

You can press Ctrl+D on shader select screen to enable debug mode, and see if tbn in/out matches in terrain_solid.vsh and terrain_solid.fsh (there will be a prefix before their names like 043_terrain_solid.vsh) .minecraft/patched_shaders

@BronsonCarder
Copy link
Author

This came up upon reloading the game after enabling debug mode.

java.lang.RuntimeException: Shader program linking failed, see log for details
at knot//net.caffeinemc.mods.sodium.client.gl.shader.GlProgram$Builder.link(GlProgram.java:138)
at knot//net.irisshaders.iris.pipeline.programs.SodiumPrograms.buildProgram(SodiumPrograms.java:167)
at knot//net.irisshaders.iris.pipeline.programs.SodiumPrograms.createShader(SodiumPrograms.java:124)
at knot//net.irisshaders.iris.pipeline.programs.SodiumPrograms.(SodiumPrograms.java:66)
at knot//net.irisshaders.iris.pipeline.IrisRenderingPipeline.(IrisRenderingPipeline.java:451)
at knot//net.irisshaders.iris.Iris.createPipeline(Iris.java:616)
at knot//net.irisshaders.iris.pipeline.PipelineManager.preparePipeline(PipelineManager.java:33)
at knot//net.irisshaders.iris.Iris.onLoadingComplete(Iris.java:150)
at knot//net.minecraft.class_442.handler$dof000$iris$firstInit(class_442.java:525)
at knot//net.minecraft.class_442.method_25426(class_442.java:143)
at knot//net.minecraft.class_437.method_25423(class_437.java:309)
at knot//net.minecraft.class_310.method_1507(class_310.java:1143)
at knot//net.minecraft.class_310.method_53528(class_310.java:737)
at knot//net.minecraft.class_310.redirect$bph000$distanthorizons$buildInitialScreens(class_310.java:11757)
at knot//net.minecraft.class_310.method_51736(class_310.java:722)
at knot//net.minecraft.class_310.method_53465(class_310.java:711)
at knot//net.minecraft.class_310.method_29338(class_310.java:701)
at knot//net.minecraft.class_156.method_17974(class_156.java:597)
at knot//net.minecraft.class_310.method_53522(class_310.java:696)
at knot//net.minecraft.class_425.method_25394(class_425.java:149)
at knot//net.minecraft.class_757.method_3192(class_757.java:902)
at knot//net.minecraft.class_310.method_1523(class_310.java:1285)
at knot//net.minecraft.class_310.method_1514(class_310.java:882)
at knot//net.minecraft.client.main.Main.main(Main.java:256)
at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:480)
at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74)
at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23)

@BronsonCarder
Copy link
Author

BronsonCarder commented Dec 27, 2024

I'm not sure what you mean by checking to see if tbn matches.

038_terrain_solid.vsh:

#version 400 core
// Generated by glsl-transformer
uniform mat4 iris_ProjMat;
in vec3 iris_Position;
uniform mat4 iris_ModelViewMatInverse;
uniform mat4 iris_ProjMatInverse;
uniform mat3 iris_NormalMat;
uniform mat4 iris_LightmapTextureMatrix;
uniform mat4 iris_TextureMat;
uniform mat4 iris_ModelViewMat;
in vec3 iris_Normal;
in vec4 iris_Color;
uniform vec4 iris_ColorModulator;
in ivec2 iris_UV2;
in vec2 iris_UV0;
uniform float iris_FogDensity;
uniform float iris_FogStart;
uniform float iris_FogEnd;
uniform vec4 iris_FogColor;
struct iris_FogParameters {
vec4 color;
float density;
float start;
float end;
float scale;
};
iris_FogParameters iris_Fog = iris_FogParameters(iris_FogColor, iris_FogDensity, iris_FogStart, iris_FogEnd, 1.0f / (iris_FogEnd - iris_FogStart));
vec4 iris_FrontColor;
out float iris_FogFragCoord;
const int noiseTextureResolution = 512;
const bool shadowHardwareFiltering1 = true;
const int shadowMapResolution = 2048;
const int voxelDistance = 32;
const float shadowDistance = 192.0f;
const float shadowDistanceRenderMul = 1.0f;
const float shadowIntervalSize = 2.0f;
const float sunPathRotation = -45.0f;
const float drynessHalflife = 300.0f;
const float wetnessHalflife = 70.0f;
const float eps = 1.0E-6f;
const float e = exp(1.0f);
const float pi = acos(-1.0f);
const float tau = 2.0f * pi;
const float half_pi = 0.5f * pi;
const float rcp_pi = 1.0f / pi;
const float degree = tau / 360.0f;
const float golden_ratio = 0.5f + 0.5f * sqrt(5.0f);
const float golden_angle = tau / golden_ratio / golden_ratio;
const float hand_depth = 0.56f;
const float taau_render_scale = 0.75f;
uniform vec3 iris_ChunkOffset;
mat4 _iris_internal_translate(vec3 offset) {
return mat4(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, offset.x, offset.y, offset.z, 1.0f);
}
float sqr(float x) {
return x * x;
}
vec2 sqr(vec2 v) {
return v * v;
}
vec3 sqr(vec3 v) {
return v * v;
}
vec4 sqr(vec4 v) {
return v * v;
}
float cube(float x) {
return x * x * x;
}
float max_of(vec2 v) {
return max(v.x, v.y);
}
float max_of(vec3 v) {
return max(v.x, max(v.y, v.z));
}
float max_of(vec4 v) {
return max(v.x, max(v.y, max(v.z, v.w)));
}
float min_of(vec2 v) {
return min(v.x, v.y);
}
float min_of(vec3 v) {
return min(v.x, min(v.y, v.z));
}
float min_of(vec4 v) {
return min(v.x, min(v.y, min(v.z, v.w)));
}
float length_squared(vec2 v) {
return dot(v, v);
}
float length_squared(vec3 v) {
return dot(v, v);
}
vec2 normalize_safe(vec2 v) {
return v == vec2(0.0f) ? v : normalize(v);
}
vec3 normalize_safe(vec3 v) {
return v == vec3(0.0f) ? v : normalize(v);
}
float linear_step(float edge0, float edge1, float x) {
return clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
}
vec2 linear_step(vec2 edge0, vec2 edge1, vec2 x) {
return clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
}
float dampen(float x) {
x = clamp(x, 0.0f, 1.0f);
return x * (2.0f - x);
}
float lift(float x, float amount) {
return (x + x * amount) / (1.0f + x * amount);
}
vec3 lift(vec3 x, float amount) {
return (x + x * amount) / (1.0f + x * amount);
}
float cubic_smooth(float x) {
return sqr(x) * (3.0f - 2.0f * x);
}
float quintic_smooth(float x) {
return cube(x) * (x * (x * 6.0f - 15.0f) + 10.0f);
}
float get_uv_from_unit_range(float values, const int res) {
return values * (1.0f - 1.0f / float(res)) + (0.5f / float(res));
}
float get_unit_range_from_uv(float uv, const int res) {
return (uv - 0.5f / float(res)) / (1.0f - 1.0f / float(res));
}
float almost_identity(float x, float m, float n) {
if (x > m) return x;
float a = 2.0f * n - m;
float b = 2.0f * m - 3.0f * n;
float t = x / m;
return (a * t + b) * t * t + n;
}
float almost_unit_identity(float x) {
return x * x * (2.0f - x);
}
float pulse(float x, float center, float width) {
x = abs(x - center) / width;
return x > 1.0f ? 0.0f : 1.0f - cubic_smooth(x);
}
float pulse(float x, float center, float width, const float period) {
x = (x - center + 0.5f * period) / period;
x = fract(x) * period - (0.5f * period);
return pulse(x, 0.0f, width);
}
float impulse(float x, float peak) {
float h = peak * x;
return h * exp(1.0f - h);
}
float cubic_length(vec2 v) {
return pow(cube(abs(v.x)) + cube(abs(v.y)), (1.0f / (3.0f)));
}
vec2 diagonal(mat2 m) {
return vec2(m[0].x, m[1].y);
}
vec3 diagonal(mat3 m) {
return vec3(m[0].x, m[1].y, m[2].z);
}
vec4 diagonal(mat4 m) {
return vec4(m[0].x, m[1].y, m[2].z, m[3].w);
}
vec3 transform(mat4 m, vec3 pos) {
return mat3(m) * pos + m[3].xyz;
}
vec4 project(mat4 m, vec3 pos) {
return vec4(m[0].x, m[1].y, m[2].zw) * pos.xyzz + m[3];
}
vec3 project_and_divide(mat4 m, vec3 pos) {
vec4 homogenous = project(m, pos);
return homogenous.xyz / homogenous.w;
}
vec3 project_ortho(mat4 m, vec3 pos) {
return diagonal(m).xyz * pos + m[3].xyz;
}
out vec2 uv;
out vec2 light_levels;
out vec3 scene_pos;
out vec4 tint;
flat out uint material_mask;
out mat3 tbn;
out vec2 atlas_tile_coord;
out vec3 tangent_pos;
flat out vec2 atlas_tile_offset;
flat out vec2 atlas_tile_scale;
out float vanilla_ao;
in vec4 at_tangent;
in vec3 mc_Entity;
in vec2 mc_midTexCoord;
uniform sampler2D noisetex;
uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform vec3 cameraPosition;
uniform float near;
uniform float far;
uniform ivec2 atlasSize;
uniform float frameTimeCounter;
uniform float rainStrength;
uniform vec2 taa_offset;
uniform vec3 light_dir;
uniform mat4 dhProjection;
uniform mat4 dhProjectionInverse;
uniform mat4 dhPreviousProjection;
uniform mat4 dhPreviousProjectionInverse;
uniform float dhNearPlane;
uniform float dhFarPlane;
float linearize_depth(float near, float far, float depth) {
return (near * far) / (depth * (near - far) + far);
}
float linearize_depth(float depth) {
return linearize_depth(near, far, depth);
}
float reverse_linear_depth(float near, float far, float linear_z) {
return (far + near) / (far - near) + (2.0f * far * near) / (linear_z * (far - near));
}
float reverse_linear_depth(float linear_z) {
return reverse_linear_depth(near, far, linear_z);
}
float linearize_depth_fast(float near, float depth) {
return near / (1.0f - depth);
}
float linearize_depth_fast(float depth) {
return linearize_depth_fast(near, depth);
}
vec3 screen_to_view_space(mat4 projection_matrix_inverse, vec3 screen_pos, bool handle_jitter) {
vec3 ndc_pos = 2.0f * screen_pos - 1.0f;
vec2 jitter_offset = taa_offset * (1.0f / (taau_render_scale));
if (handle_jitter) ndc_pos.xy -= jitter_offset;
return project_and_divide(projection_matrix_inverse, ndc_pos);
}
vec3 view_to_screen_space(mat4 projection_matrix, vec3 view_pos, bool handle_jitter) {
vec3 ndc_pos = project_and_divide(projection_matrix, view_pos);
vec2 jitter_offset = taa_offset * (1.0f / (taau_render_scale));
if (handle_jitter) ndc_pos.xy += jitter_offset;
return ndc_pos * 0.5f + 0.5f;
}
vec3 screen_to_view_space(vec3 screen_pos, bool handle_jitter) {
return screen_to_view_space(gbufferProjectionInverse, screen_pos, handle_jitter);
}
vec3 view_to_screen_space(vec3 view_pos, bool handle_jitter) {
return view_to_screen_space(gbufferProjection, view_pos, handle_jitter);
}
vec3 screen_to_view_space(vec3 screen_pos, bool handle_jitter, bool is_dh_terrain) {
mat4 projection_matrix_inverse = is_dh_terrain ? dhProjectionInverse : gbufferProjectionInverse;
return screen_to_view_space(projection_matrix_inverse, screen_pos, handle_jitter);
}
vec3 view_to_screen_space(vec3 view_pos, bool handle_jitter, bool is_dh_terrain) {
mat4 projection_matrix = is_dh_terrain ? dhProjection : gbufferProjection;
return view_to_screen_space(projection_matrix, view_pos, handle_jitter);
}
float screen_to_view_space_depth(mat4 projection_matrix_inverse, float depth) {
depth = depth * 2.0f - 1.0f;
vec2 zw = depth * projection_matrix_inverse[2].zw + projection_matrix_inverse[3].zw;
return -zw.x / zw.y;
}
float view_to_screen_space_depth(mat4 projection_matrix, float depth) {
vec2 zw = -depth * projection_matrix[2].zw + projection_matrix[3].zw;
return (zw.x / zw.y) * 0.5f + 0.5f;
}
vec3 view_to_scene_space(vec3 view_pos) {
return transform(gbufferModelViewInverse, view_pos);
}
vec3 scene_to_view_space(vec3 scene_pos) {
return transform(gbufferModelView, scene_pos);
}
mat3 get_tbn_matrix(vec3 normal) {
vec3 tangent = normal.y == 1.0f ? vec3(1.0f, 0.0f, 0.0f) : normalize(cross(vec3(0.0f, 1.0f, 0.0f), normal));
vec3 bitangent = normalize(cross(tangent, normal));
return mat3(tangent, bitangent, normal);
}
vec3 get_wind_displacement(vec3 world_pos, float wind_speed, float wind_strength, bool is_tall_plant_top_vertex) {
const float wind_angle = 30.0f * degree;
const vec2 wind_dir = vec2(cos(wind_angle), sin(wind_angle));
float t = wind_speed * frameTimeCounter;
float gust_amount = texture(noisetex, 0.05f * (world_pos.xz + wind_dir * t)).y;
gust_amount *= gust_amount;
vec3 gust = vec3(wind_dir * gust_amount, 0.1f * gust_amount).xzy;
world_pos = 32.0f * world_pos + 3.0f * t + vec3(0.0f, golden_angle, 2.0f * golden_angle);
vec3 wobble = sin(world_pos) + 0.5f * sin(2.0f * world_pos) + 0.25f * sin(4.0f * world_pos);
if (is_tall_plant_top_vertex) {
gust *= 2.0f;
wobble *= 0.5f;
}
return wind_strength * (gust + 0.1f * wobble);
}
vec3 animate_vertex(vec3 world_pos, bool is_top_vertex, float skylight, uint material_mask) {
float wind_speed = 0.3f;
float wind_strength = sqr(skylight) * (0.25f + 0.66f * rainStrength);
switch (material_mask) {
case 2:
return world_pos + get_wind_displacement(world_pos, wind_speed, wind_strength, false) * float(is_top_vertex);
case 3:
return world_pos + get_wind_displacement(world_pos, wind_speed, wind_strength, false) * float(is_top_vertex);
case 4:
return world_pos + get_wind_displacement(world_pos, wind_speed, wind_strength, is_top_vertex);
case 5:
return world_pos + get_wind_displacement(world_pos, wind_speed, wind_strength * 0.5f, false);
default:
return world_pos;
}
}
uint get_material_mask() {
return uint(max(mc_Entity.x - 10000.0f, 0.0f));
}
mat3 get_tbn_matrix() {
mat3 tbn;
tbn[0] = mat3(gbufferModelViewInverse) * normalize(iris_NormalMat * at_tangent.xyz);
tbn[2] = mat3(gbufferModelViewInverse) * normalize(iris_NormalMat * iris_Normal);
tbn[1] = cross(tbn[0], tbn[2]) * sign(at_tangent.w);
return tbn;
}
void main() {
iris_FogFragCoord = 0.0f;
uv = (iris_TextureMat * vec4(iris_UV0, 0.0f, 1.0f)).xy;
light_levels = clamp(vec4(iris_UV2, 0.0f, 1.0f).xy * (1.0f / (240.0f)), 0.0f, 1.0f);
tint = (iris_Color * iris_ColorModulator);
material_mask = get_material_mask();
tbn = get_tbn_matrix();
vanilla_ao = (iris_Color * iris_ColorModulator).a < 0.1f ? 1.0f : (iris_Color * iris_ColorModulator).a;
vanilla_ao = material_mask == 5 ? 1.0f : vanilla_ao;
tint.a = 1.0f;
vec2 uv_minus_mid = uv - mc_midTexCoord;
atlas_tile_offset = min(uv, mc_midTexCoord - uv_minus_mid);
atlas_tile_scale = abs(uv_minus_mid) * 2.0f;
atlas_tile_coord = sign(uv_minus_mid) * 0.5f + 0.5f;
bool is_top_vertex = uv.y < mc_midTexCoord.y;
vec3 pos = transform((iris_ModelViewMat * _iris_internal_translate(iris_ChunkOffset)), vec4(iris_Position, 1.0f).xyz);
pos = view_to_scene_space(pos);
pos = pos + cameraPosition;
pos = animate_vertex(pos, is_top_vertex, light_levels.y, material_mask);
pos = pos - cameraPosition;
scene_pos = pos;
tangent_pos = (pos - gbufferModelViewInverse[3].xyz) * tbn;
vec3 view_pos = scene_to_view_space(pos);
vec4 clip_pos = project(iris_ProjMat, view_pos);
clip_pos.xy = clip_pos.xy * taau_render_scale + clip_pos.w * (taau_render_scale - 1.0f);
clip_pos.xy += taa_offset * clip_pos.w;
gl_Position = clip_pos;
}

### 038_terrain_solid.fsh:

#version 400 core
// Generated by glsl-transformer
uniform mat4 iris_ProjMat;
uniform mat4 iris_ModelViewMatInverse;
uniform mat4 iris_ProjMatInverse;
uniform mat3 iris_NormalMat;
uniform mat4 iris_LightmapTextureMatrix;
uniform mat4 iris_TextureMat;
uniform mat4 iris_ModelViewMat;
uniform vec4 iris_ColorModulator;
uniform float iris_FogDensity;
uniform float iris_FogStart;
uniform float iris_FogEnd;
uniform vec4 iris_FogColor;
struct iris_FogParameters {
vec4 color;
float density;
float start;
float end;
float scale;
};
iris_FogParameters iris_Fog = iris_FogParameters(iris_FogColor, iris_FogDensity, iris_FogStart, iris_FogEnd, 1.0f / (iris_FogEnd - iris_FogStart));
in float iris_FogFragCoord;
const int noiseTextureResolution = 512;
const bool shadowHardwareFiltering1 = true;
const int shadowMapResolution = 2048;
const int voxelDistance = 32;
const float shadowDistance = 192.0f;
const float shadowDistanceRenderMul = 1.0f;
const float shadowIntervalSize = 2.0f;
const float sunPathRotation = -45.0f;
const float drynessHalflife = 300.0f;
const float wetnessHalflife = 70.0f;
const float eps = 1.0E-6f;
const float e = exp(1.0f);
const float pi = acos(-1.0f);
const float tau = 2.0f * pi;
const float half_pi = 0.5f * pi;
const float rcp_pi = 1.0f / pi;
const float degree = tau / 360.0f;
const float golden_ratio = 0.5f + 0.5f * sqrt(5.0f);
const float golden_angle = tau / golden_ratio / golden_ratio;
const float hand_depth = 0.56f;
const float taau_render_scale = 0.75f;
float sqr(float x) {
return x * x;
}
vec2 sqr(vec2 v) {
return v * v;
}
vec3 sqr(vec3 v) {
return v * v;
}
vec4 sqr(vec4 v) {
return v * v;
}
float cube(float x) {
return x * x * x;
}
float max_of(vec2 v) {
return max(v.x, v.y);
}
float max_of(vec3 v) {
return max(v.x, max(v.y, v.z));
}
float max_of(vec4 v) {
return max(v.x, max(v.y, max(v.z, v.w)));
}
float min_of(vec2 v) {
return min(v.x, v.y);
}
float min_of(vec3 v) {
return min(v.x, min(v.y, v.z));
}
float min_of(vec4 v) {
return min(v.x, min(v.y, min(v.z, v.w)));
}
float length_squared(vec2 v) {
return dot(v, v);
}
float length_squared(vec3 v) {
return dot(v, v);
}
vec2 normalize_safe(vec2 v) {
return v == vec2(0.0f) ? v : normalize(v);
}
vec3 normalize_safe(vec3 v) {
return v == vec3(0.0f) ? v : normalize(v);
}
float linear_step(float edge0, float edge1, float x) {
return clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
}
vec2 linear_step(vec2 edge0, vec2 edge1, vec2 x) {
return clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
}
float dampen(float x) {
x = clamp(x, 0.0f, 1.0f);
return x * (2.0f - x);
}
float lift(float x, float amount) {
return (x + x * amount) / (1.0f + x * amount);
}
vec3 lift(vec3 x, float amount) {
return (x + x * amount) / (1.0f + x * amount);
}
float cubic_smooth(float x) {
return sqr(x) * (3.0f - 2.0f * x);
}
float quintic_smooth(float x) {
return cube(x) * (x * (x * 6.0f - 15.0f) + 10.0f);
}
float get_uv_from_unit_range(float values, const int res) {
return values * (1.0f - 1.0f / float(res)) + (0.5f / float(res));
}
float get_unit_range_from_uv(float uv, const int res) {
return (uv - 0.5f / float(res)) / (1.0f - 1.0f / float(res));
}
float almost_identity(float x, float m, float n) {
if (x > m) return x;
float a = 2.0f * n - m;
float b = 2.0f * m - 3.0f * n;
float t = x / m;
return (a * t + b) * t * t + n;
}
float almost_unit_identity(float x) {
return x * x * (2.0f - x);
}
float pulse(float x, float center, float width) {
x = abs(x - center) / width;
return x > 1.0f ? 0.0f : 1.0f - cubic_smooth(x);
}
float pulse(float x, float center, float width, const float period) {
x = (x - center + 0.5f * period) / period;
x = fract(x) * period - (0.5f * period);
return pulse(x, 0.0f, width);
}
float impulse(float x, float peak) {
float h = peak * x;
return h * exp(1.0f - h);
}
float cubic_length(vec2 v) {
return pow(cube(abs(v.x)) + cube(abs(v.y)), (1.0f / (3.0f)));
}
vec2 diagonal(mat2 m) {
return vec2(m[0].x, m[1].y);
}
vec3 diagonal(mat3 m) {
return vec3(m[0].x, m[1].y, m[2].z);
}
vec4 diagonal(mat4 m) {
return vec4(m[0].x, m[1].y, m[2].z, m[3].w);
}
vec3 transform(mat4 m, vec3 pos) {
return mat3(m) * pos + m[3].xyz;
}
vec4 project(mat4 m, vec3 pos) {
return vec4(m[0].x, m[1].y, m[2].zw) * pos.xyzz + m[3];
}
vec3 project_and_divide(mat4 m, vec3 pos) {
vec4 homogenous = project(m, pos);
return homogenous.xyz / homogenous.w;
}
vec3 project_ortho(mat4 m, vec3 pos) {
return diagonal(m).xyz * pos + m[3].xyz;
}
layout(location = 0) out vec4 gbuffer_data_0;
layout(location = 1) out vec4 gbuffer_data_1;
in vec2 uv;
in vec2 light_levels;
in vec3 scene_pos;
in vec4 tint;
flat in uint material_mask;
in mat3 tbn;
in vec2 atlas_tile_coord;
in vec3 tangent_pos;
flat in vec2 atlas_tile_offset;
flat in vec2 atlas_tile_scale;
in float vanilla_ao;
uniform sampler2D noisetex;
uniform sampler2D gtexture;
uniform sampler2D normals;
uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform vec3 cameraPosition;
uniform float near;
uniform float far;
uniform int frameCounter;
uniform float frameTimeCounter;
uniform vec2 view_res;
uniform vec2 view_pixel_size;
uniform vec2 taa_offset;
uniform vec3 light_dir;
vec2 get_uv_from_local_coord(vec2 local_coord) {
return atlas_tile_offset + atlas_tile_scale * fract(local_coord);
}
vec2 get_local_coord_from_uv(vec2 uv) {
return (uv - atlas_tile_offset) * (1.0f / (atlas_tile_scale));
}
float get_height_value(vec2 local_coord, mat2 uv_gradient) {
vec2 uv = get_uv_from_local_coord(local_coord);
return textureGrad(normals, uv, uv_gradient[0], uv_gradient[1]).w;
}
float get_depth_value(vec2 local_coord, mat2 uv_gradient) {
return 1.0f - get_height_value(local_coord, uv_gradient);
}
vec2 get_parallax_uv(vec3 tangent_dir, mat2 uv_gradient, float view_distance, float dither, out vec3 previous_ray_pos, out float pom_depth) {
const float depth_step = (1.0f / (float(40)));
float depth_value = get_depth_value(atlas_tile_coord, uv_gradient);
if (depth_value < (1.0f / (255.0f))) {
previous_ray_pos = vec3(atlas_tile_coord, 0.0f);
pom_depth = 0.0f;
return uv;
}
float parallax_fade = linear_step(0.75f * 32, 32, view_distance);
vec3 ray_step = vec3(tangent_dir.xy * (1.0f / (-tangent_dir.z)) * 0.25f * (1.0f - parallax_fade), 1.0f) * depth_step;
vec3 pos = vec3(atlas_tile_coord + ray_step.xy * dither, 0.0f);
while (depth_value - pos.z >= (1.0f / (255.0f))) {
previous_ray_pos = vec3(pos);
depth_value = get_depth_value(pos.xy, uv_gradient);
pos += ray_step;
}
pom_depth = depth_value;
return get_uv_from_local_coord(pos.xy);
}
bool get_parallax_shadow(vec3 pos, mat2 uv_gradient, float view_distance, float dither) {
float parallax_fade = linear_step(0.75f * 32, 32, view_distance);
vec3 tangent_dir = light_dir * tbn;
vec3 ray_step = vec3(tangent_dir.xy * (1.0f / (tangent_dir.z)) * 0.25f * (1.0f - parallax_fade), -1.0f) * pos.z * (1.0f / (float(40)));
pos.xy += ray_step.xy * dither;
for (int i = 0; i < 40; ++i) {
pos += ray_step;
if (get_depth_value(pos.xy, uv_gradient) < pos.z) return true;
}
return false;
}
vec2 get_directional_lightmaps(vec3 normal) {
vec2 lightmap_mul = vec2(1.0f);
vec2 lightmap_gradient;
vec3 lightmap_dir;
mat2x3 pos_gradient = mat2x3(dFdx(scene_pos), dFdy(scene_pos));
lightmap_gradient = vec2(dFdx(light_levels.x), dFdy(light_levels.x));
lightmap_dir = pos_gradient * lightmap_gradient;
if (length_squared(lightmap_gradient) > 1.0E-12f) {
lightmap_mul.x = (clamp(dot(normalize(lightmap_dir), normal) + 0.8f, 0.0f, 1.0f) * 0.2f + (1.0f - 0.2f)) * inversesqrt(sqrt(light_levels.x) + eps);
}
lightmap_gradient = vec2(dFdx(light_levels.y), dFdy(light_levels.y));
lightmap_dir = pos_gradient * lightmap_gradient;
if (length_squared(lightmap_gradient) > 1.0E-12f) {
lightmap_mul.y = (clamp(dot(normalize(lightmap_dir), normal) + 0.8f, 0.0f, 1.0f) * 0.2f + (1.0f - 0.2f)) * inversesqrt(sqrt(light_levels.y) + eps);
}
return lightmap_mul;
}
float bayer2(vec2 a) {
a = floor(a);
return fract(dot(a, vec2(0.5f, a.y * 0.75f)));
}
float bayer4(vec2 a) {
return 0.25f * bayer2(0.5f * a) + bayer2(a);
}
float bayer8(vec2 a) {
return 0.25f * bayer4(0.5f * a) + bayer2(a);
}
float bayer16(vec2 a) {
return 0.25f * bayer8(0.5f * a) + bayer2(a);
}
float bayer32(vec2 a) {
return 0.25f * bayer16(0.5f * a) + bayer2(a);
}
float interleaved_gradient_noise(vec2 pos) {
return fract(52.9829189f * fract(0.06711056f * pos.x + (0.00583715f * pos.y)));
}
float interleaved_gradient_noise(vec2 pos, int t) {
return interleaved_gradient_noise(pos + 5.588238f * (t & 63));
}
float dither_8bit(float x, float pattern) {
const vec2 mul_add = vec2(1.0f, -0.5f) / 255.0f;
return clamp(x + (pattern * mul_add.x + mul_add.y), 0.0f, 1.0f);
}
vec2 dither_8bit(vec2 x, float pattern) {
const vec2 mul_add = vec2(1.0f, -0.5f) / 255.0f;
return clamp(x + (pattern * mul_add.x + mul_add.y), 0.0f, 1.0f);
}
vec3 dither_8bit(vec3 rgb, float pattern) {
const vec2 mul_add = vec2(1.0f, -0.5f) / 255.0f;
return clamp(rgb + (pattern * mul_add.x + mul_add.y), 0.0f, 1.0f);
}
vec2 sign_non_zero(vec2 v) {
return vec2(v.x >= 0.0f ? 1.0f : -1.0f, v.y >= 0.0f ? 1.0f : -1.0f);
}
vec2 encode_unit_vector(vec3 v) {
vec2 p = v.xy * (1.0f / (abs(v.x) + abs(v.y) + abs(v.z)));
p = v.z <= 0.0f ? ((1.0f - abs(p.yx)) * sign_non_zero(p)) : p;
return 0.5f * p + 0.5f;
}
vec3 decode_unit_vector(vec2 e) {
e = 2.0f * e - 1.0f;
vec3 v = vec3(e.xy, 1.0f - abs(e.x) - abs(e.y));
if (v.z < 0) v.xy = (1.0f - abs(v.yx)) * sign_non_zero(v.xy);
return normalize(v);
}
vec4 encode_rgbe8(vec3 rgb) {
float exponent_part = floor(log2(max_of(vec4(rgb, exp2(-127.0f)))));
vec3 mantissa_part = clamp((128.0f / 255.0f) * exp2(-exponent_part) * rgb, 0.0f, 1.0f);
exponent_part = clamp(exponent_part * (1.0f / 255.0f) + (127.0f / 255.0f), 0.0f, 1.0f);
return vec4(mantissa_part, exponent_part);
}
vec3 decode_rgbe8(vec4 rgbe) {
const float add = log2(255.0f / 128.0f) - 127.0f;
return exp2(rgbe.a * 255.0f + add) * rgbe.rgb;
}
float pack_unorm_2x4(vec2 xy) {
return dot(floor(15.0f * xy + 0.5f), vec2(1.0f / 255.0f, 16.0f / 255.0f));
}
float pack_unorm_2x4(float x, float y) {
return pack_unorm_2x4(vec2(x, y));
}
vec2 unpack_unorm_2x4(float pack) {
vec2 xy;
xy.x = modf((255.0f / 16.0f) * pack, xy.y);
return xy * vec2(16.0f / 15.0f, 1.0f / 15.0f);
}
float pack_unorm_2x8(vec2 v) {
return dot(floor(255.0f * v + 0.5f), vec2(1.0f / 65535.0f, 256.0f / 65535.0f));
}
float pack_unorm_2x8(float x, float y) {
return pack_unorm_2x8(vec2(x, y));
}
vec2 unpack_unorm_2x8(float pack) {
vec2 xy;
xy.x = modf((65535.0f / 256.0f) * pack, xy.y);
return xy * vec2(256.0f / 255.0f, 1.0f / 255.0f);
}
uint pack_unorm_arb(vec4 data, const uvec4 bits) {
vec4 mul = exp2(vec4(bits)) - 1.0f;
uvec4 shift = uvec4(0, bits.x, bits.x + bits.y, bits.x + bits.y + bits.z);
uvec4 shifted = uvec4(data * mul + 0.5f) << shift;
return shifted.x | shifted.y | shifted.z | shifted.w;
}
vec4 unpack_unorm_arb(uint pack, const uvec4 bits) {
uvec4 max_value = uvec4(exp2(bits) - 1);
uvec4 shift = uvec4(0, bits.x, bits.x + bits.y, bits.x + bits.y + bits.z);
uvec4 unshifted = uvec4(pack) >> shift;
unshifted = unshifted & max_value;
return vec4(unshifted) * (1.0f / (vec4(max_value)));
}
float fast_acos(float x) {
const float C0 = 1.57018f;
const float C1 = -0.201877f;
const float C2 = 0.0464619f;
float res = (C2 * abs(x) + C1) * abs(x) + C0;
res *= sqrt(1.0f - abs(x));
return x >= 0 ? res : pi - res;
}
vec2 fast_acos(vec2 v) {
return vec2(fast_acos(v.x), fast_acos(v.y));
}
float pow4(float x) {
return sqr(sqr(x));
}
float pow5(float x) {
return pow4(x) * x;
}
float pow6(float x) {
return sqr(cube(x));
}
float pow7(float x) {
return pow6(x) * x;
}
float pow8(float x) {
return sqr(pow4(x));
}
float pow12(float x) {
return cube(pow4(x));
}
float pow16(float x) {
x *= x;
x *= x;
x *= x;
x *= x;
return x;
}
float pow32(float x) {
x *= x;
x *= x;
x *= x;
x *= x;
x *= x;
return x;
}
float pow64(float x) {
x *= x;
x *= x;
x *= x;
x *= x;
x *= x;
x *= x;
return x;
}
float pow128(float x) {
x *= x;
x *= x;
x *= x;
x *= x;
x *= x;
x *= x;
x *= x;
return x;
}
float pow1d5(float x) {
return x * sqrt(x);
}
float rcp_length(vec2 v) {
return inversesqrt(dot(v, v));
}
float rcp_length(vec3 v) {
return inversesqrt(dot(v, v));
}
void length_normalize(vec3 v, out vec3 normalized, out float len) {
float len_sq = length_squared(v);
float rcp_len = inversesqrt(len_sq);
len = len_sq * rcp_len;
normalized = rcp_len * v;
}
const float phi1 = 1.6180339887f;
const float phi2 = 1.3247179572f;
const float phi3 = 1.2207440846f;
float r1(int n, float seed) {
const float alpha = 1.0f / phi1;
return fract(seed + n * alpha);
}
float r1(int n) {
return r1(n, 0.5f);
}
float r1_next(float u) {
const float alpha = 1.0f / phi1;
return fract(u + alpha);
}
vec2 r2(int n, vec2 seed) {
const vec2 alpha = 1.0f / vec2(phi2, phi2 * phi2);
return fract(seed + n * alpha);
}
vec2 r2(int n) {
return r2(n, vec2(0.5f));
}
vec2 r2_next(vec2 u) {
const vec2 alpha = 1.0f / vec2(phi2, phi2 * phi2);
return fract(u + alpha);
}
vec3 r3(int n, vec3 seed) {
const vec3 alpha = 1.0f / vec3(phi3, phi3 * phi3, phi3 * phi3 * phi3);
return fract(seed + n * alpha);
}
vec3 r3(int n) {
return r3(n, vec3(0.5f));
}
vec3 r3_next(vec3 u) {
const vec3 alpha = 1.0f / vec3(phi3, phi3 * phi3, phi3 * phi3 * phi3);
return fract(u + alpha);
}
uint lowbias32(uint x) {
x ^= x >> 16;
x *= 0x7feb352du;
x ^= x >> 15;
x *= 0x846ca68bu;
x ^= x >> 16;
return x;
}
uint lowbias32_inverse(uint x) {
x ^= x >> 16;
x *= 0x43021123u;
x ^= x >> 15 ^ x >> 30;
x *= 0x1d69e2a5u;
x ^= x >> 16;
return x;
}
float rand_next_float(inout uint state) {
state = lowbias32(state);
return float(state) / float(0xffffffffu);
}
vec2 rand_next_vec2(inout uint state) {
return vec2(rand_next_float(state), rand_next_float(state));
}
vec3 rand_next_vec3(inout uint state) {
return vec3(rand_next_float(state), rand_next_float(state), rand_next_float(state));
}
vec4 rand_next_vec4(inout uint state) {
return vec4(rand_next_float(state), rand_next_float(state), rand_next_float(state), rand_next_float(state));
}
float hash1(float p) {
p = fract(p * 0.1031f);
p *= p + 33.33f;
p *= p + p;
return fract(p);
}
float hash1(vec3 p3) {
p3 = fract(p3 * 0.1031f);
p3 += dot(p3, p3.zyx + 31.32f);
return fract((p3.x + p3.y) * p3.z);
}
vec2 hash2(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031f, 0.103f, 0.0973f));
p3 += dot(p3, p3.yzx + 33.33f);
return fract((p3.xx + p3.yz) * p3.zy);
}
vec2 hash2(vec3 p3) {
p3 = fract(p3 * vec3(0.1031f, 0.103f, 0.0973f));
p3 += dot(p3, p3.yzx + 33.33f);
return fract((p3.xx + p3.yz) * p3.zy);
}
vec4 hash4(vec2 p) {
vec4 p4 = fract(vec4(p.xyxy) * vec4(0.1031f, 0.103f, 0.0973f, 0.1099f));
p4 += dot(p4, p4.wzxy + 33.33f);
return fract((p4.xxyz + p4.yzzw) * p4.zywx);
}
vec4 hash4(vec3 p) {
vec4 p4 = fract(vec4(p.xyzx) * vec4(0.1031f, 0.103f, 0.0973f, 0.1099f));
p4 += dot(p4, p4.wzxy + 33.33f);
return fract((p4.xxyz + p4.yzzw) * p4.zywx);
}
uniform mat4 dhProjection;
uniform mat4 dhProjectionInverse;
uniform mat4 dhPreviousProjection;
uniform mat4 dhPreviousProjectionInverse;
uniform float dhNearPlane;
uniform float dhFarPlane;
float linearize_depth(float near, float far, float depth) {
return (near * far) / (depth * (near - far) + far);
}
float linearize_depth(float depth) {
return linearize_depth(near, far, depth);
}
float reverse_linear_depth(float near, float far, float linear_z) {
return (far + near) / (far - near) + (2.0f * far * near) / (linear_z * (far - near));
}
float reverse_linear_depth(float linear_z) {
return reverse_linear_depth(near, far, linear_z);
}
float linearize_depth_fast(float near, float depth) {
return near / (1.0f - depth);
}
float linearize_depth_fast(float depth) {
return linearize_depth_fast(near, depth);
}
vec3 screen_to_view_space(mat4 projection_matrix_inverse, vec3 screen_pos, bool handle_jitter) {
vec3 ndc_pos = 2.0f * screen_pos - 1.0f;
vec2 jitter_offset = taa_offset * (1.0f / (taau_render_scale));
if (handle_jitter) ndc_pos.xy -= jitter_offset;
return project_and_divide(projection_matrix_inverse, ndc_pos);
}
vec3 view_to_screen_space(mat4 projection_matrix, vec3 view_pos, bool handle_jitter) {
vec3 ndc_pos = project_and_divide(projection_matrix, view_pos);
vec2 jitter_offset = taa_offset * (1.0f / (taau_render_scale));
if (handle_jitter) ndc_pos.xy += jitter_offset;
return ndc_pos * 0.5f + 0.5f;
}
vec3 screen_to_view_space(vec3 screen_pos, bool handle_jitter) {
return screen_to_view_space(gbufferProjectionInverse, screen_pos, handle_jitter);
}
vec3 view_to_screen_space(vec3 view_pos, bool handle_jitter) {
return view_to_screen_space(gbufferProjection, view_pos, handle_jitter);
}
vec3 screen_to_view_space(vec3 screen_pos, bool handle_jitter, bool is_dh_terrain) {
mat4 projection_matrix_inverse = is_dh_terrain ? dhProjectionInverse : gbufferProjectionInverse;
return screen_to_view_space(projection_matrix_inverse, screen_pos, handle_jitter);
}
vec3 view_to_screen_space(vec3 view_pos, bool handle_jitter, bool is_dh_terrain) {
mat4 projection_matrix = is_dh_terrain ? dhProjection : gbufferProjection;
return view_to_screen_space(projection_matrix, view_pos, handle_jitter);
}
float screen_to_view_space_depth(mat4 projection_matrix_inverse, float depth) {
depth = depth * 2.0f - 1.0f;
vec2 zw = depth * projection_matrix_inverse[2].zw + projection_matrix_inverse[3].zw;
return -zw.x / zw.y;
}
float view_to_screen_space_depth(mat4 projection_matrix, float depth) {
vec2 zw = -depth * projection_matrix[2].zw + projection_matrix[3].zw;
return (zw.x / zw.y) * 0.5f + 0.5f;
}
vec3 view_to_scene_space(vec3 view_pos) {
return transform(gbufferModelViewInverse, view_pos);
}
vec3 scene_to_view_space(vec3 scene_pos) {
return transform(gbufferModelView, scene_pos);
}
mat3 get_tbn_matrix(vec3 normal) {
vec3 tangent = normal.y == 1.0f ? vec3(1.0f, 0.0f, 0.0f) : normalize(cross(vec3(0.0f, 1.0f, 0.0f), normal));
vec3 bitangent = normalize(cross(tangent, normal));
return mat3(tangent, bitangent, normal);
}
void decode_normal_map(vec3 normal_map, out vec3 normal, out float ao) {
normal.xy = normal_map.xy * 2.0f - 1.0f;
normal.z = sqrt(clamp(1.0f - dot(normal.xy, normal.xy), 0.0f, 1.0f));
ao = normal_map.z;
}
const float lod_bias = log2(taau_render_scale);
void main() {
vec2 coord = gl_FragCoord.xy * view_pixel_size * (1.0f / (taau_render_scale));
if (clamp(coord, 0.0f, 1.0f) != coord) discard;
bool parallax_shadow = false;
float dither = interleaved_gradient_noise(gl_FragCoord.xy, frameCounter);
float view_distance = length(tangent_pos);
bool has_pom = view_distance < 32;
has_pom = has_pom && material_mask != 1 && material_mask != 39;
vec3 tangent_dir = -normalize(tangent_pos);
mat2 uv_gradient = mat2(dFdx(uv), dFdy(uv));
vec2 parallax_uv;
if (has_pom) {
float pom_depth;
vec3 shadow_trace_pos;
parallax_uv = get_parallax_uv(tangent_dir, uv_gradient, view_distance, dither, shadow_trace_pos, pom_depth);
}
else {
parallax_uv = uv;
parallax_shadow = false;
}
vec4 base_color = textureGrad(gtexture, parallax_uv, uv_gradient[0], uv_gradient[1]) * tint;
vec3 normal_map = textureGrad(normals, parallax_uv, uv_gradient[0], uv_gradient[1]).xyz;
if (base_color.a < 0.1f) {
discard;
return;
}
const float vanilla_ao_strength = 0.9f;
const float vanilla_ao_lift = 0.5f;
base_color.rgb *= lift(vanilla_ao, vanilla_ao_lift) * vanilla_ao_strength + (1.0f - vanilla_ao_strength);
vec2 adjusted_light_levels = light_levels;
vec3 normal;
float material_ao;
decode_normal_map(normal_map, normal, material_ao);
normal = tbn * normal;
adjusted_light_levels *= mix(0.7f, 1.0f, material_ao);
adjusted_light_levels *= get_directional_lightmaps(normal);
gbuffer_data_0.x = pack_unorm_2x8(base_color.rg);
gbuffer_data_0.y = pack_unorm_2x8(base_color.b, clamp(float(material_mask) * (1.0f / (255.0f)), 0.0f, 1.0f));
gbuffer_data_0.z = pack_unorm_2x8(encode_unit_vector(tbn[2]));
gbuffer_data_0.w = pack_unorm_2x8(dither_8bit(adjusted_light_levels, dither));
gbuffer_data_1.xy = encode_unit_vector(normal);
}

@GeForceLegend
Copy link

Iris removes the flat modifier for both in and out for tbn... Then why the log says interpolation modifier mismatch? Or Iris forget one in other shader program?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants