-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
121 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { positionView } from '../accessors/Position.js'; | ||
import { smoothstep } from '../math/MathNode.js'; | ||
import { Fn, vec4 } from '../tsl/TSLBase.js'; | ||
|
||
/** | ||
* Returns a node that represents the `z` coordinate in view space | ||
* for the current fragment. It's a different representation of the | ||
* default depth value. | ||
* | ||
* This value can be part of a computation that defines how the fog | ||
* density increases when moving away from the camera. | ||
* | ||
* @param {NodeBuilder} builder - The current node builder. | ||
* @return {Node} The viewZ node. | ||
*/ | ||
function getViewZNode( builder ) { | ||
|
||
let viewZ; | ||
|
||
const getViewZ = builder.context.getViewZ; | ||
|
||
if ( getViewZ !== undefined ) { | ||
|
||
viewZ = getViewZ( this ); | ||
|
||
} | ||
|
||
return ( viewZ || positionView.z ).negate(); | ||
|
||
} | ||
|
||
/** | ||
* Constructs a new range factor node. | ||
* | ||
* @param {Node} near - Defines the near value. | ||
* @param {Node} far - Defines the far value. | ||
*/ | ||
export const rangeFogFactor = Fn( ( [ near, far ], builder ) => { | ||
|
||
const viewZ = getViewZNode( builder ); | ||
|
||
return smoothstep( near, far, viewZ ); | ||
|
||
} ); | ||
|
||
/** | ||
* Represents an exponential squared fog. This type of fog gives | ||
* a clear view near the camera and a faster than exponentially | ||
* densening fog farther from the camera. | ||
* | ||
* @param {Node} density - Defines the fog density. | ||
*/ | ||
export const densityFogFactor = Fn( ( [ density ], builder ) => { | ||
|
||
const viewZ = getViewZNode( builder ); | ||
|
||
return density.mul( density, viewZ, viewZ ).negate().exp().oneMinus(); | ||
|
||
} ); | ||
|
||
/** | ||
* This class can be used to configure a fog for the scene. | ||
* Nodes of this type are assigned to `Scene.fogNode`. | ||
* | ||
* @param {Node} color - Defines the color of the fog. | ||
* @param {Node} factor - Defines how the fog is factored in the scene. | ||
*/ | ||
export const fog = Fn( ( [ color, factor ] ) => { | ||
|
||
return vec4( color.toVec3(), factor.toFloat() ); | ||
|
||
} ); | ||
|
||
// Deprecated | ||
|
||
export function rangeFog( color, near, far ) { // @deprecated, r171 | ||
|
||
console.warn( 'THREE.TSL: "rangeFog( color, near, far )" is deprecated. Use "fog( color, rangeFog( near, far ) )" instead.' ); | ||
return fog( color, rangeFogFactor( near, far ) ); | ||
|
||
} | ||
|
||
export function densityFog( color, density ) { // @deprecated, r171 | ||
|
||
console.warn( 'THREE.TSL: "densityFog( color, density )" is deprecated. Use "fog( color, densityFogFactor( density ) )" instead.' ); | ||
return fog( color, densityFogFactor( density ) ); | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.