Kaydet (Commit) b3ce63e5 authored tarafından Emmanuel Gil Peyrot's avatar Emmanuel Gil Peyrot Kaydeden (comit) Tomaž Vajngerl

slideshow: Reimplement reflections in shaders, and port Rochade and TurnAround

This removes the hack reflections were previously, where a black quad
was drawn on top of a mirror version of the first primitive only.

Change-Id: I8c0863ab30e85d0130a8d7e838f3514e9be93788
üst f62990a8
...@@ -15,6 +15,8 @@ $(eval $(call gb_Package_add_files,slideshow_opengl_shader,$(LIBO_ETC_FOLDER)/op ...@@ -15,6 +15,8 @@ $(eval $(call gb_Package_add_files,slideshow_opengl_shader,$(LIBO_ETC_FOLDER)/op
dissolveFragmentShader.glsl \ dissolveFragmentShader.glsl \
fadeBlackFragmentShader.glsl \ fadeBlackFragmentShader.glsl \
fadeFragmentShader.glsl \ fadeFragmentShader.glsl \
reflectionVertexShader.glsl \
reflectionFragmentShader.glsl \
staticFragmentShader.glsl \ staticFragmentShader.glsl \
vortexFragmentShader.glsl \ vortexFragmentShader.glsl \
vortexVertexShader.glsl \ vortexVertexShader.glsl \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2015 by Collabora, Ltd.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#version 130
uniform sampler2D slideTexture;
varying float v_isShadow;
varying vec2 v_texturePosition;
void main() {
vec4 fragment = texture2D(slideTexture, v_texturePosition);
if (v_isShadow > 0.5) {
if (v_texturePosition.y > 1.0 - 0.3)
gl_FragColor = mix(fragment, vec4(0.0, 0.0, 0.0, 0.0), (1.0 - v_texturePosition.y) / 0.3);
else
discard;
} else {
gl_FragColor = fragment;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#version 130
varying float v_isShadow;
varying vec2 v_texturePosition;
void main( void )
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
v_texturePosition = gl_MultiTexCoord0.xy;
v_isShadow = float(gl_VertexID >= 6);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -93,53 +93,6 @@ void OGLTransitionImpl::finish() ...@@ -93,53 +93,6 @@ void OGLTransitionImpl::finish()
finishTransition(); finishTransition();
} }
static void blendSlide( double depth )
{
CHECK_GL_ERROR();
double showHeight = -1 + depth*2;
GLfloat reflectionColor[] = {0, 0, 0, 0.25};
glDisable( GL_DEPTH_TEST );
glBegin( GL_QUADS );
glColor4fv( reflectionColor );
glVertex3f( -1, -1, 0 );
glColor4f( 0, 0, 0, 1 );
glVertex3f(-1, showHeight, 0 );
glVertex3f( 1, showHeight, 0 );
glColor4fv( reflectionColor );
glVertex3f( 1, -1, 0 );
glEnd();
glBegin( GL_QUADS );
glColor4f( 0, 0, 0, 1 );
glVertex3f( -1, showHeight, 0 );
glVertex3f( -1, 1, 0 );
glVertex3f( 1, 1, 0 );
glVertex3f( 1, showHeight, 0 );
glEnd();
glEnable( GL_DEPTH_TEST );
CHECK_GL_ERROR();
}
static void slideShadow( double nTime, const Primitive& primitive, double sw, double sh )
{
CHECK_GL_ERROR();
double reflectionDepth = 0.3;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_LIGHTING);
glPushMatrix();
primitive.applyOperations( nTime, sw, sh );
blendSlide( reflectionDepth );
glPopMatrix();
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
CHECK_GL_ERROR();
}
void OGLTransitionImpl::prepare( double, double, double, double, double ) void OGLTransitionImpl::prepare( double, double, double, double, double )
{ {
} }
...@@ -256,33 +209,8 @@ OGLTransitionImpl::displaySlide( ...@@ -256,33 +209,8 @@ OGLTransitionImpl::displaySlide(
double SlideWidthScale, double SlideHeightScale ) double SlideWidthScale, double SlideHeightScale )
{ {
CHECK_GL_ERROR(); CHECK_GL_ERROR();
//TODO change to foreach
glBindTexture(GL_TEXTURE_2D, glSlideTex); glBindTexture(GL_TEXTURE_2D, glSlideTex);
CHECK_GL_ERROR(); CHECK_GL_ERROR();
// display slide reflection
// note that depth test is turned off while blending the shadow
// so the slides has to be rendered in right order, see rochade as example
if( maSettings.mbReflectSlides ) {
double surfaceLevel = -0.04;
/* reflected slides */
glPushMatrix();
glm::mat4 matrix;
matrix = glm::scale(matrix, glm::vec3(1, -1, 1));
matrix = glm::translate(matrix, glm::vec3(0, 2 - surfaceLevel, 0));
glMultMatrixf(glm::value_ptr(matrix));
glCullFace(GL_FRONT);
display_primitives(primitives, nTime, SlideWidthScale, SlideHeightScale);
glCullFace(GL_BACK);
slideShadow( nTime, primitives[0], SlideWidthScale, SlideHeightScale );
glPopMatrix();
}
display_primitives(primitives, nTime, SlideWidthScale, SlideHeightScale); display_primitives(primitives, nTime, SlideWidthScale, SlideHeightScale);
CHECK_GL_ERROR(); CHECK_GL_ERROR();
} }
...@@ -493,6 +421,69 @@ void ShaderTransition::impl_setTextureUniforms() ...@@ -493,6 +421,69 @@ void ShaderTransition::impl_setTextureUniforms()
namespace namespace
{ {
class ReflectionTransition : public ShaderTransition
{
public:
ReflectionTransition(const TransitionScene& rScene, const TransitionSettings& rSettings)
: ShaderTransition(rScene, rSettings)
{}
private:
virtual GLuint makeShader() const override;
virtual void displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ) override;
virtual void impl_prepareTransition() override {
glDisable(GL_CULL_FACE);
}
virtual void impl_finishTransition() override {
glEnable(GL_CULL_FACE);
}
};
GLuint ReflectionTransition::makeShader() const
{
return OpenGLHelper::LoadShaders( "reflectionVertexShader", "reflectionFragmentShader" );
}
void ReflectionTransition::displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex,
double SlideWidthScale, double SlideHeightScale )
{
CHECK_GL_ERROR();
applyOverallOperations( nTime, SlideWidthScale, SlideHeightScale );
sal_Int32 texture;
Primitives_t slide;
if (nTime < 0.5) {
texture = glLeavingSlideTex;
slide = getScene().getLeavingSlide();
} else {
texture = glEnteringSlideTex;
slide = getScene().getEnteringSlide();
}
displaySlide( nTime, texture, slide, SlideWidthScale, SlideHeightScale );
CHECK_GL_ERROR();
}
std::shared_ptr<OGLTransitionImpl>
makeReflectionTransition(
const Primitives_t& rLeavingSlidePrimitives,
const Primitives_t& rEnteringSlidePrimitives,
const Operations_t& rOverallOperations,
const TransitionSettings& rSettings = TransitionSettings())
{
return std::make_shared<ReflectionTransition>(
TransitionScene(rLeavingSlidePrimitives, rEnteringSlidePrimitives, rOverallOperations, SceneObjects_t()),
rSettings)
;
}
}
namespace
{
class SimpleTransition : public ShaderTransition class SimpleTransition : public ShaderTransition
{ {
public: public:
...@@ -639,25 +630,30 @@ std::shared_ptr<OGLTransitionImpl> makeFallLeaving() ...@@ -639,25 +630,30 @@ std::shared_ptr<OGLTransitionImpl> makeFallLeaving()
std::shared_ptr<OGLTransitionImpl> makeTurnAround() std::shared_ptr<OGLTransitionImpl> makeTurnAround()
{ {
Primitive Slide; Primitive Slide;
TransitionSettings aSettings; TransitionSettings aSettings;
aSettings.mbReflectSlides = true;
Slide.pushTriangle(glm::vec2(0,0),glm::vec2(1,0),glm::vec2(0,1)); Slide.pushTriangle(glm::vec2(0,0),glm::vec2(1,0),glm::vec2(0,1));
Slide.pushTriangle(glm::vec2(1,0),glm::vec2(0,1),glm::vec2(1,1)); Slide.pushTriangle(glm::vec2(1,0),glm::vec2(0,1),glm::vec2(1,1));
Primitives_t aLeavingPrimitives; Primitives_t aLeavingPrimitives;
aLeavingPrimitives.push_back(Slide); aLeavingPrimitives.push_back(Slide);
Slide.Operations.push_back(makeSScale(glm::vec3(1, -1, 1), glm::vec3(0, -1.02, 0), false, -1, 0));
aLeavingPrimitives.push_back(Slide);
Slide.Operations.clear();
Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0),-180,false,0.0,1.0)); Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0),-180,false,0.0,1.0));
Primitives_t aEnteringPrimitives; Primitives_t aEnteringPrimitives;
aEnteringPrimitives.push_back(Slide); aEnteringPrimitives.push_back(Slide);
Slide.Operations.push_back(makeSScale(glm::vec3(1, -1, 1), glm::vec3(0, -1.02, 0), false, -1, 0));
aEnteringPrimitives.push_back(Slide);
Operations_t aOperations; Operations_t aOperations;
aOperations.push_back(makeSTranslate(glm::vec3(0, 0, -1.5),true, 0, 0.5)); aOperations.push_back(makeSTranslate(glm::vec3(0, 0, -1.5),true, 0, 0.5));
aOperations.push_back(makeSTranslate(glm::vec3(0, 0, 1.5), true, 0.5, 1)); aOperations.push_back(makeSTranslate(glm::vec3(0, 0, 1.5), true, 0.5, 1));
aOperations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0, 1, 0),glm::vec3(0, 0, 0), -180, true, 0.0, 1.0)); aOperations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0, 1, 0),glm::vec3(0, 0, 0), -180, true, 0.0, 1.0));
return makeSimpleTransition(aLeavingPrimitives, aEnteringPrimitives, aOperations, aSettings); return makeReflectionTransition(aLeavingPrimitives, aEnteringPrimitives, aOperations, aSettings);
} }
std::shared_ptr<OGLTransitionImpl> makeTurnDown() std::shared_ptr<OGLTransitionImpl> makeTurnDown()
...@@ -755,15 +751,15 @@ std::shared_ptr<OGLTransitionImpl> makeIris() ...@@ -755,15 +751,15 @@ std::shared_ptr<OGLTransitionImpl> makeIris()
namespace namespace
{ {
class RochadeTransition : public SimpleTransition class RochadeTransition : public ReflectionTransition
{ {
public: public:
RochadeTransition(const TransitionScene& rScene, const TransitionSettings& rSettings) RochadeTransition(const TransitionScene& rScene, const TransitionSettings& rSettings)
: SimpleTransition(rScene, rSettings) : ReflectionTransition(rScene, rSettings)
{} {}
private: private:
virtual void displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ) override; virtual void displaySlides_(double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale) override;
}; };
void RochadeTransition::displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ) void RochadeTransition::displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale )
...@@ -798,9 +794,7 @@ makeRochadeTransition( ...@@ -798,9 +794,7 @@ makeRochadeTransition(
std::shared_ptr<OGLTransitionImpl> makeRochade() std::shared_ptr<OGLTransitionImpl> makeRochade()
{ {
Primitive Slide; Primitive Slide;
TransitionSettings aSettings; TransitionSettings aSettings;
aSettings.mbReflectSlides = true;
double w, h; double w, h;
...@@ -815,6 +809,9 @@ std::shared_ptr<OGLTransitionImpl> makeRochade() ...@@ -815,6 +809,9 @@ std::shared_ptr<OGLTransitionImpl> makeRochade()
Primitives_t aLeavingSlide; Primitives_t aLeavingSlide;
aLeavingSlide.push_back(Slide); aLeavingSlide.push_back(Slide);
Slide.Operations.push_back(makeSScale(glm::vec3(1, -1, 1), glm::vec3(0, -1.02, 0), false, -1, 0));
aLeavingSlide.push_back(Slide);
Slide.Operations.clear(); Slide.Operations.clear();
Slide.Operations.push_back(makeSEllipseTranslate(w, h, 0.75, 0.25, true, 0, 1)); Slide.Operations.push_back(makeSEllipseTranslate(w, h, 0.75, 0.25, true, 0, 1));
Slide.Operations.push_back(makeSTranslate(glm::vec3(0, 0, -h), false, -1, 0)); Slide.Operations.push_back(makeSTranslate(glm::vec3(0, 0, -h), false, -1, 0));
...@@ -823,6 +820,9 @@ std::shared_ptr<OGLTransitionImpl> makeRochade() ...@@ -823,6 +820,9 @@ std::shared_ptr<OGLTransitionImpl> makeRochade()
Primitives_t aEnteringSlide; Primitives_t aEnteringSlide;
aEnteringSlide.push_back(Slide); aEnteringSlide.push_back(Slide);
Slide.Operations.push_back(makeSScale(glm::vec3(1, -1, 1), glm::vec3(0, -1.02, 0), false, -1, 0));
aEnteringSlide.push_back(Slide);
return makeRochadeTransition(aLeavingSlide, aEnteringSlide, aSettings); return makeRochadeTransition(aLeavingSlide, aEnteringSlide, aSettings);
} }
......
...@@ -51,8 +51,7 @@ struct TransitionSettings ...@@ -51,8 +51,7 @@ struct TransitionSettings
TransitionSettings() : TransitionSettings() :
mbUseMipMapLeaving( true ), mbUseMipMapLeaving( true ),
mbUseMipMapEntering( true ), mbUseMipMapEntering( true ),
mnRequiredGLVersion( 1.0 ), mnRequiredGLVersion( 1.0 )
mbReflectSlides( false )
{ {
} }
...@@ -64,11 +63,6 @@ struct TransitionSettings ...@@ -64,11 +63,6 @@ struct TransitionSettings
/** which GL version does the transition require /** which GL version does the transition require
*/ */
float mnRequiredGLVersion; float mnRequiredGLVersion;
/** Whether to reflect slides, the reflection happens on flat surface beneath the slides.
** Now it only works with slides which keep their rectangular shape together.
*/
bool mbReflectSlides;
}; };
typedef std::vector<Primitive> Primitives_t; typedef std::vector<Primitive> Primitives_t;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment