-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🆕 feat: tangent space & spimle skybox
- Loading branch information
Showing
18 changed files
with
2,863 additions
and
38 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,68 @@ | ||
import { ShaderGraphCompiler, SGNodeOutput } from '../../../compilers'; | ||
import { SGNodeData } from '../../../editors'; | ||
import { Sockets } from '../../../sockets'; | ||
import { ExtendReteNode, ValueType, Rete, SpaceValue, SpaceSuffixMap } from '../../../types'; | ||
import { NodeView, SelectControl } from '../../../view'; | ||
import { RC } from '../../ReteComponent'; | ||
import { TransformationMatrixRC } from '../matrix'; | ||
import { NormalRC } from './NormalRC'; | ||
import { TangentVectorRC } from './TangentVectorRC'; | ||
|
||
export type ReteBiTangentVectorNode = ExtendReteNode< | ||
'BiTangentVector', | ||
{ | ||
outValue: number[]; | ||
outValueType: ValueType.vec3; | ||
spaceValue: SpaceValue; | ||
} | ||
>; | ||
|
||
export class BiTangentVectorRC extends RC { | ||
static Name = 'BiTangentVector'; | ||
constructor() { | ||
super(BiTangentVectorRC.Name); | ||
this.data.component = NodeView; | ||
} | ||
|
||
initNode(node: ReteBiTangentVectorNode) { | ||
const { data, meta } = node; | ||
node.initValueType('out', [0, 0, 0], ValueType.vec3); | ||
node.initValueType('space', 'world', ValueType.string); | ||
data.exposed ??= true; | ||
data.preview ??= true; | ||
data.expanded ??= true; | ||
data.previewType ??= '3d'; | ||
meta.category = 'input/geometry'; | ||
meta.previewDisabled = false; | ||
meta.label = 'BiTangent Vector'; | ||
} | ||
|
||
async builder(node: ReteBiTangentVectorNode) { | ||
this.initNode(node); | ||
const out = new Rete.Output('out', 'Out', Sockets.vec3); | ||
node.addOutput(out).addControl(new SelectControl('space', node, 'Space', ['object', 'view', 'world', 'tangent'], false)); | ||
} | ||
|
||
static initBiTangentVectorContext(compiler: ShaderGraphCompiler, space: SpaceValue) { | ||
if (space === 'tangent') return 'vec3(0, 1, 0)'; | ||
|
||
const node = { name: 'BiTangent', data: {} } as any; | ||
const suffix = SpaceSuffixMap[space]; | ||
const key = 'bitangent' + suffix; | ||
const vertVar = key; | ||
const normalSameSpace = NormalRC.initNormalContext(compiler, space); | ||
const tangentSameSpace = TangentVectorRC.initTangentVectorContext(compiler, space); | ||
const tangentOS = TangentVectorRC.initTangentVectorContext(compiler, 'object'); | ||
const code = `let ${vertVar} = cross(${normalSameSpace}, ${tangentSameSpace}.xyz) * ${tangentOS}.w;`; | ||
compiler.setContext('vertShared', node, key, { varName: vertVar, code }); | ||
const varyingVar = compiler.setContext('varyings', node, key, varName => `${varName}: vec3f`); | ||
const fragVar = compiler.setContext('fragShared', node, key, varName => `let ${varName} = normalize(${varyingVar});`); | ||
const defVar = compiler.setVarNameMap(node, key + '_def', vertVar, fragVar); | ||
compiler.setAutoVaryings(node, key, varyingVar, vertVar); | ||
return defVar; | ||
} | ||
|
||
compileSG(compiler: ShaderGraphCompiler, node: SGNodeData<ReteBiTangentVectorNode>): SGNodeOutput { | ||
return { outputs: { out: BiTangentVectorRC.initBiTangentVectorContext(compiler, node.data.spaceValue) }, code: '' }; | ||
} | ||
} |
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,82 @@ | ||
import { ShaderGraphCompiler, SGNodeOutput } from '../../../compilers'; | ||
import { SGNodeData } from '../../../editors'; | ||
import { Sockets } from '../../../sockets'; | ||
import { ExtendReteNode, ValueType, Rete, SpaceValue, SpaceSuffixMap } from '../../../types'; | ||
import { NodeView, SelectControl } from '../../../view'; | ||
import { RC } from '../../ReteComponent'; | ||
import { TransformationMatrixRC } from '../matrix/TransformationMatrixRC'; | ||
import { NormalRC } from './NormalRC'; | ||
|
||
export type ReteTangentVectorNode = ExtendReteNode< | ||
'TangentVector', | ||
{ | ||
outValue: number[]; | ||
outValueType: ValueType.vec3; | ||
spaceValue: SpaceValue; | ||
} | ||
>; | ||
|
||
export class TangentVectorRC extends RC { | ||
static Name = 'TangentVector'; | ||
constructor() { | ||
super(TangentVectorRC.Name); | ||
this.data.component = NodeView; | ||
} | ||
|
||
initNode(node: ReteTangentVectorNode) { | ||
const { data, meta } = node; | ||
node.initValueType('out', [0, 0, 0], ValueType.vec3); | ||
node.initValueType('space', 'world', ValueType.string); | ||
data.exposed ??= true; | ||
data.preview ??= true; | ||
data.expanded ??= true; | ||
data.previewType ??= '3d'; | ||
meta.category = 'input/geometry'; | ||
meta.previewDisabled = false; | ||
meta.label = 'Tangent Vector'; | ||
} | ||
|
||
async builder(node: ReteTangentVectorNode) { | ||
this.initNode(node); | ||
const out = new Rete.Output('out', 'Out', Sockets.vec3); | ||
node.addOutput(out).addControl(new SelectControl('space', node, 'Space', ['object', 'view', 'world', 'tangent'], false)); | ||
} | ||
|
||
static initTangentVectorContext(compiler: ShaderGraphCompiler, space: SpaceValue) { | ||
if (space === 'tangent') return 'vec3(1, 0, 0)'; | ||
|
||
const node = { name: 'Tangent', data: {} } as any; | ||
const suffix = SpaceSuffixMap[space]; | ||
const key = 'tangent' + suffix; | ||
let vertVar = key; | ||
const Mat = (type: Parameters<typeof TransformationMatrixRC.initMatrixContext>['1']) => | ||
TransformationMatrixRC.initMatrixContext(compiler, type); | ||
if (space === 'object') { | ||
vertVar = '(*tangentOS)'; | ||
compiler.setContext('attributes', node, key, { | ||
varName: 'tangentOS', | ||
code: ``, | ||
}); | ||
const varyingVar = compiler.setContext('varyings', node, key, varName => `${varName}: vec4f`); | ||
const fragVar = compiler.setContext('fragShared', node, key, varName => `let ${varName} = normalize(${varyingVar}.xyz);`); | ||
const defVar = compiler.setVarNameMap(node, key + '_def', vertVar, fragVar); | ||
compiler.setAutoVaryings(node, key, varyingVar, vertVar); | ||
return defVar; | ||
} else { | ||
let code: string; | ||
const tangentOS = TangentVectorRC.initTangentVectorContext(compiler, 'object'); | ||
const matrix = Mat(space === 'view' ? 'ModelView' : 'Model'); | ||
code = `let ${vertVar} = mat3x3f(${matrix}[0].xyz, ${matrix}[1].xyz, ${matrix}[2].xyz) * ${tangentOS}.xyz;`; | ||
compiler.setContext('vertShared', node, key, { varName: vertVar, code }); | ||
const varyingVar = compiler.setContext('varyings', node, key, varName => `${varName}: vec3f`); | ||
const fragVar = compiler.setContext('fragShared', node, key, varName => `let ${varName} = normalize(${varyingVar});`); | ||
const defVar = compiler.setVarNameMap(node, key + '_def', vertVar, fragVar); | ||
compiler.setAutoVaryings(node, key, varyingVar, vertVar); | ||
return defVar; | ||
} | ||
} | ||
|
||
compileSG(compiler: ShaderGraphCompiler, node: SGNodeData<ReteTangentVectorNode>): SGNodeOutput { | ||
return { outputs: { out: TangentVectorRC.initTangentVectorContext(compiler, node.data.spaceValue) }, code: '' }; | ||
} | ||
} |
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
Oops, something went wrong.