diff --git a/TennisGame/game.uip b/TennisGame/game.uip index 7cb3ccd91676f804784def5198e5dadc72f07de6..5e1093d20f44411330af6b96fb77c30aec14f45f 100644 --- a/TennisGame/game.uip +++ b/TennisGame/game.uip @@ -4,92 +4,672 @@ #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + - - - + + - - - - + + + + + + - + + + + - - - + - - - + - + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + - - - - - - - - + + + + + + + @@ -97,33 +677,118 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - + - + - + + + + + + + 0 0.294118 100 100 1 0.294118 100 100 + 0 0.294118 100 100 1 0.294118 100 100 + 0 0.294118 100 100 1 0.294118 100 100 + + + + + + 0 1 100 100 0.3 0.294118 100 100 + 0 1 100 100 0.3 0.294118 100 100 + 0 1 100 100 0.3 0.294118 100 100 + + + + + + + + 0 100 100 100 1 100 100 100 + + + + + 0 300 100 100 1 100 100 100 + + + + + + + + + + 0 0.3 100 100 1 0.3 100 100 + 0 0.3 100 100 1 0.3 100 100 + 0 0.5 100 100 1 0.5 100 100 + + + + + + 0 0.714285 100 100 0.4 0.3 100 100 + 0 0.698413 100 100 0.4 0.3 100 100 + 0 1 100 100 0.4 0.5 100 100 + + + + diff --git a/TennisGame/maps/Cork1.png b/TennisGame/maps/Cork1.png deleted file mode 100644 index b27b27d40ce9fe5146d8e49da42a68c9b5ec6384..0000000000000000000000000000000000000000 Binary files a/TennisGame/maps/Cork1.png and /dev/null differ diff --git a/TennisGame/maps/Wood7.png b/TennisGame/maps/Wood7.png deleted file mode 100644 index 9d9a219a459b4176ba1a95d8897f6788c9604527..0000000000000000000000000000000000000000 Binary files a/TennisGame/maps/Wood7.png and /dev/null differ diff --git a/TennisGame/maps/lines.png b/TennisGame/maps/lines.png new file mode 100644 index 0000000000000000000000000000000000000000..f4cdc0688e0af37248794bb0848bbf2dfd7ae08b Binary files /dev/null and b/TennisGame/maps/lines.png differ diff --git a/TennisGame/scripts/CameraLookAt.qml b/TennisGame/scripts/CameraLookAt.qml new file mode 100644 index 0000000000000000000000000000000000000000..087ddac67e46238e59b91d3ba31b133356933571 --- /dev/null +++ b/TennisGame/scripts/CameraLookAt.qml @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*[[ + + + + + +]]*/ + +import QtStudio3D.Behavior 1.0 + +Behavior { + //External: + property string cameraTarget + property bool startImmediately + //Internal: + property bool running: false + property var updateFunction + + function start() { + running = true; + } + function stop() { + running = false; + } + onInitialize: { + if (startImmediately) + start(); + } + onUpdate: { + if (!running) + return; + var targetTransform = calculateGlobalTransform(cameraTarget); + var targetSpot = targetTransform.row(3).toVector3d(); + var cameraTransform = calculateGlobalTransform(); + var cameraSpot = cameraTransform.row(3).toVector3d(); + + var matrix = calculateGlobalTransform(getParent()).inverted(); + matrix.m41 = 0; + matrix.m42 = 0; + matrix.m43 = 0; + + var rotateRay = targetSpot + .minus(cameraSpot) + .times(matrix); + + var rotation = lookAt(rotateRay); + setAttributeVector("rotation", rotation); + setAttributeVector("position", cameraSpot); + } + + function getAttributeVector(name) { + var vec = Qt.vector3d(0, 0, 0); + getAttribute(name + ".x", vec.x); + getAttribute(name + ".y", vec.y); + getAttribute(name + ".z", vec.z); + return vec; + } + + function setAttributeVector(name, vec) { + setAttribute(name + ".x", vec.x); + setAttribute(name + ".y", vec.y); + setAttribute(name + ".z", vec.z); + } +} diff --git a/TennisGame/scripts/CopyTransform.qml b/TennisGame/scripts/CopyTransform.qml new file mode 100644 index 0000000000000000000000000000000000000000..576459c4a80fabcab0771eebe7ac82b6d4514337 --- /dev/null +++ b/TennisGame/scripts/CopyTransform.qml @@ -0,0 +1,254 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*[[ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]]*/ + +import QtStudio3D.Behavior 1.0 + +Behavior { + //External: + property string targetObject + property bool offsetMode + property bool startImmediately + property bool posMode + property bool posX + property bool posY + property bool posZ + property bool rotMode + property bool rotX + property bool rotY + property bool rotZ + property bool sclMode + property bool sclX + property bool sclY + property bool sclZ + //Internal: + property bool running: false + property var updateFunction + property var offsetAmount + property var startRotation + property var startScale + property var startPosition + property var targetStartScale + property var scaleRatio + + function start() { + running = true; + } + function stop() { + running = false; + } + onInitialize: { + var targetTransform = calculateGlobalTransform(targetObject); + var position = targetTransform.row(3).toVector3d(); + var thisTransform = calculateGlobalTransform(); + var startRotMatrix = transformToRotationMatrix(thisTransform); + startScale = calculateScale(thisTransform); + startRotation = matrixToEuler(startRotMatrix); + startPosition = thisTransform.row(3).toVector3d(); + targetStartScale = calculateScale(targetTransform); + offsetAmount = startPosition.minus(position); + + var startx = startScale.x/targetStartScale.x; + var starty = startScale.y/targetStartScale.y; + var startz = startScale.z/targetStartScale.z; + + scaleRatio = Qt.vector3d(startx,starty,startz); + + if (offsetMode) updateFunction = copyTransformOffset; + else updateFunction = copyTransformParent; + if (startImmediately) start(); + } + onUpdate: { + if (!running) + return; + updateFunction(); + } + function copyTransformParent(){ + var thisTransform = calculateGlobalTransform(); + var thisPosition = thisTransform.row(3).toVector3d(); + var targetTransform = calculateGlobalTransform(targetObject); + var targetPosition = targetTransform.row(3).toVector3d(); + if (sclMode) { + var targetScale = calculateScale(targetTransform); + var resultscale = targetScale; + if (!sclX) resultscale.x = startScale.x; + if (!sclY) resultscale.y = startScale.y; + if (!sclZ) resultscale.z = startScale.z; + setAttributeVector("scale", resultscale); + } + if (rotMode) { + var thisRotation = matrixToEuler(transformToRotationMatrix((thisTransform))); + var targetRotation = matrixToEuler(transformToRotationMatrix(targetTransform)); + var resultrotation = targetRotation; + if (!rotX) resultrotation.x = startRotation.x; + if (!rotY) resultrotation.y = startRotation.y; + if (!rotZ) resultrotation.z = startRotation.z; + setAttributeVector("rotation",resultrotation ); + } + if (posMode) { + var resultposition = targetPosition; + if (!posX) resultposition.x = startPosition.x; + if (!posY) resultposition.y = startPosition.y; + if (!posZ) resultposition.z = startPosition.z; + setAttributeVector("position", resultposition); + console.log(resultposition.x); + } + } + function copyTransformOffset(){ + var thisTransform = calculateGlobalTransform(); + var thisPosition = thisTransform.row(3).toVector3d(); + var targetTransform = calculateGlobalTransform(targetObject); + var targetPosition = targetTransform.row(3).toVector3d(); + if (sclMode) { + var targetScale = calculateScale(targetTransform); + var scaleOffset = targetScale.minus(targetStartScale); + var resultscale = startScale.plus(scaleOffset.times(scaleRatio)); + if (!sclX) resultscale.x = startScale.x; + if (!sclY) resultscale.y = startScale.y; + if (!sclZ) resultscale.z = startScale.z; + setAttributeVector("scale", resultscale); + } + if (rotMode) { + var targetRotation = matrixToEuler(transformToRotationMatrix(targetTransform)); + var resultrotation = startRotation.plus(targetRotation); + if (!rotX) resultrotation.x = startRotation.x; + if (!rotY) resultrotation.y = startRotation.y; + if (!rotZ) resultrotation.z = startRotation.z; + setAttributeVector("rotation",resultrotation ); + } + if (posMode) { + var resultposition = targetPosition.plus(offsetAmount); + if (!posX) resultposition.x = startPosition.x; + if (!posY) resultposition.y = startPosition.y; + if (!posZ) resultposition.z = startPosition.z; + setAttributeVector("position", resultposition); + } + } + function calculateScale(transForm){ + var VecScaleX = transForm.row(0).toVector3d(); + var TargetX = VecScaleX.length(); + var VecScaleY = transForm.row(1).toVector3d(); + var TargetY = VecScaleY.length(); + var VecScaleZ = transForm.row(2).toVector3d(); + var TargetZ = VecScaleZ.length(); + var result = Qt.vector3d(TargetX,TargetY,TargetZ); + return result; + } + function transformToRotationMatrix(transForm){ + var rotationMatrix = transForm; + var VecScaleX = transForm.row(0).toVector3d(); + var TargetX = VecScaleX.length(); + var VecScaleY = transForm.row(1).toVector3d(); + var TargetY = VecScaleY.length(); + var VecScaleZ = transForm.row(2).toVector3d(); + var TargetZ = VecScaleZ.length(); + var result = Qt.vector3d(TargetX,TargetY,TargetZ); + + rotationMatrix.m11 = transForm.m11/TargetX; + rotationMatrix.m12 = transForm.m12/TargetX; + rotationMatrix.m13 = transForm.m13/TargetX; + rotationMatrix.m21 = transForm.m21/TargetY; + rotationMatrix.m22 = transForm.m22/TargetY; + rotationMatrix.m23 = transForm.m23/TargetY; + rotationMatrix.m31 = transForm.m31/TargetZ; + rotationMatrix.m32 = transForm.m32/TargetZ; + rotationMatrix.m33 = transForm.m33/TargetZ; + return rotationMatrix; + } + function getAttributeVector(name) { + var vec = Qt.vector3d(0, 0, 0); + getAttribute(name + ".x", vec.x); + getAttribute(name + ".y", vec.y); + getAttribute(name + ".z", vec.z); + return vec; + } + function setAttributeVector(name, vec) { + setAttribute(name + ".x", vec.x); + setAttribute(name + ".y", vec.y); + setAttribute(name + ".z", vec.z); + } +} diff --git a/TennisGame/scripts/Corona.effect b/TennisGame/scripts/Corona.effect new file mode 100644 index 0000000000000000000000000000000000000000..1097ceb6501eb260f8b0a0f54662d3bfffc5de94 --- /dev/null +++ b/TennisGame/scripts/Corona.effect @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + +#include "blur.glsllib" +uniform float AppFrame; // frame number since app starts +uniform float FPS; + + + +varying vec2 crawl; // corona crawl direction and magnitude + + +void vert () +{ + SetupHorizontalGaussianBlur(Texture0Info.x, HBlurBias, TexCoord); + // compute crawl + float alpha = radians(CrawlAngle + 180.0); + crawl = vec2(CrawlLen * sin(alpha), CrawlLen * cos(alpha)); +} + + +void frag() +{ + //Passing in 1.0 means the value will not get alpha-multiplied again + float OutCol = GaussianAlphaBlur( GlowSampler, 1.0 ); + OutCol *= Trailfade; // fade away glow color + OutCol += texture2D_0( TexCoord ).a; // add glow color in the original tex area + + vec2 nuv = NoiseScale * TexCoord3 + AppFrame / FPS * crawl; + vec4 noise = texture2D_NoiseSamp(fract(nuv)); + float ns = (1.0 - NoiseRatio) + NoiseRatio * NoiseBright * noise.x; + OutCol *= ns; + gl_FragColor = vec4( OutCol ); +} + + + + +void vert () +{ + SetupVerticalGaussianBlur( Texture0Info.y, VBlurBias, TexCoord ); +} + + +void frag() // PS_Blur_Vertical_9tap +{ + float OutCol = GaussianAlphaBlur( Texture0, Texture0Info.z ); + gl_FragColor = OutCol * vec4(GlowCol, 1.0); +} + + + + +void vert() +{ +} + + +void frag () +{ + vec4 src = texture2D_0( TexCoord ); + vec4 dst = texture2D_Sprite(TexCoord); + colorOutput( src * (1.0 - dst.a) + dst ); +} + + + + + + + + + + + + + + + + + diff --git a/TennisGame/scripts/Edge Detect.effect b/TennisGame/scripts/Edge Detect.effect new file mode 100644 index 0000000000000000000000000000000000000000..2b200d005730357dba0073084775945f2d42b7ab --- /dev/null +++ b/TennisGame/scripts/Edge Detect.effect @@ -0,0 +1,81 @@ + + + + + + + + +//////////////////////////////////////////////////////////// +// vert / frag shaders. + +varying vec4 TexCoordBLL; //Bottom Left and Bottom Tap +varying vec4 TexCoordTLT; //Top Left and Top Tap +varying vec4 TexCoordTRR; //Upper Right and Right Tap +varying vec4 TexCoordBRB; //Bottom Right and Bottom Tap + + + +void vert() +{ + //Pass Through the Texture Taps + float deltax = 1.0/Texture0Info.x; + float deltay = 1.0/Texture0Info.y; + + //Bottom Left + TexCoordBLL.x = TexCoord.s - deltax; + TexCoordBLL.y = TexCoord.t - deltay; + + //Left + TexCoordBLL.z = TexCoord.s - deltax; + TexCoordBLL.w = TexCoord.t; + + //Top Left + TexCoordTLT.x = TexCoord.s - deltax; + TexCoordTLT.y = TexCoord.t + deltay; + + //Top + TexCoordTLT.z = TexCoord.s; + TexCoordTLT.w = TexCoord.t + deltay; + + //Upper Right + TexCoordTRR.x = TexCoord.s + deltax; + TexCoordTRR.y = TexCoord.t + deltay; + + //Right + TexCoordTRR.z = TexCoord.s + deltax; + TexCoordTRR.w = TexCoord.t; + + //Bottom Right + TexCoordBRB.x = TexCoord.s + deltax; + TexCoordBRB.y = TexCoord.t - deltay; + + //Bottom + TexCoordBRB.z = TexCoord.s; + TexCoordBRB.w = TexCoord.t - deltay; +} + + +void frag (void) +{ + vec4 centerTap = texture2D_0(TexCoord); + vec4 edgeTap = texture2D_0(TexCoordBLL.xy) + + texture2D_0(TexCoordBLL.zw) + + texture2D_0(TexCoordTLT.xy) + + texture2D_0(TexCoordTLT.zw) + + texture2D_0(TexCoordTRR.xy) + + texture2D_0(TexCoordTRR.zw) + + texture2D_0(TexCoordBRB.xy) + + texture2D_0(TexCoordBRB.zw); + vec3 edgeDetect = 8.0*(centerTap.rgb + -0.125*edgeTap.rgb); + edgeDetect = clamp(edgeDetect, 0.0, centerTap.a); + + colorOutput(vec4(mix(centerTap.rgb, edgeDetect, amount), centerTap.a)); +} + + + + + + + diff --git a/TennisGame/scripts/HDRBloomTonemap.effect b/TennisGame/scripts/HDRBloomTonemap.effect new file mode 100644 index 0000000000000000000000000000000000000000..4424393b655eb84632682a8f4ae26864d432145b --- /dev/null +++ b/TennisGame/scripts/HDRBloomTonemap.effect @@ -0,0 +1,282 @@ + + + + + + + + + + + + +#include "blur.glsllib" +#include "luminance.glsllib" +float get_blur_falloff() { return exp2( -BlurFalloff ); } +float get_exposure() { return exp2( Exposure ); } + + + +vec2 ToRotatedPoissonTexCoord( vec3 poisson, vec2 inputTex, vec2 inc, mat2 rotation ) +{ + vec2 rotatedPoisson = rotation * vec2( poisson.xy ); + return vec2( inputTex.x + rotatedPoisson.x * inc.x, inputTex.y + rotatedPoisson.y * inc.y ); +} + +void SetupPoissonBlurCoordsRotation(float inBlurAmount, vec2 inTexInfo, float inRotationRadians ) +{ + float incX = inBlurAmount / inTexInfo.x; + float incY = inBlurAmount / inTexInfo.y; + float rotCos = cos( inRotationRadians ); + float rotSin = sin( inRotationRadians ); + mat2 rotMatrix = mat2( rotCos, rotSin, -rotSin, rotCos ); + vec2 incVec = vec2( incX, incY ); + + TexCoord0 = ToRotatedPoissonTexCoord( poisson0, TexCoord, incVec, rotMatrix ); + TexCoord1 = ToRotatedPoissonTexCoord( poisson1, TexCoord, incVec, rotMatrix ); + TexCoord2 = ToRotatedPoissonTexCoord( poisson2, TexCoord, incVec, rotMatrix ); + TexCoord3 = ToRotatedPoissonTexCoord( poisson3, TexCoord, incVec, rotMatrix ); + TexCoord4 = ToRotatedPoissonTexCoord( poisson4, TexCoord, incVec, rotMatrix ); + TexCoord5 = ToRotatedPoissonTexCoord( poisson5, TexCoord, incVec, rotMatrix ); + TexCoord6 = ToRotatedPoissonTexCoord( poisson6, TexCoord, incVec, rotMatrix ); + TexCoord7 = ToRotatedPoissonTexCoord( poisson7, TexCoord, incVec, rotMatrix ); +} +// No op +void vert () +{ + SetupPoissonBlurCoordsRotation( 5.0 * get_blur_falloff(), Texture0Info.xy, 0.0); +} + + + +float cutoff( float color ) +{ + return color >= BloomThreshold ? color : 0.0; +} +vec4 cutoffColor( sampler2D inSampler, vec2 texCoord ) +{ + vec4 color = GetTextureValue(inSampler, texCoord, 1.0); + vec3 exposed_color = color.xyz * get_exposure(); + vec3 cutoff_color = vec3( cutoff( color.x ), cutoff( color.y ), cutoff( color.z ) ); + float pixelMult = dot( cutoff_color, cutoff_color ) > 0.0 ? 1.0 : 0.0; + return vec4( exposed_color.xyz, color.a ) * pixelMult; +} + +vec4 PoissonBlur(sampler2D inSampler ) +{ + //flatten out the poisson for this step, we really just want to smear. + float mult0 = 1.0; + float mult1 = mult0; + float mult2 = mult0; + float mult3 = mult2; + float mult4 = mult2; + float mult5 = mult2; + float mult6 = mult2; + float mult7 = mult2; + + float multTotal = mult0 + mult1 + mult2 + mult3 + mult4 + mult5 + mult6 + mult7; + float multMultiplier = ( multTotal > 0.0 ? 1.0 / multTotal : 0.0 ); + + vec4 outColor = cutoffColor( inSampler, TexCoord0 ) * (mult0 * multMultiplier); + outColor += cutoffColor( inSampler, TexCoord1 ) * (mult1 * multMultiplier); + outColor += cutoffColor( inSampler, TexCoord2 ) * (mult2 * multMultiplier); + outColor += cutoffColor( inSampler, TexCoord3 ) * (mult3 * multMultiplier); + outColor += cutoffColor( inSampler, TexCoord4 ) * (mult4 * multMultiplier); + outColor += cutoffColor( inSampler, TexCoord5 ) * (mult5 * multMultiplier); + outColor += cutoffColor( inSampler, TexCoord6 ) * (mult6 * multMultiplier); + outColor += cutoffColor( inSampler, TexCoord7 ) * (mult7 * multMultiplier); + return outColor; +} + +void frag() // Luminosity pass with exponential color channel decay based on the threshold above. +{ + gl_FragColor = PoissonBlur( Texture0 ); +} + + + + + +vec2 ToRotatedPoissonTexCoord( vec3 poisson, vec2 inputTex, vec2 inc, mat2 rotation ) +{ + vec2 rotatedPoisson = rotation * vec2( poisson.xy ); + return vec2( inputTex.x + rotatedPoisson.x * inc.x, inputTex.y + rotatedPoisson.y * inc.y ); +} + +void SetupPoissonBlurCoordsRotation(float inBlurAmount, vec2 inTexInfo, float inRotationRadians ) +{ + float incX = inBlurAmount / inTexInfo.x; + float incY = inBlurAmount / inTexInfo.y; + float rotCos = cos( inRotationRadians ); + float rotSin = sin( inRotationRadians ); + mat2 rotMatrix = mat2( rotCos, rotSin, -rotSin, rotCos ); + vec2 incVec = vec2( incX, incY ); + + TexCoord0 = ToRotatedPoissonTexCoord( poisson0, TexCoord, incVec, rotMatrix ); + TexCoord1 = ToRotatedPoissonTexCoord( poisson1, TexCoord, incVec, rotMatrix ); + TexCoord2 = ToRotatedPoissonTexCoord( poisson2, TexCoord, incVec, rotMatrix ); + TexCoord3 = ToRotatedPoissonTexCoord( poisson3, TexCoord, incVec, rotMatrix ); + TexCoord4 = ToRotatedPoissonTexCoord( poisson4, TexCoord, incVec, rotMatrix ); + TexCoord5 = ToRotatedPoissonTexCoord( poisson5, TexCoord, incVec, rotMatrix ); + TexCoord6 = ToRotatedPoissonTexCoord( poisson6, TexCoord, incVec, rotMatrix ); + TexCoord7 = ToRotatedPoissonTexCoord( poisson7, TexCoord, incVec, rotMatrix ); +} + +void vert () +{ + SetupPoissonBlurCoordsRotation( PoissonDistance, Texture0Info.xy, PoissonRotation); +} + + +vec4 PoissonBlur(sampler2D inSampler ) +{ + float mult0 = (1.0 - poisson0.z); + float mult1 = (1.0 - poisson1.z); + float mult2 = (1.0 - poisson2.z); + float mult3 = (1.0 - poisson3.z); + float mult4 = (1.0 - poisson4.z); + float mult5 = (1.0 - poisson5.z); + float mult6 = (1.0 - poisson6.z); + float mult7 = (1.0 - poisson7.z); + + float multTotal = mult0 + mult1 + mult2 + mult3 + mult4 + mult5 + mult6 + mult7; + float multMultiplier = ( multTotal > 0.0 ? 1.0 / multTotal : 0.0 ) * get_blur_falloff(); + + vec4 outColor = GetTextureValue( inSampler, TexCoord0, 1.0 ) * (mult0 * multMultiplier); + outColor += GetTextureValue( inSampler, TexCoord1, 1.0 ) * (mult1 * multMultiplier); + outColor += GetTextureValue( inSampler, TexCoord2, 1.0 ) * (mult2 * multMultiplier); + outColor += GetTextureValue( inSampler, TexCoord3, 1.0 ) * (mult3 * multMultiplier); + outColor += GetTextureValue( inSampler, TexCoord4, 1.0 ) * (mult4 * multMultiplier); + outColor += GetTextureValue( inSampler, TexCoord5, 1.0 ) * (mult5 * multMultiplier); + outColor += GetTextureValue( inSampler, TexCoord6, 1.0 ) * (mult6 * multMultiplier); + outColor += GetTextureValue( inSampler, TexCoord7, 1.0 ) * (mult7 * multMultiplier); + return outColor; +} + +void frag() +{ + //Passing in 1.0 means the value will not get alpha-multiplied again + gl_FragColor = PoissonBlur( Texture0 ); +} + + + + + /* + +float GetAdaptedLuminance( sampler2D inSampler ) +{ + + vec3 col = textureLod( inSampler, TexCoord, TonemappingLod).rgb; + return luminance( col ); +} + +vec3 GetTonemappedReinhard( sampler2D inSampler, vec3 inSource, vec3 inBlurred ) +{ + // adapted luminance value + float adpLm = GetAdaptedLuminance( inSampler ); + // luminance of current color + float curLm = luminance( inSource.rgb ); + // relative luminance + float relLm = Key/adpLm; + // displayable value D + float D = (relLm * (1.0 + relLm/(expLum*expLum)) / (1.0 + relLm)); + // tone map result + vec3 color = inBlurred.xyz * relLm; + //vec3 gamaColor = pow(color, vec3(1.0/2.2)); + + //return gamaColor; + return vec3(relLm, relLm, relLm ); +} + +vec3 GetTonemappedReinhardSimple( vec3 inSource, vec3 inBlurred ) +{ + vec3 texColor = inBlurred * 1.0; // Hardcoded Exposure Adjustment + texColor = texColor/(1.0 + texColor); + vec3 retColor = pow( texColor, vec3(1.0/2.2) ); + return retColor; +} +*/ + +void frag() +{ + vec4 sourceColor = texture2D_0(TexCoord); + + + vec4 summation = texture2D_Downsample2(TexCoord) + + texture2D_Downsample4(TexCoord); + + vec3 bloom_result = sourceColor.xyz * get_exposure() + summation.xyz; + + //Threshold defines the white point for the image which shouldn't be adaptive. + vec3 thresholded = clamp( bloom_result.xyz, 0.0, ChannelThreshold ) / ChannelThreshold; + + vec3 tonemapped = pow( thresholded, vec3( 1.0 / GammaValue ) ); + + vec3 final_color = mix( thresholded, tonemapped, TonemappingLerp ); + + float resultAlpha = max( summation.a, sourceColor.a ); + + gl_FragColor = vec4( final_color, resultAlpha ); + + /* + gl_FragColor = vec4( texture2D_Downsample2(TexCoord).xyz + , 1.0 ); + */ +} + + + + +void vert () +{ +} + + +void frag() +{ + //Passing in 1.0 means the value will not get alpha-multiplied again + gl_FragColor = GetTextureValue( Texture0, TexCoord, 1.0 ); +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TennisGame/scripts/Movement.qml b/TennisGame/scripts/Movement.qml index fb9cef4b2f0bbc32ec23bb10868fba9f8e514373..176c9e54a1b1cd6142c060f9984feabd088729e6 100644 --- a/TennisGame/scripts/Movement.qml +++ b/TennisGame/scripts/Movement.qml @@ -16,6 +16,7 @@ + ]]*/ import QtStudio3D.Behavior 1.0 @@ -76,7 +77,7 @@ Behavior { var perspectiveFactor = 1; var halfScreenHeight = 360; var target = (halfScreenHeight - getMousePosition().y) * perspectiveFactor; - if (Math.abs(position.y - target) > 6) { + if (Math.abs(position.y - target) > 1) { if (position.y > target) moveDown(); else @@ -96,7 +97,7 @@ Behavior { //Handle AI movement input var obstacleTransform = calculateGlobalTransform(obstacle1); var obstaclePosition = obstacleTransform.row(3).toVector3d(); - if (Math.abs(obstaclePosition.y - position.y) > 25) + if (Math.abs(obstaclePosition.y - position.y) > 20) input.y = Math.sign(obstaclePosition.y - position.y); else input.y = 0; @@ -137,6 +138,7 @@ Behavior { } else { //Change ball direction and the angle if collision happens if (hasPhysics) { + fireEvent("ballCollision"); direction.x = -direction.x; direction.y = -Math.sin(Math.atan2(collisionPosition.y - position.y, collisionPosition.x - position.x)); @@ -149,6 +151,7 @@ Behavior { } else { if (hasPhysics) + fireEvent("ballCollision"); direction.y = -direction.y; } } diff --git a/TennisGame/scripts/Score.qml b/TennisGame/scripts/Score.qml index 02308739e2cf3345602475d7d11aad17445d6a07..0cf1ab1d4484a160321275648f8cd811b766a586 100644 --- a/TennisGame/scripts/Score.qml +++ b/TennisGame/scripts/Score.qml @@ -1,8 +1,12 @@ /*[[ + + + + ]]*/ @@ -12,9 +16,13 @@ import QtStudio3D.Behavior 1.0 Behavior { property var playerScore: 0 property var computerScore: 0 + property var isplayerScore: false onUpdate: { - setAttribute("textstring", playerScore + " - " + computerScore); + if(isplayerScore === true) + setAttribute("textstring", playerScore.toFixed()); + else + setAttribute("textstring", computerScore.toFixed()); } function addPlayerScore() { @@ -34,3 +42,4 @@ Behavior { computerScore = 0; } } + diff --git a/TennisGame/scripts/VignetteEffect.effect b/TennisGame/scripts/VignetteEffect.effect new file mode 100644 index 0000000000000000000000000000000000000000..a4591208ac8b32b479a91e4fafd32cca32ae8f70 --- /dev/null +++ b/TennisGame/scripts/VignetteEffect.effect @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + +