Example usage for org.lwjgl.opengl GL13 GL_TEXTURE0

List of usage examples for org.lwjgl.opengl GL13 GL_TEXTURE0

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL13 GL_TEXTURE0.

Prototype

int GL_TEXTURE0

To view the source code for org.lwjgl.opengl GL13 GL_TEXTURE0.

Click Source Link

Document

Accepted by the texture parameter of ActiveTexture and MultiTexCoord.

Usage

From source file:org.terasology.rendering.shader.ShaderParametersLightShaft.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    DefaultRenderingProcess.FBO scene = DefaultRenderingProcess.getInstance().getFBO("sceneOpaque");

    int texId = 0;

    if (scene != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        scene.bindTexture();/*from w w w  . j  av  a 2  s .  co  m*/
        program.setInt("texScene", texId++, true);
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        scene.bindDepthTexture();
        program.setInt("texDepth", texId++, true);
    }

    program.setFloat("density", density, true);
    program.setFloat("exposure", exposure, true);
    program.setFloat("weight", weight, true);
    program.setFloat("decay", decay, true);

    WorldRenderer worldRenderer = CoreRegistry.get(WorldRenderer.class);
    if (worldRenderer != null) {
        Vector3f sunDirection = worldRenderer.getSkysphere().getSunDirection(true);

        Camera activeCamera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();

        Vector4f sunPositionWorldSpace4 = new Vector4f(sunDirection.x * 10000.0f, sunDirection.y * 10000.0f,
                sunDirection.z * 10000.0f, 1.0f);
        Vector4f sunPositionScreenSpace = new Vector4f();
        activeCamera.getViewProjectionMatrix().transform(sunPositionWorldSpace4, sunPositionScreenSpace);

        sunPositionScreenSpace.x /= sunPositionScreenSpace.w;
        sunPositionScreenSpace.y /= sunPositionScreenSpace.w;
        sunPositionScreenSpace.z /= sunPositionScreenSpace.w;
        sunPositionScreenSpace.w = 1.0f;

        program.setFloat("lightDirDotViewDir", activeCamera.getViewingDirection().dot(sunDirection), true);
        program.setFloat2("lightScreenPos", (sunPositionScreenSpace.x + 1.0f) / 2.0f,
                (sunPositionScreenSpace.y + 1.0f) / 2.0f, true);
    }
}

From source file:org.terasology.rendering.shader.ShaderParametersLightShafts.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    // TODO: obtain once in superclass and monitor from there?
    DisplayResolutionDependentFBOs displayResolutionDependentFBOs = CoreRegistry
            .get(DisplayResolutionDependentFBOs.class); // TODO: switch from CoreRegistry to Context.
    FBO scene = displayResolutionDependentFBOs.get(DefaultDynamicFBOs.READ_ONLY_GBUFFER.getName());

    int texId = 0;

    // TODO: - move into node
    // TODO: - many null checks are happening in these shader parameter classes. I feel they are unnecessary
    // TODO:   as those objects should never be null. If they are I'd be happy receiving an NPE and debugging as needed.
    if (scene != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        scene.bindTexture();/*  w w  w  .j  a v a 2 s  . com*/
        program.setInt("texScene", texId++, true);
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        scene.bindDepthTexture();
        program.setInt("texDepth", texId++, true);
    }

    // TODO: move into Material?
    program.setFloat("density", density, true);
    program.setFloat("exposure", exposure, true);
    program.setFloat("weight", weight, true);
    program.setFloat("decay", decay, true);

    WorldRenderer worldRenderer = CoreRegistry.get(WorldRenderer.class);
    BackdropProvider backdropProvider = CoreRegistry.get(BackdropProvider.class);

    // TODO: eliminate null check?
    if (worldRenderer != null) {
        // TODO: move into Material?
        Vector3f sunDirection = backdropProvider.getSunDirection(true);

        Camera activeCamera = worldRenderer.getActiveCamera();

        Vector4f sunPositionWorldSpace4 = new Vector4f(sunDirection.x * 10000.0f, sunDirection.y * 10000.0f,
                sunDirection.z * 10000.0f, 1.0f);
        Vector4f sunPositionScreenSpace = new Vector4f(sunPositionWorldSpace4);
        activeCamera.getViewProjectionMatrix().transform(sunPositionScreenSpace);

        sunPositionScreenSpace.x /= sunPositionScreenSpace.w;
        sunPositionScreenSpace.y /= sunPositionScreenSpace.w;
        sunPositionScreenSpace.z /= sunPositionScreenSpace.w;
        sunPositionScreenSpace.w = 1.0f;

        program.setFloat("lightDirDotViewDir", activeCamera.getViewingDirection().dot(sunDirection), true);
        program.setFloat2("lightScreenPos", (sunPositionScreenSpace.x + 1.0f) / 2.0f,
                (sunPositionScreenSpace.y + 1.0f) / 2.0f, true);
    }
}

