Skip to content

Commit

Permalink
Merge pull request #1447 from actnwit/chore/add-comment
Browse files Browse the repository at this point in the history
chore: add comment
  • Loading branch information
emadurandal authored Jun 22, 2024
2 parents 452128e + 9076cea commit b0222ba
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
61 changes: 57 additions & 4 deletions src/foundation/materials/core/ShaderGraphResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ import { SinShaderNode } from '../nodes/SinShaderNode';
import { StepShaderNode } from '../nodes/StepShaderNode';
import { TimeShaderNode } from '../nodes/TimeShaderNode';

/**
* ShaderGraphResolver is a class that resolves the shader node graph and generates shader code.
*/
export class ShaderGraphResolver {
/**
* Create a vertex shader code from the given vertex nodes.
* @param vertexNodes - Vertex nodes
* @param varyingNodes - Varying nodes
* @param isFullVersion - Whether to generate a full version of the shader code
* @returns Vertex shader code
*/
static createVertexShaderCode(
vertexNodes: AbstractShaderNode[],
varyingNodes: AbstractShaderNode[],
Expand Down Expand Up @@ -70,7 +80,7 @@ export class ShaderGraphResolver {
let shaderBody = '';

// function definitions
shaderBody += ShaderGraphResolver.getFunctionDefinition(
shaderBody += ShaderGraphResolver.__getFunctionDefinition(
// sortedShaderNodes,
sortedShaderNodes.concat(varyingNodes.filter((node) => node.getShaderStage() !== 'Fragment')),
ShaderType.VertexShader
Expand All @@ -89,6 +99,13 @@ export class ShaderGraphResolver {
return shader;
}

/**
* Create a pixel shader code from the given pixel nodes.
*
* @param pixelNodes - Pixel nodes
* @param isFullVersion - Whether to generate a full version of the shader code
* @returns Pixel shader code
*/
static createPixelShaderCode(pixelNodes: AbstractShaderNode[], isFullVersion: boolean = true) {
const shaderNodes = pixelNodes.concat();

Expand All @@ -108,7 +125,7 @@ export class ShaderGraphResolver {
let shaderBody = '';

// function definitions
shaderBody += ShaderGraphResolver.getFunctionDefinition(
shaderBody += ShaderGraphResolver.__getFunctionDefinition(
sortedShaderNodes.filter((node) => node.getShaderStage() !== 'Vertex'),
ShaderType.PixelShader
);
Expand Down Expand Up @@ -144,6 +161,12 @@ export class ShaderGraphResolver {
return true;
}

/**
* Sort shader nodes topologically.
*
* @param shaderNodes - Shader nodes to sort
* @returns Sorted shader nodes
*/
private static __sortTopologically(shaderNodes: AbstractShaderNode[]) {
const sortedNodeArray: AbstractShaderNode[] = [];
const inputNumArray: Index[] = [];
Expand Down Expand Up @@ -210,7 +233,17 @@ export class ShaderGraphResolver {
return sortedNodeArray;
}

static getFunctionDefinition(shaderNodes: AbstractShaderNode[], shaderType: ShaderTypeEnum) {
/**
* Get function definition from shader nodes.
*
* @param shaderNodes - Shader nodes
* @param shaderType - Shader type
* @returns Function definition as a string
*/
private static __getFunctionDefinition(
shaderNodes: AbstractShaderNode[],
shaderType: ShaderTypeEnum
) {
let shaderText = '';
const existVertexFunctions: string[] = [];
for (let i = 0; i < shaderNodes.length; i++) {
Expand All @@ -225,6 +258,14 @@ export class ShaderGraphResolver {
return shaderText;
}

/**
* Construct shader code with shader nodes.
*
* @param shaderNodes - Shader nodes
* @param isVertexStage - Whether the shader is a vertex shader
* @param isFullVersion - Whether to generate a full version of the shader code
* @returns Shader code
*/
private static __constructShaderWithNodes(
shaderNodes: AbstractShaderNode[],
isVertexStage: boolean,
Expand Down Expand Up @@ -413,6 +454,12 @@ export class ShaderGraphResolver {
return shaderBody;
}

/**
* Generate shader code from JSON.
*
* @param json - JSON data of a shader node graph
* @returns Shader code
*/
public static generateShaderCodeFromJson(
json: any
): { vertexShader: string; pixelShader: string } | undefined {
Expand Down Expand Up @@ -561,7 +608,13 @@ function filterNodesForVarying(nodes: AbstractShaderNode[], endNodeName: string)
return varyingNodes.reverse();
}

export default function constructNodes(json: any) {
/**
* Construct shader nodes from JSON.
*
* @param json - JSON data of a shader node graph
* @returns Constructed shader nodes
*/
function constructNodes(json: any) {
// Create Node Instances
const nodeInstances: Record<number, AbstractShaderNode> = {};
const nodes: Record<string, any> = {};
Expand Down
3 changes: 2 additions & 1 deletion src/webgl/WebGLStrategyUniform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import { ModuleManager } from '../foundation/system/ModuleManager';
import { RnXR } from '../xr/main';
import { WebXRSystem } from '../xr/WebXRSystem';
import { Vector2 } from '../foundation/math/Vector2';
import { AnimationComponent, Scalar } from '../foundation';
import { AnimationComponent } from '../foundation/components/Animation/AnimationComponent';
import { Scalar } from '../foundation/math/Scalar';

declare const spector: any;

Expand Down

0 comments on commit b0222ba

Please sign in to comment.