Skip to content

Commit

Permalink
WebGLRenderer: Fix equirect texture conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Aug 11, 2020
1 parent a381ffe commit 0168a79
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/renderers/WebGLCubeRenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer
const currentMinFilter = texture.minFilter;
const currentRenderList = renderer.getRenderList();
const currentRenderTarget = renderer.getRenderTarget();
const currentRenderState = renderer.getRenderState();

// Avoid blurred poles
if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
Expand All @@ -115,6 +116,7 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer

renderer.setRenderTarget( currentRenderTarget );
renderer.setRenderList( currentRenderList );
renderer.setRenderState( currentRenderState );

mesh.geometry.dispose();
mesh.material.dispose();
Expand Down
20 changes: 19 additions & 1 deletion src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ function WebGLRenderer( parameters ) {
const fog = scene.fog;
const environment = material.isMeshStandardMaterial ? scene.environment : null;
const encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
const envMap = cubemaps.get( material.envMap || environment );

const materialProperties = properties.get( material );
const lights = currentRenderState.state.lights;
Expand Down Expand Up @@ -1502,6 +1503,11 @@ function WebGLRenderer( parameters ) {

initMaterial( material, scene, object );

} else if ( materialProperties.envMap !== envMap ) {

initMaterial( material, scene, object );
materialProperties.envMap = envMap;

}

} else {
Expand Down Expand Up @@ -1694,7 +1700,7 @@ function WebGLRenderer( parameters ) {

}

materials.refreshMaterialUniforms( m_uniforms, material, environment, _pixelRatio, _height );
materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height );

// RectAreaLight Texture
// TODO (mrdoob): Find a nicer implementation
Expand Down Expand Up @@ -1788,6 +1794,18 @@ function WebGLRenderer( parameters ) {

};

this.getRenderState = function () {

return currentRenderState;

};

this.setRenderState = function ( renderState ) {

currentRenderState = renderState;

};

this.getRenderTarget = function () {

return _currentRenderTarget;
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/webgl/WebGLMaterials.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { WebGLCubeMaps } from './WebGLCubeMaps';

export class WebGLMaterials {

constructor( properties: WebGLProperties, cubemaps: WebGLCubeMaps );
constructor( properties: WebGLProperties );

refreshMaterialUniforms( uniforms: object, material: Material, environment: Texture, pixelRatio: number, height: number ): void;
refreshMaterialUniforms( uniforms: object, material: Material, pixelRatio: number, height: number ): void;
refreshFogUniforms( uniforms: object, fog: IFog ): void;

}
24 changes: 13 additions & 11 deletions src/renderers/webgl/WebGLMaterials.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BackSide } from "../../constants.js";

function WebGLMaterials( properties, cubemaps ) {
function WebGLMaterials( properties ) {

function refreshFogUniforms( uniforms, fog ) {

Expand All @@ -19,7 +19,7 @@ function WebGLMaterials( properties, cubemaps ) {

}

function refreshMaterialUniforms( uniforms, material, environment, pixelRatio, height ) {
function refreshMaterialUniforms( uniforms, material, pixelRatio, height ) {

if ( material.isMeshBasicMaterial ) {

Expand All @@ -42,15 +42,15 @@ function WebGLMaterials( properties, cubemaps ) {

} else if ( material.isMeshStandardMaterial ) {

refreshUniformsCommon( uniforms, material, environment );
refreshUniformsCommon( uniforms, material );

if ( material.isMeshPhysicalMaterial ) {

refreshUniformsPhysical( uniforms, material, environment );
refreshUniformsPhysical( uniforms, material );

} else {

refreshUniformsStandard( uniforms, material, environment );
refreshUniformsStandard( uniforms, material );

}

Expand Down Expand Up @@ -105,7 +105,7 @@ function WebGLMaterials( properties, cubemaps ) {

}

function refreshUniformsCommon( uniforms, material, environment ) {
function refreshUniformsCommon( uniforms, material ) {

uniforms.opacity.value = material.opacity;

Expand Down Expand Up @@ -139,7 +139,7 @@ function WebGLMaterials( properties, cubemaps ) {

}

const envMap = cubemaps.get( material.envMap || environment );
const envMap = properties.get( material ).envMap;

if ( envMap ) {

Expand Down Expand Up @@ -477,7 +477,7 @@ function WebGLMaterials( properties, cubemaps ) {

}

function refreshUniformsStandard( uniforms, material, environment ) {
function refreshUniformsStandard( uniforms, material ) {

uniforms.roughness.value = material.roughness;
uniforms.metalness.value = material.metalness;
Expand Down Expand Up @@ -524,7 +524,9 @@ function WebGLMaterials( properties, cubemaps ) {

}

if ( material.envMap || environment ) {
const envMap = properties.get( material ).envMap;

if ( envMap ) {

//uniforms.envMap.value = material.envMap; // part of uniforms common
uniforms.envMapIntensity.value = material.envMapIntensity;
Expand All @@ -533,9 +535,9 @@ function WebGLMaterials( properties, cubemaps ) {

}

function refreshUniformsPhysical( uniforms, material, environment ) {
function refreshUniformsPhysical( uniforms, material ) {

refreshUniformsStandard( uniforms, material, environment );
refreshUniformsStandard( uniforms, material );

uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common

Expand Down

0 comments on commit 0168a79

Please sign in to comment.