0

I'm trying to use a shaderMaterial to adjust the brightness and contrast on one object (the sphere for VR video)

Here is how I implement the ShaderMaterial

var geometry = new THREE.SphereGeometry( 500, 60, 40 );

var panoTexture = new THREE.VideoTexture( video );
panoTexture.minFilter = THREE.LinearFilter;
panoTexture.magFilter = THREE.LinearFilter;
panoTexture.format = THREE.RGBFormat;

// var material   = new THREE.MeshLambertMaterial( { map : texture } );

var shader = THREE.BrightnessContrastShader;
shader.uniforms[ "contrast" ].value = 0.0;
shader.uniforms[ "brightness" ].value = 0.0;
shader.uniforms[ "texture" ].texture = panoTexture;

var panoMaterial   = new THREE.ShaderMaterial(shader);


panoVideoMesh = new THREE.Mesh( geometry, panoMaterial );

And here is the code I'm using for the shader

THREE.BrightnessContrastShader = {

    uniforms: {

        "tDiffuse":   { type: "t", value: null },
        "brightness": { type: "f", value: 0 },
        "contrast":   { type: "f", value: 0 },
        "texture":   { type: "t", value: 0 }

    },

    vertexShader: [

        "varying vec2 vUv;",

        "void main() {",

            "vUv = uv;",

            "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",

        "}"

    ].join("\n"),

    fragmentShader: [

        "uniform sampler2D tDiffuse;",
        "uniform float brightness;",
        "uniform float contrast;",

        "varying vec2 vUv;",

        "void main() {",

            "gl_FragColor = texture2D( tDiffuse, vUv );",

            "gl_FragColor.rgb += brightness;",

            "if (contrast > 0.0) {",
                "gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) / (1.0 - contrast) + 0.5;",
            "} else {",
                "gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) * (1.0 + contrast) + 0.5;",
            "}",

        "}"

    ].join("\n")

};

When the sphere is rendered it's using another more recently generated texture that is for another part of the scene.

How do I keep the video texture on the panoTexture, is this possible and and am I going about this the right way?

2
  • 1
    You are not using the texture uniform in your fragment shader, your using the tDiffuse uniform. Commented Nov 21, 2016 at 8:48
  • Thanks I tried shader.uniforms[ "tDiffuse" ].texture = panoTexture; and it's the same. Each time there is a new texture created elsewhere it seems to use this texture Commented Nov 21, 2016 at 19:20

1 Answer 1

2

This worked

shader.uniforms[ "tDiffuse" ].value = panoTexture;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.