Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReflectVectorNode: Fix and improve #24265

Merged
merged 4 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/jsm/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Object3DNode from './accessors/Object3DNode.js';
import PointUVNode from './accessors/PointUVNode.js';
import PositionNode from './accessors/PositionNode.js';
import ReferenceNode from './accessors/ReferenceNode.js';
import ReflectNode from './accessors/ReflectNode.js';
import ReflectVectorNode from './accessors/ReflectVectorNode.js';
import SkinningNode from './accessors/SkinningNode.js';
import TextureNode from './accessors/TextureNode.js';
import UVNode from './accessors/UVNode.js';
Expand Down Expand Up @@ -153,7 +153,7 @@ const nodeLib = {
PointUVNode,
PositionNode,
ReferenceNode,
ReflectNode,
ReflectVectorNode,
SkinningNode,
TextureNode,
UVNode,
Expand Down Expand Up @@ -260,7 +260,7 @@ export {
PointUVNode,
PositionNode,
ReferenceNode,
ReflectNode,
ReflectVectorNode,
SkinningNode,
TextureNode,
UVNode,
Expand Down
10 changes: 7 additions & 3 deletions examples/jsm/nodes/accessors/CubeTextureNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import TextureNode from './TextureNode.js';
import UniformNode from '../core/UniformNode.js';
import ReflectNode from './ReflectNode.js';
import ReflectVectorNode from './ReflectVectorNode.js';

import { negate, vec3, nodeObject } from '../shadernode/ShaderNodeBaseElements.js';

class CubeTextureNode extends TextureNode {

Expand Down Expand Up @@ -28,7 +30,7 @@ class CubeTextureNode extends TextureNode {

const properties = builder.getNodeProperties( this );

const uvNode = this.uvNode || builder.context.uvNode || new ReflectNode();
const uvNode = this.uvNode || builder.context.uvNode || new ReflectVectorNode();
let levelNode = this.levelNode || builder.context.levelNode;

if ( levelNode?.isNode === true ) {
Expand Down Expand Up @@ -74,7 +76,9 @@ class CubeTextureNode extends TextureNode {

if ( snippet === undefined || builder.context.tempRead === false ) {

const uvSnippet = uvNode.build( builder, 'vec3' );
const uvNodeObject = nodeObject( uvNode );
const cubeUV = vec3( negate( uvNodeObject.x ), uvNodeObject.yz );
const uvSnippet = cubeUV.build( builder, 'vec3' );

if ( levelNode ) {

Expand Down
70 changes: 0 additions & 70 deletions examples/jsm/nodes/accessors/ReflectNode.js

This file was deleted.

31 changes: 31 additions & 0 deletions examples/jsm/nodes/accessors/ReflectVectorNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Node from '../core/Node.js';
import {
transformedNormalView, positionViewDirection,
transformDirection, negate, reflect, cameraViewMatrix
} from '../shadernode/ShaderNodeBaseElements.js';

class ReflectVectorNode extends Node {

constructor() {

super( 'vec3' );

}

getHash( /*builder*/ ) {

return `reflectVector`;

}

construct() {

const reflectView = reflect( negate( positionViewDirection ), transformedNormalView );

return transformDirection( reflectView, cameraViewMatrix );

}

}

export default ReflectVectorNode;
7 changes: 2 additions & 5 deletions examples/jsm/nodes/lighting/EnvironmentNode.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import LightingNode from './LightingNode.js';
import ContextNode from '../core/ContextNode.js';
import MaxMipLevelNode from '../utils/MaxMipLevelNode.js';
import { ShaderNode, float, add, mul, div, log2, clamp, roughness, reflect, mix, vec3, positionViewDirection, negate, normalize, transformedNormalView, transformedNormalWorld, transformDirection, cameraViewMatrix } from '../shadernode/ShaderNodeElements.js';
import { ShaderNode, float, add, mul, div, log2, clamp, roughness, reflect, mix, positionViewDirection, negate, normalize, transformedNormalView, transformedNormalWorld, transformDirection, cameraViewMatrix } from '../shadernode/ShaderNodeElements.js';

// taken from here: http://casual-effects.blogspot.ca/2011/08/plausible-environment-lighting-in-two.html
const getSpecularMIPLevel = new ShaderNode( ( { texture, levelNode } ) => {
Expand Down Expand Up @@ -30,12 +30,9 @@ class EnvironmentNode extends LightingNode {
const envNode = this.envNode;
const properties = builder.getNodeProperties( this );

const flipNormalWorld = vec3( negate( transformedNormalWorld.x ), transformedNormalWorld.yz );

let reflectVec = reflect( negate( positionViewDirection ), transformedNormalView );
reflectVec = normalize( mix( reflectVec, transformedNormalView, mul( roughness, roughness ) ) );
reflectVec = transformDirection( reflectVec, cameraViewMatrix );
reflectVec = vec3( negate( reflectVec.x ), reflectVec.yz );

const radianceContext = new ContextNode( envNode, {
tempRead: false,
Expand All @@ -46,7 +43,7 @@ class EnvironmentNode extends LightingNode {

const irradianceContext = new ContextNode( envNode, {
tempRead: false,
uvNode: flipNormalWorld,
uvNode: transformedNormalWorld,
levelNode: float( 1 ),
levelShaderNode: getSpecularMIPLevel
} );
Expand Down
5 changes: 2 additions & 3 deletions examples/jsm/nodes/shadernode/ShaderNodeElements.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// accessors
import CubeTextureNode from '../accessors/CubeTextureNode.js';
import InstanceNode from '../accessors/InstanceNode.js';
import ReflectNode from '../accessors/ReflectNode.js';
import ReflectVectorNode from '../accessors/ReflectVectorNode.js';
import SkinningNode from '../accessors/SkinningNode.js';

// display
Expand Down Expand Up @@ -65,8 +65,7 @@ export const cubeTexture = nodeProxy( CubeTextureNode );

export const instance = nodeProxy( InstanceNode );

export const reflectVector = nodeImmutable( ReflectNode, ReflectNode.VECTOR );
export const reflectCube = nodeImmutable( ReflectNode, ReflectNode.CUBE );
export const reflectVector = nodeImmutable( ReflectVectorNode );

export const skinning = nodeProxy( SkinningNode );

Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_cubemap_adjustments.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import * as THREE from 'three';
import * as Nodes from 'three-nodes/Nodes.js';

import { uniform, mix, cubeTexture, mul, reference, add, positionWorld, normalWorld, modelWorldMatrix, transformDirection, saturate, saturation, hue, reflectCube, context } from 'three-nodes/Nodes.js';
import { uniform, mix, cubeTexture, mul, reference, add, positionWorld, normalWorld, modelWorldMatrix, transformDirection, saturate, saturation, hue, reflectVector, context } from 'three-nodes/Nodes.js';

import WebGPU from './jsm/capabilities/WebGPU.js';
import WebGPURenderer from './jsm/renderers/webgpu/WebGPURenderer.js';
Expand Down Expand Up @@ -122,7 +122,7 @@

const blurNode = uniform( 0 );

scene.environmentNode = getEnvironmentNode( reflectCube );
scene.environmentNode = getEnvironmentNode( reflectVector );

scene.backgroundNode = context( getEnvironmentNode( transformDirection( positionWorld, modelWorldMatrix ) ), {
levelNode : blurNode // @TODO: currently it uses mipmaps value, I think it should be replaced for [0,1]
Expand Down