فهرست منبع

TSL Transpiler: Add support for `discard`. (#30538)

Michael Herzog 11 ماه پیش
والد
کامیت
686b93f88f
3فایلهای تغییر یافته به همراه21 افزوده شده و 1 حذف شده
  1. 10 0
      examples/jsm/transpiler/AST.js
  2. 5 1
      examples/jsm/transpiler/GLSLDecoder.js
  3. 6 0
      examples/jsm/transpiler/TSLEncoder.js

+ 10 - 0
examples/jsm/transpiler/AST.js

@@ -204,6 +204,16 @@ export class Return {
 
 
 }
 }
 
 
+export class Discard {
+
+	constructor() {
+
+		this.isDiscard = true;
+
+	}
+
+}
+
 export class Accessor {
 export class Accessor {
 
 
 	constructor( property ) {
 	constructor( property ) {

+ 5 - 1
examples/jsm/transpiler/GLSLDecoder.js

@@ -1,4 +1,4 @@
-import { Program, FunctionDeclaration, For, AccessorElements, Ternary, Varying, DynamicElement, StaticElement, FunctionParameter, Unary, Conditional, VariableDeclaration, Operator, Number, String, FunctionCall, Return, Accessor, Uniform } from './AST.js';
+import { Program, FunctionDeclaration, For, AccessorElements, Ternary, Varying, DynamicElement, StaticElement, FunctionParameter, Unary, Conditional, VariableDeclaration, Operator, Number, String, FunctionCall, Return, Accessor, Uniform, Discard } from './AST.js';
 
 
 const unaryOperators = [
 const unaryOperators = [
 	'+', '-', '~', '!', '++', '--'
 	'+', '-', '~', '!', '++', '--'
@@ -489,6 +489,10 @@ class GLSLDecoder {
 
 
 				return new Return( this.parseExpressionFromTokens( tokens.slice( 1 ) ) );
 				return new Return( this.parseExpressionFromTokens( tokens.slice( 1 ) ) );
 
 
+			} else if ( firstToken.str === 'discard' ) {
+
+				return new Discard();
+
 			}
 			}
 
 
 			const secondToken = tokens[ 1 ];
 			const secondToken = tokens[ 1 ];

+ 6 - 0
examples/jsm/transpiler/TSLEncoder.js

@@ -244,6 +244,12 @@ class TSLEncoder {
 
 
 			}
 			}
 
 
+		} else if ( node.isDiscard ) {
+
+			this.addImport( 'Discard' );
+
+			code = 'Discard()';
+
 		} else if ( node.isAccessorElements ) {
 		} else if ( node.isAccessorElements ) {
 
 
 			code = this.emitExpression( node.object );
 			code = this.emitExpression( node.object );

粤ICP备19079148号