From source file:org.terasology.rendering.shader.ShaderParametersOcDistortion.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    int texId = 0;
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    DefaultRenderingProcess.getInstance().bindFboTexture("sceneFinal");
    program.setInt("texSceneFinal", texId++, true);
}

From source file:org.terasology.rendering.shader.ShaderParametersParticle.java

License:Apache License

@Override
public void applyParameters(ShaderProgram program) {
    Texture terrainTex = Assets.getTexture("engine:terrain");
    if (terrainTex == null) {
        return;//from ww w.j  a  va2 s . c  o m
    }

    LocalPlayer localPlayer = CoreRegistry.get(LocalPlayer.class);

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    glBindTexture(GL11.GL_TEXTURE_2D, terrainTex.getId());

    if (localPlayer != null)
        program.setInt("carryingTorch", localPlayer.isCarryingTorch() ? 1 : 0);
}

From source file:org.terasology.rendering.shader.ShaderParametersPost.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    CameraTargetSystem cameraTargetSystem = CoreRegistry.get(CameraTargetSystem.class);

    int texId = 0;
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    DefaultRenderingProcess.getInstance().bindFboTexture("sceneToneMapped");
    program.setInt("texScene", texId++, true);

    if (CoreRegistry.get(Config.class).getRendering().getBlurIntensity() != 0) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        DefaultRenderingProcess.getInstance().getFBO("sceneBlur1").bindTexture();
        program.setInt("texBlur", texId++, true);

        if (cameraTargetSystem != null) {
            program.setFloat("blurFocusDistance", cameraTargetSystem.getFocalDistance(), true);
        }/*  w w  w  . j  a v a2  s .  co  m*/

        program.setFloat("blurStart", blurStart, true);
        program.setFloat("blurLength", blurLength, true);
    }

    Texture colorGradingLut = Assets.getTexture("engine:colorGradingLut1");

    if (colorGradingLut != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        glBindTexture(GL12.GL_TEXTURE_3D, colorGradingLut.getId());
        program.setInt("texColorGradingLut", texId++, true);
    }

    DefaultRenderingProcess.FBO sceneCombined = DefaultRenderingProcess.getInstance().getFBO("sceneOpaque");

    if (sceneCombined != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        sceneCombined.bindDepthTexture();
        program.setInt("texDepth", texId++, true);

        Texture filmGrainNoiseTexture = Assets.getTexture("engine:noise");

        if (CoreRegistry.get(Config.class).getRendering().isFilmGrain()) {
            GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
            glBindTexture(GL11.GL_TEXTURE_2D, filmGrainNoiseTexture.getId());
            program.setInt("texNoise", texId++, true);
            program.setFloat("grainIntensity", filmGrainIntensity, true);
            program.setFloat("noiseOffset", rand.nextFloat(), true);

            program.setFloat2("noiseSize", filmGrainNoiseTexture.getWidth(), filmGrainNoiseTexture.getHeight(),
                    true);
            program.setFloat2("renderTargetSize", sceneCombined.width, sceneCombined.height, true);
        }
    }

    Camera activeCamera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();
    if (activeCamera != null && CoreRegistry.get(Config.class).getRendering().isMotionBlur()) {
        program.setMatrix4("invViewProjMatrix", activeCamera.getInverseViewProjectionMatrix(), true);
        program.setMatrix4("prevViewProjMatrix", activeCamera.getPrevViewProjectionMatrix(), true);
    }
}

