Package fcagnin.jglsdk.glm

Examples of fcagnin.jglsdk.glm.Vec4


    protected void display() {
        lights.updateTime( getElapsedTime() );

        float gamma = isGammaCorrect ? gammaValue : 1.0f;

        Vec4 bkg = gammaCorrect( lights.getBackgroundColor(), gamma );

        glClearColor( bkg.x, bkg.y, bkg.z, bkg.w );
        glClearDepth( 1.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        MatrixStack modelMatrix = new MatrixStack();
        modelMatrix.setMatrix( viewPole.calcMatrix() );

        final Mat4 worldToCamMat = modelMatrix.top();
        LightBlockGamma lightData = lights.getLightInformationGamma( worldToCamMat );
        lightData.gamma = gamma;

        glBindBuffer( GL_UNIFORM_BUFFER, lightUniformBuffer );
        glBufferSubData( GL_UNIFORM_BUFFER, 0, lightData.fillAndFlipBuffer( lightBlockBuffer ) );
        glBindBuffer( GL_UNIFORM_BUFFER, 0 );

        {
            modelMatrix.push();

            scene.draw( modelMatrix, materialBlockIndex, lights.getTimerValue( "tetra" ) );

            modelMatrix.pop();
        }

        {
            modelMatrix.push();

            // Render the sun
            {
                modelMatrix.push();

                Vec3 sunlightDir = new Vec3( lights.getSunlightDirection() );
                modelMatrix.translate( sunlightDir.scale( 500.0f ) );
                modelMatrix.scale( 30.0f, 30.0f, 30.0f );

                glUseProgram( unlit.theProgram );
                glUniformMatrix4( unlit.modelToCameraMatrixUnif, false,
                        modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );

                Vec4 lightColor = lights.getSunlightIntensity();
                glUniform4( unlit.objectColorUnif, lightColor.fillAndFlipBuffer( vec4Buffer ) );
                scene.getSphereMesh().render( "flat" );

                modelMatrix.pop();
            }

            // Render the lights
            {
                for ( int light = 0; light < lights.getNumberOfPointLights(); light++ ) {
                    modelMatrix.push();

                    modelMatrix.translate( lights.getWorldLightPosition( light ) );

                    glUseProgram( unlit.theProgram );
                    glUniformMatrix4( unlit.modelToCameraMatrixUnif, false,
                            modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );

                    Vec4 lightColor = lights.getPointLightIntensity( light );
                    glUniform4( unlit.objectColorUnif, lightColor.fillAndFlipBuffer( vec4Buffer ) );
                    scene.getCubeMesh().render( "flat" );

                    modelMatrix.pop();
                }
            }
View Full Code Here


    private void setupHDRLighting() {
        SunlightValueHDR values[] = {
                new SunlightValueHDR(
                        0.0f / 24.0f,
                        new Vec4( 0.6f, 0.6f, 0.6f, 1.0f ),
                        new Vec4( 1.8f, 1.8f, 1.8f, 1.0f ),
                        new Vec4( skyDaylightColor ),
                        3.0f ),
                new SunlightValueHDR(
                        4.5f / 24.0f,
                        new Vec4( 0.6f, 0.6f, 0.6f, 1.0f ),
                        new Vec4( 1.8f, 1.8f, 1.8f, 1.0f ),
                        new Vec4( skyDaylightColor ),
                        3.0f ),
                new SunlightValueHDR(
                        6.5f / 24.0f,
                        new Vec4( 0.225f, 0.075f, 0.075f, 1.0f ),
                        new Vec4( 0.45f, 0.15f, 0.15f, 1.0f ),
                        new Vec4( 0.5f, 0.1f, 0.1f, 1.0f ),
                        1.5f ),
                new SunlightValueHDR(
                        8.0f / 24.0f,
                        new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ),
                        new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ),
                        new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ),
                        1.0f ),
                new SunlightValueHDR(
                        18.0f / 24.0f,
                        new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ),
                        new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ),
                        new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ),
                        1.0f ),
                new SunlightValueHDR(
                        19.5f / 24.0f,
                        new Vec4( 0.225f, 0.075f, 0.075f, 1.0f ),
                        new Vec4( 0.45f, 0.15f, 0.15f, 1.0f ),
                        new Vec4( 0.5f, 0.1f, 0.1f, 1.0f ),
                        1.5f ),
                new SunlightValueHDR(
                        20.5f / 24.0f,
                        new Vec4( 0.6f, 0.6f, 0.6f, 1.0f ),
                        new Vec4( 1.8f, 1.8f, 1.8f, 1.0f ),
                        new Vec4( skyDaylightColor ),
                        3.0f ),
        };

        lights.setSunlightValues( values, 7 );

        lights.setPointLightIntensity( 0, new Vec4( 0.6f, 0.6f, 0.6f, 1.0f ) );
        lights.setPointLightIntensity( 1, new Vec4( 0.0f, 0.0f, 0.7f, 1.0f ) );
        lights.setPointLightIntensity( 2, new Vec4( 0.7f, 0.0f, 0.0f, 1.0f ) );
    }
