gpt4 book ai didi

javascript - Three.js ShaderMaterial 上的错误纹理

转载 作者:行者123 更新时间:2023-12-02 13:55:46 29 4
gpt4 key购买 nike

我正在尝试使用 ShaderMaterial 来调整一个对象(VR 视频的球体)的亮度和对比度

这是我实现 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 );

这是我用于着色器的代码

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")

};

渲染球体时,它使用另一个最近生成的纹理,该纹理用于场景的另一部分。

如何将视频纹理保留在 panoTexture 上,这可能吗?我是否以正确的方式进行此操作?

最佳答案

这有效

shader.uniforms[ "tDiffuse" ].value = panoTexture;

关于javascript - Three.js ShaderMaterial 上的错误纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40715234/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com