From source file:org.terasology.rendering.shader.ShaderParametersPrePost.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    Vector3f tint = CoreRegistry.get(WorldRenderer.class).getTint();
    program.setFloat3("inLiquidTint", tint.x, tint.y, tint.z, true);

    int texId = 0;
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    DefaultRenderingProcess.getInstance().bindFboTexture("sceneOpaque");
    program.setInt("texScene", texId++, true);

    if (CoreRegistry.get(Config.class).getRendering().isBloom()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        DefaultRenderingProcess.getInstance().bindFboTexture("sceneBloom2");
        program.setInt("texBloom", texId++, true);

        program.setFloat("bloomFactor", bloomFactor, true);
    }//  w  w  w.  ja  v a2s .c om

    program.setFloat2("aberrationOffset", aberrationOffsetX, aberrationOffsetY, true);

    if (CoreRegistry.get(Config.class).getRendering().isLightShafts()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        DefaultRenderingProcess.getInstance().bindFboTexture("lightShafts");
        program.setInt("texLightShafts", texId++, true);
    }

    Texture vignetteTexture = Assets.getTexture("engine:vignette");

    if (vignetteTexture != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        glBindTexture(GL11.GL_TEXTURE_2D, vignetteTexture.getId());
        program.setInt("texVignette", texId++, true);
    }
}

From source file:org.terasology.rendering.shader.ShaderParametersPrePostComposite.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    int texId = 0;
    // TODO: obtain these objects once in superclass and add there monitoring functionality as needed?
    DisplayResolutionDependentFBOs displayResolutionDependentFBOs = CoreRegistry
            .get(DisplayResolutionDependentFBOs.class); // TODO: switch from CoreRegistry to Context.

    // TODO: move texture bindings to the appropriate nodes
    if (READ_ONLY_GBUFFER.getFbo() != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        READ_ONLY_GBUFFER.bindTexture();
        program.setInt("texSceneOpaque", texId++, true);

        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        READ_ONLY_GBUFFER.bindDepthTexture();
        program.setInt("texSceneOpaqueDepth", texId++, true);

        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        READ_ONLY_GBUFFER.bindNormalsTexture();
        program.setInt("texSceneOpaqueNormals", texId++, true);

        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        READ_ONLY_GBUFFER.bindLightBufferTexture();
        program.setInt("texSceneOpaqueLightBuffer", texId++, true);
    }//from  w ww.jav a 2 s .co  m

    FBO sceneReflectiveRefractive = displayResolutionDependentFBOs
            .get(RefractiveReflectiveBlocksNode.REFRACTIVE_REFLECTIVE);

    if (sceneReflectiveRefractive != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        sceneReflectiveRefractive.bindTexture();
        program.setInt("texSceneReflectiveRefractive", texId++, true);
    }

    RenderingConfig renderingConfig = CoreRegistry.get(Config.class).getRendering();
    Camera activeCamera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();

    // TODO: review - unnecessary? Probably from a time when shaders were initialized
    // TODO:          on application startup rather than renderer startup.
    if (renderingConfig == null || activeCamera == null) {
        return;
    }

    // TODO: monitor the property subscribing to it
    if (renderingConfig.isLocalReflections()) {
        if (sceneReflectiveRefractive != null) {
            GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
            sceneReflectiveRefractive.bindNormalsTexture();
            program.setInt("texSceneReflectiveRefractiveNormals", texId++, true);
        }

        program.setMatrix4("invProjMatrix", activeCamera.getInverseProjectionMatrix(), true);
        program.setMatrix4("projMatrix", activeCamera.getProjectionMatrix(), true);
    }

    // TODO: monitor the property subscribing to it
    if (renderingConfig.isSsao()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        displayResolutionDependentFBOs.bindFboColorTexture(BlurredAmbientOcclusionNode.SSAO_BLURRED_FBO);
        program.setInt("texSsao", texId++, true);
    }

    // TODO: monitor the property subscribing to it
    if (renderingConfig.isOutline()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        displayResolutionDependentFBOs.bindFboColorTexture(OutlineNode.OUTLINE);
        program.setInt("texEdges", texId++, true);

        program.setFloat("outlineDepthThreshold", outlineDepthThreshold, true);
        program.setFloat("outlineThickness", outlineThickness, true);
    }

    // TODO: monitor the property subscribing to it
    if (renderingConfig.isVolumetricFog()) {
        program.setMatrix4("invViewProjMatrix", activeCamera.getInverseViewProjectionMatrix(), true);
        //TODO: Other parameters and volumetric fog test case is needed
    }

    // TODO: monitor the property subscribing to it
    if (renderingConfig.isInscattering()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        displayResolutionDependentFBOs.bindFboColorTexture(HazeNode.FINAL_HAZE);
        program.setInt("texSceneSkyBand", texId++, true);

        Vector4f skyInscatteringSettingsFrag = new Vector4f();
        skyInscatteringSettingsFrag.y = skyInscatteringStrength;
        skyInscatteringSettingsFrag.z = skyInscatteringLength;
        skyInscatteringSettingsFrag.w = skyInscatteringThreshold;
        program.setFloat4("skyInscatteringSettingsFrag", skyInscatteringSettingsFrag, true);
    }
}