View Full Code Here

        lights.setPointLightIntensity( 1, new Vec4( 0.0f, 0.0f, 0.7f, 1.0f ) );
        lights.setPointLightIntensity( 2, new Vec4( 0.7f, 0.0f, 0.0f, 1.0f ) );
    }

    private void setupGammaLighting() {
        Vec4 sunlight = new Vec4( 6.5f, 6.5f, 6.5f, 1.0f );
        Vec4 brightAmbient = new Vec4( 0.4f, 0.4f, 0.4f, 1.0f );

        SunlightValueHDR values[] = {
                new SunlightValueHDR(
                        0.0f / 24.0f,
                        brightAmbient,
                        sunlight,
                        new Vec4( 0.65f, 0.65f, 1.0f, 1.0f ),
                        10.0f ),
                new SunlightValueHDR(
                        4.5f / 24.0f,
                        brightAmbient,
                        sunlight,
                        new Vec4( skyDaylightColor ),
                        10.0f ),
                new SunlightValueHDR(
                        6.5f / 24.0f,
                        new Vec4( 0.01f, 0.025f, 0.025f, 1.0f ),
                        new Vec4( 2.5f, 0.2f, 0.2f, 1.0f ),
                        new Vec4( 0.5f, 0.1f, 0.1f, 1.0f ),
                        5.0f ),
                new SunlightValueHDR(
                        8.0f / 24.0f,
                        new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ),
                        new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ),
                        new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ),
                        3.0f ),
                new SunlightValueHDR(
                        18.0f / 24.0f,
                        new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ),
                        new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ),
                        new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ),
                        3.0f ),
                new SunlightValueHDR(
                        19.5f / 24.0f,
                        new Vec4( 0.01f, 0.025f, 0.025f, 1.0f ),
                        new Vec4( 2.5f, 0.2f, 0.2f, 1.0f ),
                        new Vec4( 0.5f, 0.1f, 0.1f, 1.0f ),
                        5.0f ),
                new SunlightValueHDR(
                        20.5f / 24.0f,
                        brightAmbient,
                        sunlight,
                        new Vec4( skyDaylightColor ),
                        10.0f )
        };

        lights.setSunlightValues( values, 7 );

        lights.setPointLightIntensity( 0, new Vec4( 0.6f, 0.6f, 0.6f, 1.0f ) );
        lights.setPointLightIntensity( 1, new Vec4( 0.0f, 0.0f, 0.7f, 1.0f ) );
        lights.setPointLightIntensity( 2, new Vec4( 0.7f, 0.0f, 0.0f, 1.0f ) );
    }
