diff --git a/shaders/dimensions/all_particles.fsh b/shaders/dimensions/all_particles.fsh index d0cd795..ea9508b 100644 --- a/shaders/dimensions/all_particles.fsh +++ b/shaders/dimensions/all_particles.fsh @@ -121,6 +121,14 @@ uniform int heldItemId2; #undef FLASHLIGHT_BOUNCED_INDIRECT +#if defined VIVECRAFT + uniform bool vivecraftIsVR; + uniform vec3 vivecraftRelativeMainHandPos; + uniform vec3 vivecraftRelativeOffHandPos; + uniform mat4 vivecraftRelativeMainHandRot; + uniform mat4 vivecraftRelativeOffHandRot; +#endif + #include "/lib/diffuse_lighting.glsl" #include "/lib/sky_gradient.glsl" diff --git a/shaders/dimensions/all_solid.gsh b/shaders/dimensions/all_solid.gsh index e1b2362..eb8c4e5 100644 --- a/shaders/dimensions/all_solid.gsh +++ b/shaders/dimensions/all_solid.gsh @@ -96,6 +96,14 @@ uniform vec3 relativeEyePosition; const float PI48 = 150.796447372*WAVY_SPEED; float pi2wt = PI48*frameTimeCounter; +#if defined VIVECRAFT + uniform bool vivecraftIsVR; + uniform vec3 vivecraftRelativeMainHandPos; + uniform vec3 vivecraftRelativeOffHandPos; + uniform mat4 vivecraftRelativeMainHandRot; + uniform mat4 vivecraftRelativeOffHandRot; +#endif + uniform sampler2D noisetex; vec3 viewToWorld(vec3 viewPosition) { @@ -283,6 +291,19 @@ void main() { float playerDist = smoothstep(0.5, 0.05, length(offsetPos.xz)) * smoothstep(1.0, 0.2, abs(offsetPos.y)); vec2 dir2 = normalize(vertex.xz + relativeEyePosition.xz); + #ifdef VIVECRAFT + float mainHandDist = 0.0; + float offHandDist = 0.0; + + if(vivecraftIsVR) { + offsetPos = vertex + vivecraftRelativeMainHandPos; + mainHandDist = smoothstep(0.125, 0.025, length(offsetPos)); + + offsetPos = vertex + vivecraftRelativeOffHandPos; + offHandDist = smoothstep(0.125, 0.025, length(offsetPos)); + } + #endif + vec2 Wvertex = vertex.xz + cameraPositionFract.xz + mod(vec2(cameraPositionInt.xz), vec2(20.0)); vec2 randomDir = 2.0 * (texture(noisetex, 0.75*Wvertex).xy + texture(noisetex, 0.35*Wvertex.yx).xy) - 1.0; @@ -352,6 +373,13 @@ void main() { vertex.xz += 0.7*playerDist*vec2(dir2)*grassCurvature; + #ifdef VIVECRAFT + if(vivecraftIsVR) { + vertex.xz += mainHandDist*vec2(dir2)*grassCurvature; + vertex.xz += offHandDist*vec2(dir2)*grassCurvature; + } + #endif + vertex.xz += grassCurvature*totalRandBend; vertex += 1.6*calcMovePlants(vertex + cameraPosition)*grassCurvature*grassCurvature; diff --git a/shaders/dimensions/all_translucent.fsh b/shaders/dimensions/all_translucent.fsh index 273a4b0..135af3d 100644 --- a/shaders/dimensions/all_translucent.fsh +++ b/shaders/dimensions/all_translucent.fsh @@ -213,6 +213,14 @@ uniform vec3 relativeEyePosition; #include "/lib/lpv_buffer.glsl" #include "/lib/specular.glsl" +#if defined VIVECRAFT + uniform bool vivecraftIsVR; + uniform vec3 vivecraftRelativeMainHandPos; + uniform vec3 vivecraftRelativeOffHandPos; + uniform mat4 vivecraftRelativeMainHandRot; + uniform mat4 vivecraftRelativeOffHandRot; +#endif + #include "/lib/diffuse_lighting.glsl" #if defined PHYSICSMOD_OCEAN_SHADER diff --git a/shaders/dimensions/composite1.fsh b/shaders/dimensions/composite1.fsh index 8fa19f6..6fc402e 100644 --- a/shaders/dimensions/composite1.fsh +++ b/shaders/dimensions/composite1.fsh @@ -229,6 +229,13 @@ uniform vec3 relativeEyePosition; #define FULLRESDEPTH #include "/lib/specular.glsl" +#if defined VIVECRAFT + uniform bool vivecraftIsVR; + uniform vec3 vivecraftRelativeMainHandPos; + uniform vec3 vivecraftRelativeOffHandPos; + uniform mat4 vivecraftRelativeMainHandRot; + uniform mat4 vivecraftRelativeOffHandRot; +#endif #include "/lib/diffuse_lighting.glsl" #include "/lib/end_fog.glsl" diff --git a/shaders/dimensions/composite3.fsh b/shaders/dimensions/composite3.fsh index 4859f20..8414b7f 100644 --- a/shaders/dimensions/composite3.fsh +++ b/shaders/dimensions/composite3.fsh @@ -330,7 +330,7 @@ vec3 toClipSpace3Prev_DH( vec3 viewSpacePosition, bool depthCheck ) { #endif } -vec4 bilateralUpsample(vec2 fragcoord, sampler2D colortex, out float outerEdgeResults, float referenceDepth, sampler2D depth, bool hand, bool behindTranslucents){ +vec4 bilateralUpsample(vec2 fragcoord, sampler2D colortex, out float outerEdgeResults, float referenceDepth, sampler2D depth, bool hand, const int behindTranslucents){ vec4 colorSum = vec4(0.0); float edgeSum = 0.0; @@ -354,7 +354,10 @@ vec4 bilateralUpsample(vec2 fragcoord, sampler2D colortex, out float outerEdgeRe ivec2 UV_COLOR = ivec2(UV*VL_RENDER_SCALE); ivec2 UV_NOISE = ivec2(gl_FragCoord.xy*texelSize + 1); - ivec2 OFFSET[9] = ivec2[]( + ivec2 depthCoord = UV_DEPTH + UV_NOISE * SCALE; + ivec2 colorCoord = UV_COLOR + UV_NOISE; + + const ivec2 OFFSET[9] = ivec2[9]( ivec2(-1,-1), ivec2( 1, 1), ivec2(-1, 1), @@ -366,23 +369,30 @@ vec4 bilateralUpsample(vec2 fragcoord, sampler2D colortex, out float outerEdgeRe ivec2(-1, 0) ); + const ivec2 OFFSETSCALE[9] = ivec2[9]( + ivec2(-1,-1)*SCALE, + ivec2( 1, 1)*SCALE, + ivec2(-1, 1)*SCALE, + ivec2( 1,-1)*SCALE, + ivec2( 0, 0)*SCALE, + ivec2( 0, 1)*SCALE, + ivec2( 0,-1)*SCALE, + ivec2( 1, 0)*SCALE, + ivec2(-1, 0)*SCALE + ); + for(int i = 0; i < samples; i++) { #if defined DISTANT_HORIZONS || defined VOXY - float offsetDepth; - if(!behindTranslucents) { - offsetDepth = sqrt(texelFetch(depth, UV_DEPTH + (OFFSET[i] + UV_NOISE) * SCALE,0).z/65000.0); - } else { - offsetDepth = sqrt(texelFetch(depth, UV_DEPTH + (OFFSET[i] + UV_NOISE) * SCALE,0).a/65000.0); - } + float offsetDepth = sqrt(texelFetchOffset(depth, depthCoord, 0, OFFSETSCALE[i])[behindTranslucents]/65000.0); #else - float offsetDepth = linearize(texelFetch(depth, UV_DEPTH + (OFFSET[i] + UV_NOISE) * SCALE, 0).r); + float offsetDepth = linearize(texelFetchOffset(depth, depthCoord, 0, OFFSETSCALE[i]).r); #endif float edgeDiff = abs(offsetDepth - referenceDepth) < threshold ? 1.0 : 1e-7; outerEdgeResults = max(outerEdgeResults, abs(referenceDepth - offsetDepth)); - vec4 offsetColor = texelFetch(colortex, UV_COLOR + OFFSET[i] + UV_NOISE, 0).rgba; + vec4 offsetColor = texelFetchOffset(colortex, colorCoord, 0, OFFSET[i]); colorSum += offsetColor*edgeDiff; edgeSum += edgeDiff; @@ -393,13 +403,13 @@ vec4 bilateralUpsample(vec2 fragcoord, sampler2D colortex, out float outerEdgeRe return colorSum / edgeSum; } -vec4 VLTemporalFiltering(vec3 viewPos, in float referenceDepth, sampler2D depth, bool hand){ +vec4 VLTemporalFiltering(vec3 playerPosIn, in float referenceDepth, sampler2D depth, bool hand){ vec2 screenEdges = 2.0/vec2(viewWidth, viewHeight); vec2 offsetTexcoord = clamp(gl_FragCoord.xy*texelSize, screenEdges, 1.0-screenEdges); vec2 VLtexCoord = offsetTexcoord * VL_RENDER_SCALE; // get previous frames position stuff for UV - vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); + vec3 playerPos = playerPosIn + (cameraPosition - previousCameraPosition); vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz; previousPosition = toClipSpace3Prev(previousPosition); @@ -416,7 +426,7 @@ vec4 VLTemporalFiltering(vec3 viewPos, in float referenceDepth, sampler2D depth, // to fill pixel gaps in geometry edges, do a bilateral upsample. // pass a mask to only show upsampled color around the edges of blocks. this is so it doesnt blur reprojected results. float outerEdgeResults = 0.0; - vec4 upsampledCurrentFrame = bilateralUpsample(gl_FragCoord.xy , colortex0, outerEdgeResults, referenceDepth, depth, hand, false); + vec4 upsampledCurrentFrame = bilateralUpsample(gl_FragCoord.xy , colortex0, outerEdgeResults, referenceDepth, depth, hand, 2); // vec4 upsampledCurrentFrame = BilateralUpscale(colortex0, depth, gl_FragCoord.xy - 1.5, referenceDepth); vec4 col1 = texture(colortex0, VLtexCoord + vec2( texelSize.x, texelSize.y)); @@ -622,9 +632,9 @@ void main() { ////// --------------- get volumetrics #if defined DISTANT_HORIZONS || defined VOXY float DH_mixedLinearZ = sqrt(texelFetch(colortex12,ivec2(gl_FragCoord.xy),0).z/65000.0); - vec4 temporallyFilteredVL = VLTemporalFiltering(viewPos, DH_mixedLinearZ, colortex12, hand); + vec4 temporallyFilteredVL = VLTemporalFiltering(playerPos, DH_mixedLinearZ, colortex12, hand); #else - vec4 temporallyFilteredVL = VLTemporalFiltering(viewPos, frDepth, depthtex0, hand); + vec4 temporallyFilteredVL = VLTemporalFiltering(playerPos, frDepth, depthtex0, hand); #endif gl_FragData[2] = temporallyFilteredVL; @@ -789,9 +799,9 @@ void main() { float blank = 0.0; #if defined DISTANT_HORIZONS || defined VOXY DH_mixedLinearZ = sqrt(texelFetch(colortex12,ivec2(gl_FragCoord.xy),0).a/65000.0); - vec4 VLBehindTranslucents = bilateralUpsample(refractedCoord/texelSize, colortex13, blank, DH_mixedLinearZ, colortex12, hand, true); + vec4 VLBehindTranslucents = bilateralUpsample(refractedCoord/texelSize, colortex13, blank, DH_mixedLinearZ, colortex12, hand, 3); #else - vec4 VLBehindTranslucents = bilateralUpsample(refractedCoord/texelSize, colortex13, blank, linearize(texelFetch(depthtex1, ivec2(refractedCoord/texelSize),0).x), depthtex1, hand, true); + vec4 VLBehindTranslucents = bilateralUpsample(refractedCoord/texelSize, colortex13, blank, linearize(texelFetch(depthtex1, ivec2(refractedCoord/texelSize),0).x), depthtex1, hand, 3); #endif ////// --------------- START BLENDING FOGS AND FORWARD RENDERED COLOR diff --git a/shaders/lib/diffuse_lighting.glsl b/shaders/lib/diffuse_lighting.glsl index 99239d5..743b11a 100644 --- a/shaders/lib/diffuse_lighting.glsl +++ b/shaders/lib/diffuse_lighting.glsl @@ -184,14 +184,6 @@ vec3 doIndirectLighting( #ifndef VOXY_PROGRAM uniform float centerDepthSmooth; -#if defined VIVECRAFT - uniform bool vivecraftIsVR; - uniform vec3 vivecraftRelativeMainHandPos; - uniform vec3 vivecraftRelativeOffHandPos; - uniform mat4 vivecraftRelativeMainHandRot; - uniform mat4 vivecraftRelativeOffHandRot; -#endif - vec3 calculateFlashlight(in vec2 texcoord, in vec3 viewPos, in vec3 albedo, in vec3 normal, out vec4 flashLightSpecularData, bool hand){ // vec3 shiftedViewPos = viewPos + vec3(-0.25, 0.2, 0.0);