From source file:org.terasology.rendering.shader.ShaderParametersScreenCombine.java

License:Apache License

@Override
public void applyParameters(ShaderProgram program) {
    PostProcessingRenderer.FBO scene = PostProcessingRenderer.getInstance().getFBO("scene");

    if (Config.getInstance().isSSAO()) {
        PostProcessingRenderer.FBO ssao = PostProcessingRenderer.getInstance().getFBO("ssaoBlurred1");
        GL13.glActiveTexture(GL13.GL_TEXTURE1);
        ssao.bindTexture();//from  w ww.  j a  v a 2s .  com
        program.setInt("texSsao", 1);
    }

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    scene.bindTexture();
    program.setInt("texScene", 0);
}

From source file:org.terasology.rendering.shader.ShaderParametersSky.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    int texId = 0;
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, Assets.getTexture("engine:sky90").getId());
    program.setInt("texSky90", texId++, true);
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, Assets.getTexture("engine:sky180").getId());
    program.setInt("texSky180", texId++, true);

    WorldRenderer worldRenderer = CoreRegistry.get(WorldRenderer.class);
    WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);

    if (worldProvider != null && worldRenderer != null) {
        program.setFloat("colorExp", worldRenderer.getSkysphere().getColorExp(), true);

        Vector3f sunDirection = worldRenderer.getSkysphere().getSunDirection(false);
        Vector3d zenithColor = getAllWeatherZenith(sunDirection.y, worldRenderer.getSkysphere().getTurbidity());

        program.setFloat("sunAngle", worldRenderer.getSkysphere().getSunPosAngle(), true);
        program.setFloat("turbidity", (Float) worldRenderer.getSkysphere().getTurbidity(), true);
        program.setFloat3("zenith", (float) zenithColor.x, (float) zenithColor.y, (float) zenithColor.z, true);
    }//  w  w  w  .ja  va2  s. c o m

    program.setFloat4("skySettings", sunExponent, moonExponent, skyDaylightBrightness, skyNightBrightness,
            true);
}

From source file:org.terasology.rendering.shader.ShaderParametersSobel.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    DefaultRenderingProcess.FBO scene = DefaultRenderingProcess.getInstance().getFBO("sceneOpaque");

    if (scene != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        scene.bindDepthTexture();/*from w w  w  . j  a va  2s. c  o  m*/
        program.setInt("texDepth", 0);

        program.setFloat("texelWidth", 1.0f / scene.width);
        program.setFloat("texelHeight", 1.0f / scene.height);
    }

    program.setFloat("pixelOffsetX", pixelOffsetX);
    program.setFloat("pixelOffsetY", pixelOffsetY);
}