View Full Code Here

        lights.setPointLightIntensity( 2, new Vec4( 0.7f, 0.0f, 0.0f, 1.0f ) );
    }


    private Vec4 gammaCorrect(Vec4 input, float gamma) {
        Vec4 inputCorrected = new Vec4();
        inputCorrected.x = (float) Math.pow( input.x, 1.0f / gamma );
        inputCorrected.y = (float) Math.pow( input.y, 1.0f / gamma );
        inputCorrected.z = (float) Math.pow( input.z, 1.0f / gamma );
        inputCorrected.w = input.w;
        return inputCorrected;
View Full Code Here

            currMat.mul( scaleMat );
        }

        void translate(Vec3 offsetVec) {
            Mat4 translateMat = new Mat4( 1.0f );
            translateMat.setColumn( 3, new Vec4( offsetVec, 1.0f ) );

            currMat.mul( translateMat );
        }
View Full Code Here

            Mat4 theMat = new Mat4( 1.0f );
            theMat.set( 0, 0, theScale.x );
            theMat.set( 1, 1, theScale.y );
            theMat.set( 2, 2, theScale.z );
            theMat.setColumn( 3, new Vec4( offset, 1.0f ) );
            return theMat;
        }
View Full Code Here

        lightPos.add( new ConstVelLinearInterpolatorVec3() );
        lightPos.add( new ConstVelLinearInterpolatorVec3() );
        lightPos.add( new ConstVelLinearInterpolatorVec3() );

        for ( int i = 0; i < NUMBER_OF_POINT_LIGHTS; i++ ) {
            lightIntensity.add( new Vec4( 0.2f, 0.2f, 0.2f, 1.0f ) );
        }

        ArrayList<Vec3> posValues = new ArrayList<>();

        posValues.add( new Vec3( -50.0f, 30.0f, 70.0f ) );
View Full Code Here


    ////////////////////////////////
    Vec4 getSunlightDirection() {
        float angle = 2.0f * 3.14159f * sunTimer.getAlpha();
        Vec4 sunDirection = new Vec4( 0.0f );
        sunDirection.x = (float) Math.sin( angle );
        sunDirection.y = (float) Math.cos( angle );

        // Keep the sun from being perfectly centered overhead.
        sunDirection = Mat4.mul( Glm.rotate( new Mat4( 1.0f ), 5.0f, new Vec3( 0.0f, 1.0f, 0.0f ) ), sunDirection );
View Full Code Here

        lightData.lights[0] = new PerLight();
        lightData.lights[0].cameraSpaceLightPos = Mat4.mul( worldToCameraMat, getSunlightDirection() );
        lightData.lights[0].lightIntensity = sunlightInterpolator.interpolate( sunTimer.getAlpha() );

        for ( int light = 0; light < NUMBER_OF_POINT_LIGHTS; light++ ) {
            Vec4 worldLightPos = new Vec4( lightPos.get( light ).interpolate( lightTimers.get( light ).getAlpha() ),
                    1.0f );
            Vec4 lightPosCameraSpace = Mat4.mul( worldToCameraMat, worldLightPos );

            lightData.lights[light + 1] = new PerLight();
            lightData.lights[light + 1].cameraSpaceLightPos = lightPosCameraSpace;
            lightData.lights[light + 1].lightIntensity = new Vec4( lightIntensity.get( light ) );
        }

        return lightData;
    }
View Full Code Here

        lightData.lights[0] = new PerLight();
        lightData.lights[0].cameraSpaceLightPos = Mat4.mul( worldToCameraMat, getSunlightDirection() );
        lightData.lights[0].lightIntensity = sunlightInterpolator.interpolate( sunTimer.getAlpha() );

        for ( int light = 0; light < NUMBER_OF_POINT_LIGHTS; light++ ) {
            Vec4 worldLightPos = new Vec4( lightPos.get( light ).interpolate( lightTimers.get( light ).getAlpha() ),
                    1.0f );
            Vec4 lightPosCameraSpace = Mat4.mul( worldToCameraMat, worldLightPos );

            lightData.lights[light + 1] = new PerLight();
            lightData.lights[light + 1].cameraSpaceLightPos = lightPosCameraSpace;
            lightData.lights[light + 1].lightIntensity = new Vec4( lightIntensity.get( light ) );
        }

        return lightData;
    }
View Full Code Here

TOP

Related Classes of fcagnin.jglsdk.glm.Vec4

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.