我有一个对象,当应用正常纹理时,它允许我更改偏移量.y值,但是在使用RGBELoader和HDR文件时,我不能再更改偏移量。
我的代码如下:
var loader3 = new THREE.ObjectLoader(); loader3.load("model/dome/dome2.json",function ( obj ) { obj.scale.x = 7; obj.scale.y = 7; obj.scale.z = 7; obj.position.x = 0; obj.position.z = 0; obj.position.y = 0; var loader = new THREE.RGBELoader(); var texture = loader.load( "maps/scene2.hdr", function( texture, textureData ){ materialHDR = new THREE.ShaderMaterial( { uniforms: { tDiffuse: { type: "t", value: texture }, exposure: { type: "f", value: textureData.exposure }, brightMax: { type: "f", value: textureData.gamma } vertexShader: getText( 'vs-hdr' ), fragmentShader: getText( 'fs-hdr' ) texture.offset.y = 0.5; // HERE LIES THE PROBLEM texture.flipY = true; obj.traverse( function ( child ) { if ( child instanceof THREE.Mesh ) { child.material = materialHDR; child.receiveShadow = true; //child.material.side = THREE.BackSide; child.material.side = THREE.DoubleSide; scene.add( obj ); });
HDR图像加载得很好,并应用到对象上,就像我使用普通纹理时一样,但是我根本无法在模型周围移动纹理。
我试过用重复包装和各种组合,但顽固的胶印不会工作!
我还想补充一下,我目前正在学习three.js (太棒了!)因此,如果上面的代码有任何其他错误,请原谅。
谢谢你提前提供帮助,这让我发疯了!
下面的阴影代码
<script id="fs-hdr" type="x-shader/x-fragment"> uniform sampler2D tDiffuse; uniform float exposure; uniform float brightMax; varying vec2 vUv; vec3 decode_pnghdr( const in vec4 color ) { vec4 rgbcolor = vec4( 0.0, 0.0, 0.0, 0.0 ); if ( color.w > 0.0 ) { float f = pow(2.0, 127.0*(color.w-0.5)); rgbcolor.xyz = color.xyz * f; return rgbcolor.xyz; // remove gamma correction vec4 res = color * color; // decoded RI float ri = pow( 2.0, res.w * 32.0 - 16.0 ); // decoded HDR pixel res.xyz = res.xyz * ri; return res.xyz; void main() { vec4 color = texture2D( tDiffuse, vUv ); color.xyz = decode_pnghdr( color ); // apply gamma correction and exposure //gl_FragColor = vec4( pow( exposure * color.xyz, vec3( 0.474 ) ), 1.0 ); // Perform tone-mapping float Y = dot(vec4(0.30, 0.59, 0.11, 0.0), color); float YD = exposure * (exposure/brightMax + 1.0) / (exposure + 1.0); color *= YD; gl_FragColor = vec4( color.xyz, 1.0 ); </script> <!-- HDR vertex shader --> <script id="vs-hdr" type="x-shader/x-vertex"> varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 3 ); </script>
发布于 2016-03-28 17:11:36
您的自定义着色器必须处理 offset/repeat 。
offset/repeat
在你的制服上加入 offsetRepeat ;
offsetRepeat
offsetRepeat: { type: "v4", value: new THREE.Vector4( 0, 0.5, 1, 1 ) }
并修改顶点着色器
uniform vec4 offsetRepeat; varying vec2 vUv; void main() {