|
@@ -15,6 +15,17 @@ import { AnimatedInputBlockTypes } from './animatedInputBlockTypes';
|
|
import { Observable } from '../../../../Misc/observable';
|
|
import { Observable } from '../../../../Misc/observable';
|
|
import { MaterialHelper } from '../../../../Materials/materialHelper';
|
|
import { MaterialHelper } from '../../../../Materials/materialHelper';
|
|
|
|
|
|
|
|
+const remapAttributeName: { [name: string]: string } = {
|
|
|
|
+ "position2d": "position",
|
|
|
|
+ "particle_uv": "vUV",
|
|
|
|
+ "particle_color": "vColor",
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const attributeInFragmentOnly: { [name: string]: boolean } = {
|
|
|
|
+ "particle_uv": true,
|
|
|
|
+ "particle_color": true,
|
|
|
|
+};
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Block used to expose an input value
|
|
* Block used to expose an input value
|
|
*/
|
|
*/
|
|
@@ -96,6 +107,7 @@ export class InputBlock extends NodeMaterialBlock {
|
|
case "uv":
|
|
case "uv":
|
|
case "uv2":
|
|
case "uv2":
|
|
case "position2d":
|
|
case "position2d":
|
|
|
|
+ case "particle_uv":
|
|
this._type = NodeMaterialBlockConnectionPointTypes.Vector2;
|
|
this._type = NodeMaterialBlockConnectionPointTypes.Vector2;
|
|
return this._type;
|
|
return this._type;
|
|
case "matricesIndices":
|
|
case "matricesIndices":
|
|
@@ -107,6 +119,7 @@ export class InputBlock extends NodeMaterialBlock {
|
|
this._type = NodeMaterialBlockConnectionPointTypes.Vector4;
|
|
this._type = NodeMaterialBlockConnectionPointTypes.Vector4;
|
|
return this._type;
|
|
return this._type;
|
|
case "color":
|
|
case "color":
|
|
|
|
+ case "particle_color":
|
|
this._type = NodeMaterialBlockConnectionPointTypes.Color4;
|
|
this._type = NodeMaterialBlockConnectionPointTypes.Color4;
|
|
return this._type;
|
|
return this._type;
|
|
}
|
|
}
|
|
@@ -393,6 +406,11 @@ export class InputBlock extends NodeMaterialBlock {
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /** @hidden */
|
|
|
|
+ public get _noContextSwitch(): boolean {
|
|
|
|
+ return attributeInFragmentOnly[this.name];
|
|
|
|
+ }
|
|
|
|
+
|
|
private _emit(state: NodeMaterialBuildState, define?: string) {
|
|
private _emit(state: NodeMaterialBuildState, define?: string) {
|
|
// Uniforms
|
|
// Uniforms
|
|
if (this.isUniform) {
|
|
if (this.isUniform) {
|
|
@@ -444,10 +462,14 @@ export class InputBlock extends NodeMaterialBlock {
|
|
|
|
|
|
// Attribute
|
|
// Attribute
|
|
if (this.isAttribute) {
|
|
if (this.isAttribute) {
|
|
- this.associatedVariableName = this.name === 'position2d' ? 'position' : this.name;
|
|
|
|
|
|
+ this.associatedVariableName = remapAttributeName[this.name] ?? this.name;
|
|
|
|
|
|
if (this.target === NodeMaterialBlockTargets.Vertex && state._vertexState) { // Attribute for fragment need to be carried over by varyings
|
|
if (this.target === NodeMaterialBlockTargets.Vertex && state._vertexState) { // Attribute for fragment need to be carried over by varyings
|
|
- this._emit(state._vertexState, define);
|
|
|
|
|
|
+ if (attributeInFragmentOnly[this.name]) {
|
|
|
|
+ state._emitVaryingFromString(this.associatedVariableName, state._getGLType(this.type), define);
|
|
|
|
+ } else {
|
|
|
|
+ this._emit(state._vertexState, define);
|
|
|
|
+ }
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -456,12 +478,17 @@ export class InputBlock extends NodeMaterialBlock {
|
|
}
|
|
}
|
|
|
|
|
|
state.attributes.push(this.associatedVariableName);
|
|
state.attributes.push(this.associatedVariableName);
|
|
- if (define) {
|
|
|
|
- state._attributeDeclaration += this._emitDefine(define);
|
|
|
|
- }
|
|
|
|
- state._attributeDeclaration += `attribute ${state._getGLType(this.type)} ${this.associatedVariableName};\r\n`;
|
|
|
|
- if (define) {
|
|
|
|
- state._attributeDeclaration += `#endif\r\n`;
|
|
|
|
|
|
+
|
|
|
|
+ if (attributeInFragmentOnly[this.name]) {
|
|
|
|
+ state._emitVaryingFromString(this.associatedVariableName, state._getGLType(this.type), define);
|
|
|
|
+ } else {
|
|
|
|
+ if (define) {
|
|
|
|
+ state._attributeDeclaration += this._emitDefine(define);
|
|
|
|
+ }
|
|
|
|
+ state._attributeDeclaration += `attribute ${state._getGLType(this.type)} ${this.associatedVariableName};\r\n`;
|
|
|
|
+ if (define) {
|
|
|
|
+ state._attributeDeclaration += `#endif\r\n`;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|