-
Notifications
You must be signed in to change notification settings - Fork 4
/
UniformDataShader.ts
75 lines (65 loc) · 2.05 KB
/
UniformDataShader.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import {VertexAttributeEnum} from '../../../foundation/definitions/VertexAttribute';
import { GLSLShader } from '../GLSLShader';
import {CompositionTypeEnum} from '../../../foundation/definitions/CompositionType';
import {ComponentTypeEnum} from '../../../foundation/definitions/ComponentType';
import { AttributeNames } from '../../types/CommonTypes';
export class UniformDataShader extends GLSLShader {
private __variableName = '';
private __valueStr = '';
constructor(
private __functionName: string,
private __compositionType: CompositionTypeEnum,
private __componentType: ComponentTypeEnum
) {
super();
}
setVariableName(name: any) {
this.__variableName = name;
}
setDefaultValue(value: any) {
this.__valueStr = value.toString();
}
get vertexShaderDefinitions() {
return `
uniform ${this.__compositionType.getGlslStr(this.__componentType)} u_${
this.__variableName
}; // initialValue=${this.__valueStr}
void ${this.__functionName}(out ${this.__compositionType.getGlslStr(
this.__componentType
)} outValue) {
#ifdef RN_IS_DATATEXTURE_MODE
float materialSID = u_currentComponentSIDs[0]; // index 0 data is the materialSID
#else
float materialSID = u_materialSID;
#endif
outValue = get_${this.__variableName}(materialSID, 0);
}
`;
}
get pixelShaderDefinitions() {
return `
uniform ${this.__compositionType.getGlslStr(this.__componentType)} u_${
this.__variableName
}; // initialValue=${this.__valueStr}
void ${this.__functionName}(out ${this.__compositionType.getGlslStr(
this.__componentType
)} outValue) {
#ifdef RN_IS_DATATEXTURE_MODE
float materialSID = u_currentComponentSIDs[0]; // index 0 data is the materialSID
#else
float materialSID = u_materialSID;
#endif
outValue = get_${this.__variableName}(materialSID, 0);
}
`;
}
get attributeNames(): AttributeNames {
return [];
}
get attributeSemantics(): Array<VertexAttributeEnum> {
return [];
}
get attributeCompositions(): Array<CompositionTypeEnum> {
return [];
}
}