Skip to content

Commit

Permalink
ColorAdjustmentNode: Fix hue code (mrdoob#27197)
Browse files Browse the repository at this point in the history
* ColorAdjustmentNode: Fix hue code

* Improve irradiance performance slightly
  • Loading branch information
sunag authored and AdaRoseCannon committed Jan 15, 2024
1 parent d3d346d commit 69ffada
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
12 changes: 4 additions & 8 deletions examples/jsm/nodes/display/ColorAdjustmentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import TempNode from '../core/TempNode.js';
import { dot, mix } from '../math/MathNode.js';
import { add } from '../math/OperatorNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, tslFn, nodeProxy, float, vec3, mat3 } from '../shadernode/ShaderNode.js';
import { addNodeElement, tslFn, nodeProxy, float, vec3 } from '../shadernode/ShaderNode.js';

const saturationNode = tslFn( ( { color, adjustment } ) => {

Expand All @@ -23,15 +23,11 @@ const vibranceNode = tslFn( ( { color, adjustment } ) => {

const hueNode = tslFn( ( { color, adjustment } ) => {

const RGBtoYIQ = mat3( 0.299, 0.587, 0.114, 0.595716, - 0.274453, - 0.321263, 0.211456, - 0.522591, 0.311135 );
const YIQtoRGB = mat3( 1.0, 0.9563, 0.6210, 1.0, - 0.2721, - 0.6474, 1.0, - 1.107, 1.7046 );
const k = vec3( 0.57735, 0.57735, 0.57735 );

const yiq = RGBtoYIQ.mul( color );
const cosAngle = adjustment.cos();

const hue = yiq.z.atan2( yiq.y ).add( adjustment );
const chroma = yiq.yz.length();

return YIQtoRGB.mul( vec3( yiq.x, chroma.mul( hue.cos() ), chroma.mul( hue.sin() ) ) );
return vec3( color.rgb.mul( cosAngle ).add( k.cross( color.rgb ).mul( adjustment.sin() ).add( k.mul( dot( k, color.rgb ).mul( cosAngle.oneMinus() ) ) ) ) );

} );

Expand Down
12 changes: 4 additions & 8 deletions examples/jsm/nodes/lighting/EnvironmentNode.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import LightingNode from './LightingNode.js';
import { cache } from '../core/CacheNode.js';
import { context } from '../core/ContextNode.js';
import { maxMipLevel } from '../utils/MaxMipLevelNode.js';
import { roughness, clearcoatRoughness } from '../core/PropertyNode.js';
import { equirectUV } from '../utils/EquirectUVNode.js';
import { specularMIPLevel } from '../utils/SpecularMIPLevelNode.js';
import { cameraViewMatrix } from '../accessors/CameraNode.js';
import { transformedClearcoatNormalView, transformedNormalView, transformedNormalWorld } from '../accessors/NormalNode.js';
import { positionViewDirection } from '../accessors/PositionNode.js';
import { addNodeClass } from '../core/Node.js';
import { float, vec2 } from '../shadernode/ShaderNode.js';
import { vec2 } from '../shadernode/ShaderNode.js';
import { cubeTexture } from '../accessors/CubeTextureNode.js';
import { reference } from '../accessors/ReferenceNode.js';

Expand Down Expand Up @@ -166,14 +167,9 @@ const createIrradianceContext = ( normalWorldNode ) => {
return node;

},
getTextureLevel: () => {

return float( 1 );

},
getTextureLevelAlgorithm: ( textureNode, levelNode ) => {
getTextureLevel: ( textureNode ) => {

return specularMIPLevel( textureNode, levelNode );
return maxMipLevel( textureNode );

}
};
Expand Down

0 comments on commit 69ffada

Please sign in to comment.