Skip to content
Open
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
10 changes: 0 additions & 10 deletions armory/Shaders/deferred_light/deferred_light.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,6 @@ void main() {
}
#endif
#endif

#ifdef _VoxelShadow
svisibility *= textureLod(voxels_shadows, texCoord, 0.0).r * voxelgiShad;
#endif

#ifdef _SSRS
// vec2 coords = getProjectedCoord(hitCoord);
Expand Down Expand Up @@ -430,9 +426,6 @@ void main() {
#ifdef _Spot
, true, spotData.x, spotData.y, spotDir, spotData.zw, spotRight
#endif
#ifdef _VoxelShadow
, texCoord
#endif
#ifdef _MicroShadowing
, occspec.x
#endif
Expand Down Expand Up @@ -488,9 +481,6 @@ void main() {
, vec2(lightsArray[li * 3].w, lightsArray[li * 3 + 1].w) // scale
, lightsArraySpot[li * 2 + 1].xyz // right
#endif
#ifdef _VoxelShadow
, texCoord
#endif
#ifdef _MicroShadowing
, occspec.x
#endif
Expand Down
63 changes: 41 additions & 22 deletions armory/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@

#include "compiled.inc"
#include "std/math.glsl"
#include "std/brdf.glsl"
#include "std/gbuffer.glsl"

#ifdef _Brdf
uniform sampler2D senvmapBrdf;
#endif

uniform sampler2D tex;
uniform sampler2D tex1;
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
uniform sampler2D gbufferD1;
uniform sampler2D gbuffer_refraction; // ior\opacity
uniform mat4 P;
uniform mat3 V3;
uniform vec2 cameraProj;
uniform vec3 eye;

in vec3 viewRay;
in vec2 texCoord;
Expand All @@ -38,7 +45,7 @@ vec2 getProjectedCoord(const vec3 hit) {
}

float getDeltaDepth(const vec3 hit) {
float depth = textureLod(gbufferD1, getProjectedCoord(hit), 0.0).r * 2.0 - 1.0;
depth = textureLod(gbufferD1, getProjectedCoord(hit), 0.0).r * 2.0 - 1.0;
vec3 viewPos = getPosView(viewRay, depth, cameraProj);
return viewPos.z - hit.z;
}
Expand All @@ -51,62 +58,74 @@ vec4 binarySearch(vec3 dir) {
ddepth = getDeltaDepth(hitCoord);
if (ddepth < 0.0) hitCoord += dir;
}
if (abs(ddepth) > ss_refractionSearchDist) return vec4(0.0);
return vec4(getProjectedCoord(hitCoord), 0.0, 1.0);
}

vec4 rayCast(vec3 dir) {
float ddepth;
dir *= ss_refractionRayStep;
for (int i = 0; i < maxSteps; i++) {
hitCoord += dir;
hitCoord += dir * ss_refractionRayStep;
ddepth = getDeltaDepth(hitCoord);
if (ddepth > 0.0) return binarySearch(dir);
}
return vec4(0.0);
return vec4(getProjectedCoord(hitCoord), 0.0, 0.0);
}

void main() {
vec4 g0 = textureLod(gbuffer0, texCoord, 0.0);
float roughness = g0.z;
float roughness = g0.b;
float metallic;
uint matid;
unpackFloatInt16(g0.a, metallic, matid);
vec4 gr = textureLod(gbuffer_refraction, texCoord, 0.0);
float ior = gr.x;
float opac = gr.y;

float d = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;

if (opac == 1.0) {
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
return;
}
if (d == 0.0) {
fragColor.rgb = textureLod(tex1, texCoord, 0.0).rgb;
if (d == 0.0 || d == 1.0 || opac == 1.0) {
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
return;
}

vec2 enc = g0.rg;
vec2 enc = g0.rg;
vec3 n;
n.z = 1.0 - abs(enc.x) - abs(enc.y);
n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
n = normalize(n);

vec3 viewNormal = V3 * n;
vec3 viewPos = getPosView(viewRay, d, cameraProj);
vec3 viewPos = getPosView(normalize(viewRay), d, cameraProj);
vec3 refracted = refract(viewPos, viewNormal, 1.0 / ior);
hitCoord = viewPos;
vec3 hitCoord1 = viewPos;

vec3 dir = refracted * (1.0 - rand(texCoord) * ss_refractionJitter * roughness) * 2.0;

vec3 dir = refracted * (1.0 - rand(texCoord) * ss_refractionJitter * roughness) * 2.0;
vec4 coords = rayCast(dir);
float dist = length(hitCoord - hitCoord1);
vec3 refractionCol = textureLod(tex, coords.xy, 0.0).rgb; /* * exp(log(1.0 - opac) * dist); */

vec4 g1 = textureLod(gbuffer1, texCoord, 0.0); // Basecolor.rgb, spec/occ
vec3 f0 = surfaceF0(refractionCol.rgb, metallic);
float dotNV = max(dot(viewNormal, viewPos), 0.0);

#ifdef _Brdf
vec2 envBRDF = texelFetch(senvmapBrdf, ivec2(vec2(dotNV, 1.0 - roughness) * 256.0), 0).xy;
vec3 F = f0 * envBRDF.x + envBRDF.y;
#else
vec3 F = f0;
#endif

vec2 deltaCoords = abs(vec2(0.5, 0.5) - coords.xy);
float screenEdgeFactor = clamp(1.0 - (deltaCoords.x + deltaCoords.y), 0.0, 1.0);

float refractivity = 1.0 - roughness;
float intensity = pow(refractivity, ss_refractionFalloffExp) * screenEdgeFactor * clamp(-refracted.z, 0.0, 1.0) * clamp((length(viewPos - hitCoord)), 0.0, 1.0) * coords.w;
float refractivity = 1.0 - opac;
vec3 intensity = refractivity * screenEdgeFactor * clamp(abs(refracted.z), 0.0, 1.0) * (1.0 - F);

intensity = clamp(intensity, 0.0, 1.0);

vec3 refractionCol = textureLod(tex1, coords.xy, 0.0).rgb;
vec3 color = textureLod(tex, texCoord.xy, 0.0).rgb;
fragColor.rgb = mix(refractionCol * intensity, color, opac);
refractionCol *= intensity;
vec3 color = textureLod(tex1, texCoord.xy, 0.0).rgb;

fragColor.rgb = mix(refractionCol, color, opac);

}
9 changes: 9 additions & 0 deletions armory/Shaders/ssrefr_pass/ssrefr_pass.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"compare_mode": "always",
"cull_mode": "none",
"links": [
{
"name": "eye",
"link": "_cameraPosition"
},
{
"name": "P",
"link": "_projectionMatrix"
Expand All @@ -29,6 +33,11 @@
{
"name": "cameraProj",
"link": "_cameraPlaneProj"
},
{
"name": "senvmapBrdf",
"link": "$brdf.png",
"ifdef": ["_Brdf"]
}
],
"vertex_shader": "../include/pass_viewray2.vert.glsl",
Expand Down
18 changes: 18 additions & 0 deletions armory/Shaders/std/aabb.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _AABB_GLSL
#define _AABB_GLSL

bool IntersectAABB(vec3[2] a, vec3[2] b) {
const float EPSILON = 0.001; // Small tolerance to prevent false negatives
if (abs(a[0].x - b[0].x) > (a[1].x + b[1].x + EPSILON)) return false;
if (abs(a[0].y - b[0].y) > (a[1].y + b[1].y + EPSILON)) return false;
if (abs(a[0].z - b[0].z) > (a[1].z + b[1].z + EPSILON)) return false;
return true;
}

void AABBfromMinMax(inout vec3[2] aabb, vec3 _min, vec3 _max)
{
aabb[0] = (_min + _max) * 0.5f;
aabb[1] = abs(_max - aabb[0]);
}

#endif
Loading