diff --git a/libraries/entities-renderer/src/paintStroke.slv b/libraries/entities-renderer/src/paintStroke.slv index 769b87f2a9..0cf9596cce 100644 --- a/libraries/entities-renderer/src/paintStroke.slv +++ b/libraries/entities-renderer/src/paintStroke.slv @@ -30,7 +30,7 @@ void main(void) { varTexcoord = inTexCoord0.st; // pass along the diffuse color - varColor = colorToLinearRGBA(inColor); + varColor = color_sRGBAToLinear(inColor); // standard transform diff --git a/libraries/entities-renderer/src/paintStroke_fade.slv b/libraries/entities-renderer/src/paintStroke_fade.slv index 9f10fa5d91..b6075caaf8 100644 --- a/libraries/entities-renderer/src/paintStroke_fade.slv +++ b/libraries/entities-renderer/src/paintStroke_fade.slv @@ -31,7 +31,7 @@ void main(void) { varTexcoord = inTexCoord0.st; // pass along the diffuse color - varColor = colorToLinearRGBA(inColor); + varColor = color_sRGBAToLinear(inColor); // standard transform diff --git a/libraries/gpu/src/gpu/Color.slh b/libraries/gpu/src/gpu/Color.slh index 526cc3dd46..d70e588f4d 100644 --- a/libraries/gpu/src/gpu/Color.slh +++ b/libraries/gpu/src/gpu/Color.slh @@ -11,18 +11,45 @@ <@if not GPU_COLOR_SLH@> <@def GPU_COLOR_SLH@> -float sRGBFloatToLinear(float value) { +// Linear ====> linear RGB +// sRGB ======> standard RGB with gamma of 2.2 +// YCoCg =====> Luma (Y) chrominance green (Cg) and chrominance orange (Co) +// https://software.intel.com/en-us/node/503873 + +float color_scalar_sRGBToLinear(float value) { const float SRGB_ELBOW = 0.04045; return (value <= SRGB_ELBOW) ? value / 12.92 : pow((value + 0.055) / 1.055, 2.4); } -vec3 colorToLinearRGB(vec3 srgb) { - return vec3(sRGBFloatToLinear(srgb.r), sRGBFloatToLinear(srgb.g), sRGBFloatToLinear(srgb.b)); +vec3 color_sRGBToLinear(vec3 srgb) { + return vec3(color_scalar_sRGBToLinear(srgb.r), color_scalar_sRGBToLinear(srgb.g), color_scalar_sRGBToLinear(srgb.b)); } -vec4 colorToLinearRGBA(vec4 srgba) { - return vec4(colorToLinearRGB(srgba.xyz), srgba.w); +vec4 color_sRGBAToLinear(vec4 srgba) { + return vec4(color_sRGBToLinear(srgba.xyz), srgba.w); +} + +vec3 color_LinearToYCoCg(vec3 rgb) { + // Y = R/4 + G/2 + B/4 + // Co = R/2 - B/2 + // Cg = -R/4 + G/2 - B/4 + return vec3( + rgb.x/4.0 + rgb.y/2.0 + rgb.z/4.0, + rgb.x/2.0 - rgb.z/2.0, + -rgb.x/4.0 + rgb.y/2.0 - rgb.z/4.0 + ); +} + +vec3 color_YCoCgToLinear(vec3 ycocg) { + // R = Y + Co - Cg + // G = Y + Cg + // B = Y - Co - Cg + return clamp(vec3( + ycocg.x + ycocg.y - ycocg.z, + ycocg.x + ycocg.z, + ycocg.x - ycocg.y - ycocg.z + ), vec3(0.0), vec3(1.0)); } <@func declareColorWheel()@> diff --git a/libraries/render-utils/src/animdebugdraw.slv b/libraries/render-utils/src/animdebugdraw.slv index ffa44b6cee..3255c6783c 100644 --- a/libraries/render-utils/src/animdebugdraw.slv +++ b/libraries/render-utils/src/animdebugdraw.slv @@ -17,7 +17,7 @@ out vec4 _color; void main(void) { // pass along the color - _color = colorToLinearRGBA(inColor.rgba); + _color = color_sRGBAToLinear(inColor.rgba); TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); diff --git a/libraries/render-utils/src/model.slv b/libraries/render-utils/src/model.slv index 06f6030e77..ccedff9b61 100644 --- a/libraries/render-utils/src/model.slv +++ b/libraries/render-utils/src/model.slv @@ -27,7 +27,7 @@ out vec4 _position; out vec3 _normal; void main(void) { - _color = colorToLinearRGB(inColor.xyz); + _color = color_sRGBToLinear(inColor.xyz); _alpha = inColor.w; TexMapArray texMapArray = getTexMapArray(); diff --git a/libraries/render-utils/src/model_fade.slv b/libraries/render-utils/src/model_fade.slv index 4c6bc534a9..61b8e9e1b6 100644 --- a/libraries/render-utils/src/model_fade.slv +++ b/libraries/render-utils/src/model_fade.slv @@ -28,7 +28,7 @@ out vec3 _normal; out vec3 _color; void main(void) { - _color = colorToLinearRGB(inColor.xyz); + _color = color_sRGBToLinear(inColor.xyz); _alpha = inColor.w; TexMapArray texMapArray = getTexMapArray(); diff --git a/libraries/render-utils/src/model_lightmap.slv b/libraries/render-utils/src/model_lightmap.slv index 161ceed14c..e00fcb708e 100644 --- a/libraries/render-utils/src/model_lightmap.slv +++ b/libraries/render-utils/src/model_lightmap.slv @@ -28,7 +28,7 @@ out vec3 _color; void main(void) { // pass along the color in linear space - _color = colorToLinearRGB(inColor.xyz); + _color = color_sRGBToLinear(inColor.xyz); // and the texture coordinates TexMapArray texMapArray = getTexMapArray(); diff --git a/libraries/render-utils/src/model_lightmap_fade.slv b/libraries/render-utils/src/model_lightmap_fade.slv index 561049d614..d1a1194de1 100644 --- a/libraries/render-utils/src/model_lightmap_fade.slv +++ b/libraries/render-utils/src/model_lightmap_fade.slv @@ -29,7 +29,7 @@ out vec4 _worldPosition; void main(void) { // pass along the color in linear space - _color = colorToLinearRGB(inColor.xyz); + _color = color_sRGBToLinear(inColor.xyz); // and the texture coordinates TexMapArray texMapArray = getTexMapArray(); diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slv b/libraries/render-utils/src/model_lightmap_normal_map.slv index 5fb60d9227..3b1ecaab0c 100644 --- a/libraries/render-utils/src/model_lightmap_normal_map.slv +++ b/libraries/render-utils/src/model_lightmap_normal_map.slv @@ -29,7 +29,7 @@ out vec3 _color; void main(void) { // pass along the color in linear space - _color = colorToLinearRGB(inColor.xyz); + _color = color_sRGBToLinear(inColor.xyz); TexMapArray texMapArray = getTexMapArray(); <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord0)$> diff --git a/libraries/render-utils/src/model_lightmap_normal_map_fade.slv b/libraries/render-utils/src/model_lightmap_normal_map_fade.slv index 4049fb0077..5c1212b1b7 100644 --- a/libraries/render-utils/src/model_lightmap_normal_map_fade.slv +++ b/libraries/render-utils/src/model_lightmap_normal_map_fade.slv @@ -30,7 +30,7 @@ out vec4 _worldPosition; void main(void) { // pass along the color in linear space - _color = colorToLinearRGB(inColor.xyz); + _color = color_sRGBToLinear(inColor.xyz); TexMapArray texMapArray = getTexMapArray(); <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord0)$> diff --git a/libraries/render-utils/src/model_normal_map.slv b/libraries/render-utils/src/model_normal_map.slv index 9e674d93fc..a84f8c5e2a 100644 --- a/libraries/render-utils/src/model_normal_map.slv +++ b/libraries/render-utils/src/model_normal_map.slv @@ -30,7 +30,7 @@ out float _alpha; void main(void) { // pass along the color - _color = colorToLinearRGB(inColor.rgb); + _color = color_sRGBToLinear(inColor.rgb); _alpha = inColor.a; TexMapArray texMapArray = getTexMapArray(); diff --git a/libraries/render-utils/src/model_normal_map_fade.slv b/libraries/render-utils/src/model_normal_map_fade.slv index a71900d5c3..6a6142d317 100644 --- a/libraries/render-utils/src/model_normal_map_fade.slv +++ b/libraries/render-utils/src/model_normal_map_fade.slv @@ -31,7 +31,7 @@ out float _alpha; void main(void) { // pass along the color - _color = colorToLinearRGB(inColor.rgb); + _color = color_sRGBToLinear(inColor.rgb); _alpha = inColor.a; TexMapArray texMapArray = getTexMapArray(); diff --git a/libraries/render-utils/src/overlay3D.slv b/libraries/render-utils/src/overlay3D.slv index ee28367413..7184f923e4 100644 --- a/libraries/render-utils/src/overlay3D.slv +++ b/libraries/render-utils/src/overlay3D.slv @@ -23,7 +23,7 @@ out vec4 _position; out vec3 _normal; void main(void) { - _color = colorToLinearRGB(inColor.xyz); + _color = color_sRGBToLinear(inColor.xyz); _alpha = inColor.w; _texCoord0 = inTexCoord0.st; diff --git a/libraries/render-utils/src/simple.slv b/libraries/render-utils/src/simple.slv index 64d3e24192..0ce6505a65 100644 --- a/libraries/render-utils/src/simple.slv +++ b/libraries/render-utils/src/simple.slv @@ -25,7 +25,7 @@ out vec2 _texCoord0; out vec4 _position; void main(void) { - _color = colorToLinearRGBA(inColor); + _color = color_sRGBAToLinear(inColor); _texCoord0 = inTexCoord0.st; _position = inPosition; _modelNormal = inNormal.xyz; diff --git a/libraries/render-utils/src/simple_fade.slv b/libraries/render-utils/src/simple_fade.slv index 3d9eb2c812..85946045ac 100644 --- a/libraries/render-utils/src/simple_fade.slv +++ b/libraries/render-utils/src/simple_fade.slv @@ -29,7 +29,7 @@ out vec4 _position; out vec4 _worldPosition; void main(void) { - _color = colorToLinearRGBA(inColor); + _color = color_sRGBAToLinear(inColor); _texCoord0 = inTexCoord0.st; _position = inPosition; _modelNormal = inNormal.xyz; diff --git a/libraries/render-utils/src/simple_opaque_web_browser.slf b/libraries/render-utils/src/simple_opaque_web_browser.slf index 3acf104b55..af7ef78682 100644 --- a/libraries/render-utils/src/simple_opaque_web_browser.slf +++ b/libraries/render-utils/src/simple_opaque_web_browser.slf @@ -25,6 +25,6 @@ in vec2 _texCoord0; void main(void) { vec4 texel = texture(originalTexture, _texCoord0.st); - texel = colorToLinearRGBA(texel); + texel = color_sRGBAToLinear(texel); packDeferredFragmentUnlit(normalize(_normal), 1.0, _color.rgb * texel.rgb); } diff --git a/libraries/render-utils/src/simple_textured.slf b/libraries/render-utils/src/simple_textured.slf index 550f6546fd..385270c72c 100644 --- a/libraries/render-utils/src/simple_textured.slf +++ b/libraries/render-utils/src/simple_textured.slf @@ -28,7 +28,7 @@ void main(void) { vec4 texel = texture(originalTexture, _texCoord0); float colorAlpha = _color.a; if (_color.a <= 0.0) { - texel = colorToLinearRGBA(texel); + texel = color_sRGBAToLinear(texel); colorAlpha = -_color.a; } diff --git a/libraries/render-utils/src/simple_textured_fade.slf b/libraries/render-utils/src/simple_textured_fade.slf index 025fe5fca6..75dac714fe 100644 --- a/libraries/render-utils/src/simple_textured_fade.slf +++ b/libraries/render-utils/src/simple_textured_fade.slf @@ -40,7 +40,7 @@ void main(void) { vec4 texel = texture(originalTexture, _texCoord0); float colorAlpha = _color.a; if (_color.a <= 0.0) { - texel = colorToLinearRGBA(texel); + texel = color_sRGBAToLinear(texel); colorAlpha = -_color.a; } diff --git a/libraries/render-utils/src/simple_textured_unlit.slf b/libraries/render-utils/src/simple_textured_unlit.slf index d261fb343a..1daea2f5c7 100644 --- a/libraries/render-utils/src/simple_textured_unlit.slf +++ b/libraries/render-utils/src/simple_textured_unlit.slf @@ -27,7 +27,7 @@ void main(void) { vec4 texel = texture(originalTexture, _texCoord0.st); float colorAlpha = _color.a; if (_color.a <= 0.0) { - texel = colorToLinearRGBA(texel); + texel = color_sRGBAToLinear(texel); colorAlpha = -_color.a; } diff --git a/libraries/render-utils/src/simple_textured_unlit_fade.slf b/libraries/render-utils/src/simple_textured_unlit_fade.slf index 6f03c6746f..b3c5a914b2 100644 --- a/libraries/render-utils/src/simple_textured_unlit_fade.slf +++ b/libraries/render-utils/src/simple_textured_unlit_fade.slf @@ -39,7 +39,7 @@ void main(void) { vec4 texel = texture(originalTexture, _texCoord0.st); float colorAlpha = _color.a; if (_color.a <= 0.0) { - texel = colorToLinearRGBA(texel); + texel = color_sRGBAToLinear(texel); colorAlpha = -_color.a; } diff --git a/libraries/render-utils/src/simple_transparent_textured.slf b/libraries/render-utils/src/simple_transparent_textured.slf index b9eb921e9d..8f0216690f 100644 --- a/libraries/render-utils/src/simple_transparent_textured.slf +++ b/libraries/render-utils/src/simple_transparent_textured.slf @@ -34,7 +34,7 @@ void main(void) { vec4 texel = texture(originalTexture, _texCoord0.st); float opacity = _color.a; if (_color.a <= 0.0) { - texel = colorToLinearRGBA(texel); + texel = color_sRGBAToLinear(texel); opacity = -_color.a; } opacity *= texel.a; diff --git a/libraries/render-utils/src/simple_transparent_textured_fade.slf b/libraries/render-utils/src/simple_transparent_textured_fade.slf index 20c7907bbe..cee443e3be 100644 --- a/libraries/render-utils/src/simple_transparent_textured_fade.slf +++ b/libraries/render-utils/src/simple_transparent_textured_fade.slf @@ -46,7 +46,7 @@ void main(void) { vec4 texel = texture(originalTexture, _texCoord0.st); float opacity = _color.a; if (_color.a <= 0.0) { - texel = colorToLinearRGBA(texel); + texel = color_sRGBAToLinear(texel); opacity = -_color.a; } opacity *= texel.a; diff --git a/libraries/render-utils/src/simple_transparent_textured_unlit.slf b/libraries/render-utils/src/simple_transparent_textured_unlit.slf index 693d7be2db..e9c1104cf0 100644 --- a/libraries/render-utils/src/simple_transparent_textured_unlit.slf +++ b/libraries/render-utils/src/simple_transparent_textured_unlit.slf @@ -29,7 +29,7 @@ void main(void) { vec4 texel = texture(originalTexture, _texCoord0.st); float colorAlpha = _color.a; if (_color.a <= 0.0) { - texel = colorToLinearRGBA(texel); + texel = color_sRGBAToLinear(texel); colorAlpha = -_color.a; } _fragColor0 = vec4(_color.rgb * texel.rgb, colorAlpha * texel.a); diff --git a/libraries/render-utils/src/simple_transparent_textured_unlit_fade.slf b/libraries/render-utils/src/simple_transparent_textured_unlit_fade.slf index 1c42a1f724..093b70755f 100644 --- a/libraries/render-utils/src/simple_transparent_textured_unlit_fade.slf +++ b/libraries/render-utils/src/simple_transparent_textured_unlit_fade.slf @@ -40,7 +40,7 @@ void main(void) { vec4 texel = texture(originalTexture, _texCoord0.st); float colorAlpha = _color.a; if (_color.a <= 0.0) { - texel = colorToLinearRGBA(texel); + texel = color_sRGBAToLinear(texel); colorAlpha = -_color.a; } _fragColor0 = vec4(_color.rgb * texel.rgb+fadeEmissive, colorAlpha * texel.a); diff --git a/libraries/render-utils/src/simple_transparent_web_browser.slf b/libraries/render-utils/src/simple_transparent_web_browser.slf index 19079f5d92..414f3f683f 100644 --- a/libraries/render-utils/src/simple_transparent_web_browser.slf +++ b/libraries/render-utils/src/simple_transparent_web_browser.slf @@ -25,7 +25,7 @@ in vec2 _texCoord0; void main(void) { vec4 texel = texture(originalTexture, _texCoord0.st); - texel = colorToLinearRGBA(texel); + texel = color_sRGBAToLinear(texel); packDeferredFragmentTranslucent( normalize(_normal), _color.a, diff --git a/libraries/render-utils/src/skin_model.slv b/libraries/render-utils/src/skin_model.slv index 4236508edb..46ed45e9be 100644 --- a/libraries/render-utils/src/skin_model.slv +++ b/libraries/render-utils/src/skin_model.slv @@ -36,7 +36,7 @@ void main(void) { skinPositionNormal(inSkinClusterIndex, inSkinClusterWeight, inPosition, inNormal.xyz, position, interpolatedNormal); // pass along the color - _color = colorToLinearRGB(inColor.rgb); + _color = color_sRGBToLinear(inColor.rgb); _alpha = inColor.a; TexMapArray texMapArray = getTexMapArray(); diff --git a/libraries/render-utils/src/skin_model_fade.slv b/libraries/render-utils/src/skin_model_fade.slv index fa8e1f8991..ca4500a18a 100644 --- a/libraries/render-utils/src/skin_model_fade.slv +++ b/libraries/render-utils/src/skin_model_fade.slv @@ -37,7 +37,7 @@ void main(void) { skinPositionNormal(inSkinClusterIndex, inSkinClusterWeight, inPosition, inNormal.xyz, position, interpolatedNormal); // pass along the color - _color = colorToLinearRGB(inColor.rgb); + _color = color_sRGBToLinear(inColor.rgb); _alpha = inColor.a; TexMapArray texMapArray = getTexMapArray(); diff --git a/libraries/render-utils/src/skin_model_normal_map.slv b/libraries/render-utils/src/skin_model_normal_map.slv index 9f1087f87a..3bf057c3c1 100644 --- a/libraries/render-utils/src/skin_model_normal_map.slv +++ b/libraries/render-utils/src/skin_model_normal_map.slv @@ -38,7 +38,7 @@ void main(void) { skinPositionNormalTangent(inSkinClusterIndex, inSkinClusterWeight, inPosition, inNormal.xyz, inTangent.xyz, position, interpolatedNormal.xyz, interpolatedTangent.xyz); // pass along the color - _color = colorToLinearRGB(inColor.rgb); + _color = color_sRGBToLinear(inColor.rgb); _alpha = inColor.a; TexMapArray texMapArray = getTexMapArray(); diff --git a/libraries/render-utils/src/skin_model_normal_map_fade.slv b/libraries/render-utils/src/skin_model_normal_map_fade.slv index 4e638866fc..032ef001d9 100644 --- a/libraries/render-utils/src/skin_model_normal_map_fade.slv +++ b/libraries/render-utils/src/skin_model_normal_map_fade.slv @@ -39,7 +39,7 @@ void main(void) { skinPositionNormalTangent(inSkinClusterIndex, inSkinClusterWeight, inPosition, inNormal.xyz, inTangent.xyz, position, interpolatedNormal.xyz, interpolatedTangent.xyz); // pass along the color - _color = colorToLinearRGB(inColor.rgb); + _color = color_sRGBToLinear(inColor.rgb); _alpha = inColor.a; TexMapArray texMapArray = getTexMapArray(); diff --git a/libraries/render-utils/src/standardTransformPNTC.slv b/libraries/render-utils/src/standardTransformPNTC.slv index 0ced5ba6e2..8ec685cea0 100644 --- a/libraries/render-utils/src/standardTransformPNTC.slv +++ b/libraries/render-utils/src/standardTransformPNTC.slv @@ -24,7 +24,7 @@ out vec4 varColor; void main(void) { varTexCoord0 = inTexCoord0.st; - varColor = colorToLinearRGBA(inColor); + varColor = color_sRGBAToLinear(inColor); // standard transform TransformCamera cam = getTransformCamera(); diff --git a/libraries/render-utils/src/taa.slf b/libraries/render-utils/src/taa.slf index 4b2901b4fb..aa88cc61e2 100644 --- a/libraries/render-utils/src/taa.slf +++ b/libraries/render-utils/src/taa.slf @@ -21,19 +21,15 @@ layout(location = 0) out vec4 outFragColor; void main() { vec3 fragUV = taa_findClosestFragment3x3(varTexCoord0); - vec3 sourceColor = texture(sourceMap, fragUV.xy).xyz; + vec2 fragVel = taa_fetchVelocityMap(fragUV.xy); - vec2 pixVelocity = texture(velocityMap, fragUV.xy).xy; - vec2 velocity = params.motionScale * pixVelocity; - vec2 prevTexCoord = varTexCoord0 - velocity; - - vec3 historyColor = sourceColor; - - if (!(any(lessThan(prevTexCoord, vec2(0.0))) || any(greaterThan(prevTexCoord, vec2(1.0))))) { - historyColor = texture(historyMap, prevTexCoord).xyz; - } + vec3 sourceColor; + vec3 historyColor; + //vec3 nextColor = taa_temporalReprojection(fragUV.xy, fragVel, fragUV.z); + vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV.xy, fragVel, sourceColor, historyColor); vec3 nextColor = mix(historyColor, sourceColor, params.blend); + outFragColor = vec4(nextColor, 1.0); } diff --git a/libraries/render-utils/src/taa.slh b/libraries/render-utils/src/taa.slh index 239d79a275..ad27ae4939 100644 --- a/libraries/render-utils/src/taa.slh +++ b/libraries/render-utils/src/taa.slh @@ -13,6 +13,8 @@ <@include DeferredTransform.slh@> <$declareDeferredFrameTransform()$> +<@include gpu/Color.slh@> + uniform sampler2D depthMap; uniform sampler2D sourceMap; uniform sampler2D historyMap; @@ -41,10 +43,59 @@ float taa_getDebugOrbZoom() { return params.pixelInfo_orbZoom.z; } +vec4 taa_fetchColor(sampler2D map, vec2 uv) { +#if USE_YCOCG + vec4 c = texture(map, uv); + return vec4(color_LinearToYCoCg(c.rgb), c.a); +#else + return texture(map, uv); +#endif +} + +vec3 taa_resolveColor(vec3 color) { +#if USE_YCOCG + return color_YCoCgToLinear(color); +#else + return color; +#endif +} + +vec4 taa_fetchSourceMap(vec2 uv) { +#if USE_YCOCG + vec4 c = texture(sourceMap, uv); + return vec4(color_LinearToYCoCg(c.rgb), c.a); +#else + return texture(sourceMap, uv); +#endif +} + +vec4 taa_fetchHistoryMap(vec2 uv) { +#if USE_YCOCG + vec4 c = texture(historyMap, uv); + return vec4(color_LinearToYCoCg(c.rgb), c.a); +#else + return texture(historyMap, uv); +#endif +} + +vec4 taa_fetchNextMap(vec2 uv) { +#if USE_YCOCG + vec4 c = texture(nextMap, uv); + return vec4(color_LinearToYCoCg(c.rgb), c.a); +#else + return texture(nextMap, uv); +#endif +} + +vec2 taa_fetchVelocityMap(vec2 uv) { + return params.motionScale * texture(velocityMap, uv).xy; +} + float taa_fetchDepth(vec2 uv) { return texture(depthMap, vec2(uv), 0).x; } + #define ZCMP_GT(a, b) (a < b) vec3 taa_findClosestFragment3x3(vec2 uv) @@ -80,8 +131,88 @@ vec3 taa_findClosestFragment3x3(vec2 uv) return vec3(uv + dd.xy * dmin.xy, dmin.z); } +vec2 taa_fetchSourceAndHistory(vec2 fragUV, vec2 fragVelocity, out vec3 sourceColor, out vec3 historyColor) { + sourceColor = taa_fetchSourceMap(fragUV).xyz; + vec2 prevFragUV = fragUV - fragVelocity; + historyColor = sourceColor; + if (!(any(lessThan(prevFragUV, vec2(0.0))) || any(greaterThan(prevFragUV, vec2(1.0))))) { + historyColor = taa_fetchHistoryMap(prevFragUV).xyz; + } + return prevFragUV; +} + +vec3 taa_temporalReprojection(vec2 fragUV, vec2 fragVelocity, float fragZe) +{ + vec3 sourceColor; + vec3 historyColor; + vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV, fragVelocity, sourceColor, historyColor); + + vec3 nextColor = mix(historyColor, sourceColor, params.blend); + + return taa_resolveColor(nextColor); + +/* + const float _SubpixelThreshold = 0.5; + const float _GatherBase = 0.5; + const float _GatherSubpixelMotion = 0.1666; + + float2 texel_vel = ss_vel / _MainTex_TexelSize.xy; + float texel_vel_mag = length(texel_vel) * fragZe; + float k_subpixel_motion = saturate(_SubpixelThreshold / (FLT_EPS + texel_vel_mag)); + float k_min_max_support = _GatherBase + _GatherSubpixelMotion * k_subpixel_motion; + + float2 ss_offset01 = k_min_max_support * float2(-_MainTex_TexelSize.x, _MainTex_TexelSize.y); + float2 ss_offset11 = k_min_max_support * float2(_MainTex_TexelSize.x, _MainTex_TexelSize.y); + float4 c00 = taa_fetchSourceMap(uv - ss_offset11); + float4 c10 = taa_fetchSourceMap(uv - ss_offset01); + float4 c01 = taa_fetchSourceMap(uv + ss_offset01); + float4 c11 = taa_fetchSourceMap(uv + ss_offset11); + + float4 cmin = min(c00, min(c10, min(c01, c11))); + float4 cmax = max(c00, max(c10, max(c01, c11))); + + #if USE_YCOCG || USE_CLIPPING + float4 cavg = (c00 + c10 + c01 + c11) / 4.0; + #endif + + #else + #error "missing keyword MINMAX_..." + #endif + + // shrink chroma min-max + #if USE_YCOCG + float2 chroma_extent = 0.25 * 0.5 * (cmax.r - cmin.r); + float2 chroma_center = texel0.gb; + cmin.yz = chroma_center - chroma_extent; + cmax.yz = chroma_center + chroma_extent; + cavg.yz = chroma_center; + #endif + + // clamp to neighbourhood of current sample + #if USE_CLIPPING + texel1 = clip_aabb(cmin.xyz, cmax.xyz, clamp(cavg, cmin, cmax), texel1); + #else + texel1 = clamp(texel1, cmin, cmax); + #endif + + // feedback weight from unbiased luminance diff (t.lottes) + #if USE_YCOCG + float lum0 = texel0.r; + float lum1 = texel1.r; + #else + float lum0 = Luminance(texel0.rgb); + float lum1 = Luminance(texel1.rgb); + #endif + float unbiased_diff = abs(lum0 - lum1) / max(lum0, max(lum1, 0.2)); + float unbiased_weight = 1.0 - unbiased_diff; + float unbiased_weight_sqr = unbiased_weight * unbiased_weight; + float k_feedback = lerp(_FeedbackMin, _FeedbackMax, unbiased_weight_sqr); + + // output + return lerp(texel0, texel1, k_feedback); + */ +} -<@include gpu/Color.slh@> <$declareColorWheel()$> vec3 taa_getVelocityColorRelative(float velocityPixLength) { diff --git a/libraries/render-utils/src/taa_blend.slf b/libraries/render-utils/src/taa_blend.slf index 3be62353a3..c66957a0ab 100644 --- a/libraries/render-utils/src/taa_blend.slf +++ b/libraries/render-utils/src/taa_blend.slf @@ -66,7 +66,7 @@ void main(void) { vec2 nextOrbPosToPix = pixPos - nextOrbPos; float nextOrbPosToPixLength = length(nextOrbPosToPix); - vec2 prevOrbPos = nextOrbPos + cursorVelocityDir * 2.0 * tenPercentHeight; + vec2 prevOrbPos = nextOrbPos - cursorVelocityDir * 2.0 * tenPercentHeight; vec2 prevOrbPosToPix = pixPos - prevOrbPos; float prevOrbPosToPixLength = length(prevOrbPosToPix); diff --git a/scripts/developer/utilities/render/TestQML/qml_app.js b/scripts/developer/utilities/render/TestQML/qml_app.js deleted file mode 100644 index a563c52b6c..0000000000 --- a/scripts/developer/utilities/render/TestQML/qml_app.js +++ /dev/null @@ -1,99 +0,0 @@ -"use strict"; - -// -// gemstoneMagicMaker.js -// tablet-sample-app -// -// Created by Faye Li on Feb 6 2017. -// Copyright 2017 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -(function() { - var TABLET_BUTTON_NAME = "LUCI"; - var QMLAPP_URL = Script.resolvePath("../antialiasing.qml"); - - - var onLuciScreen = false; - - function onClicked() { - if (onLuciScreen) { - tablet.gotoHomeScreen(); - } else { - tablet.loadQMLSource(QMLAPP_URL); - } - } - - var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); - var button = tablet.addButton({ - text: TABLET_BUTTON_NAME, - sortOrder: 1 - }); - - var hasEventBridge = false; - - function wireEventBridge(on) { - if (!tablet) { - print("Warning in wireEventBridge(): 'tablet' undefined!"); - return; - } - if (on) { - if (!hasEventBridge) { - tablet.fromQml.connect(fromQml); - hasEventBridge = true; - } - } else { - if (hasEventBridge) { - tablet.fromQml.disconnect(fromQml); - hasEventBridge = false; - } - } - } - - function onScreenChanged(type, url) { - if (url === QMLAPP_URL) { - onLuciScreen = true; - } else { - onLuciScreen = false; - } - - button.editProperties({isActive: onLuciScreen}); - wireEventBridge(onLuciScreen); - } - - function fromQml(message) { - } - - button.clicked.connect(onClicked); - tablet.screenChanged.connect(onScreenChanged); - - var moveDebugCursor = false; - Controller.mousePressEvent.connect(function (e) { - if (e.isMiddleButton) { - moveDebugCursor = true; - setDebugCursor(e.x, e.y); - } - }); - Controller.mouseReleaseEvent.connect(function() { moveDebugCursor = false; }); - Controller.mouseMoveEvent.connect(function (e) { if (moveDebugCursor) setDebugCursor(e.x, e.y); }); - - - Script.scriptEnding.connect(function () { - if (onLuciScreen) { - tablet.gotoHomeScreen(); - } - button.clicked.disconnect(onClicked); - tablet.screenChanged.disconnect(onScreenChanged); - tablet.removeButton(button); - }); - - function setDebugCursor(x, y) { - nx = (x / Window.innerWidth); - ny = 1.0 - ((y) / (Window.innerHeight - 32)); - - Render.getConfig("RenderMainView").getConfig("Antialiasing").debugCursorTexcoord = { x: nx, y: ny }; - } - -}()); \ No newline at end of file diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index de7802d723..a369301570 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -12,6 +12,7 @@ import QtQuick.Controls 1.4 import "configSlider" Column { + id: root spacing: 8 property var mainViewTask: Render.getConfig("RenderMainView")