Debian Codegraph @

libs/gltfio/materials/ubershader.mat.in

raw
1 material {
2 name : ubershader_${SHADINGMODEL}_${BLENDING},
3 requires : [ uv0, uv1, color ],
4 shadingModel : ${SHADINGMODEL},
5 blending : ${BLENDING},
6 depthWrite : true,
7 doubleSided : ${DOUBLESIDED},
8 flipUV : false,
9 specularAmbientOcclusion : simple,
10 specularAntiAliasing : true,
11 clearCoatIorChange : false,
12 parameters : [
13
14 { type : float3, name : specularFactor },
15 { type : float, name : glossinessFactor },
16
17 // Base Color
18 { type : int, name : baseColorIndex },
19 { type : float4, name : baseColorFactor },
20 { type : sampler2d, name : baseColorMap },
21 { type : mat3, name : baseColorUvMatrix },
22
23 // Metallic-Roughness Map
24 { type : int, name : metallicRoughnessIndex },
25 { type : float, name : metallicFactor },
26 { type : float, name : roughnessFactor },
27 { type : sampler2d, name : metallicRoughnessMap },
28 { type : mat3, name : metallicRoughnessUvMatrix },
29
30 // Normal Map
31 { type : int, name : normalIndex },
32 { type : float, name : normalScale },
33 { type : sampler2d, name : normalMap },
34 { type : mat3, name : normalUvMatrix },
35
36 // Ambient Occlusion
37 { type : int, name : aoIndex },
38 { type : float, name : aoStrength },
39 { type : sampler2d, name : occlusionMap },
40 { type : mat3, name : occlusionUvMatrix },
41
42 // Emissive Map
43 { type : int, name : emissiveIndex },
44 { type : float3, name : emissiveFactor },
45 { type : sampler2d, name : emissiveMap },
46 { type : mat3, name : emissiveUvMatrix },
47
48 // Cleat coat
49 { type : float, name : clearCoatFactor },
50 { type : float, name : clearCoatRoughnessFactor },
51 { type : int, name : clearCoatIndex },
52 { type : sampler2d, name : clearCoatMap },
53 { type : mat3, name : clearCoatUvMatrix },
54 { type : int, name : clearCoatRoughnessIndex },
55 { type : sampler2d, name : clearCoatRoughnessMap },
56 { type : mat3, name : clearCoatRoughnessUvMatrix },
57 { type : int, name : clearCoatNormalIndex },
58 { type : sampler2d, name : clearCoatNormalMap },
59 { type : mat3, name : clearCoatNormalUvMatrix },
60 { type : float, name : clearCoatNormalScale }
61 ],
62 }
63
64 fragment {
65 void material(inout MaterialInputs material) {
66 highp float2 uvs[2];
67 uvs[0] = getUV0();
68 uvs[1] = getUV1();
69
70 #if !defined(SHADING_MODEL_UNLIT)
71 if (materialParams.normalIndex > -1) {
72 highp float2 uv = uvs[materialParams.normalIndex];
73 uv = (vec3(uv, 1.0) * materialParams.normalUvMatrix).xy;
74 material.normal = texture(materialParams_normalMap, uv).xyz * 2.0 - 1.0;
75 material.normal.xy *= materialParams.normalScale;
76 }
77 #if defined(SHADING_MODEL_LIT)
78 if (materialParams.clearCoatNormalIndex > -1) {
79 highp float2 uv = uvs[materialParams.clearCoatNormalIndex];
80 uv = (vec3(uv, 1.0) * materialParams.clearCoatNormalUvMatrix).xy;
81 material.clearCoatNormal = texture(materialParams_clearCoatNormalMap, uv).xyz * 2.0 - 1.0;
82 material.clearCoatNormal.xy *= materialParams.clearCoatNormalScale;
83 }
84 #endif
85 #endif
86
87 prepareMaterial(material);
88 material.baseColor = materialParams.baseColorFactor;
89
90 if (materialParams.baseColorIndex > -1) {
91 highp float2 uv = uvs[materialParams.baseColorIndex];
92 uv = (vec3(uv, 1.0) * materialParams.baseColorUvMatrix).xy;
93 material.baseColor *= texture(materialParams_baseColorMap, uv);
94 }
95
96 #if defined(BLEND_MODE_TRANSPARENT)
97 material.baseColor.rgb *= material.baseColor.a;
98 #endif
99
100 material.baseColor *= getColor();
101
102 #if !defined(SHADING_MODEL_UNLIT)
103
104 #if defined(SHADING_MODEL_LIT)
105 material.roughness = materialParams.roughnessFactor;
106 material.metallic = materialParams.metallicFactor;
107
108 // KHR_materials_clearcoat forbids clear coat from
109 // being applied in the specular/glossiness model
110 material.clearCoat = materialParams.clearCoatFactor;
111 material.clearCoatRoughness = materialParams.clearCoatRoughnessFactor;
112
113 if (materialParams.clearCoatIndex > -1) {
114 highp float2 uv = uvs[materialParams.clearCoatIndex];
115 uv = (vec3(uv, 1.0) * materialParams.clearCoatUvMatrix).xy;
116 material.clearCoat *= texture(materialParams_clearCoatMap, uv).r;
117 }
118 if (materialParams.clearCoatRoughnessIndex > -1) {
119 highp float2 uv = uvs[materialParams.clearCoatRoughnessIndex];
120 uv = (vec3(uv, 1.0) * materialParams.clearCoatRoughnessUvMatrix).xy;
121 material.clearCoatRoughness *= texture(materialParams_clearCoatRoughnessMap, uv).g;
122 }
123 #endif
124
125 material.emissive = vec4(materialParams.emissiveFactor.rgb, 0.0);
126
127 #if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)
128 material.glossiness = materialParams.glossinessFactor;
129 material.specularColor = materialParams.specularFactor;
130 #endif
131
132 if (materialParams.metallicRoughnessIndex > -1) {
133 highp float2 uv = uvs[materialParams.metallicRoughnessIndex];
134 uv = (vec3(uv, 1.0) * materialParams.metallicRoughnessUvMatrix).xy;
135
136 #if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)
137 vec4 sg = texture(materialParams_metallicRoughnessMap, uv);
138 material.specularColor *= sg.rgb;
139 material.glossiness *= sg.a;
140 #else
141 vec4 mr = texture(materialParams_metallicRoughnessMap, uv);
142 material.roughness *= mr.g;
143 material.metallic *= mr.b;
144 #endif
145 }
146
147 if (materialParams.aoIndex > -1) {
148 highp float2 uv = uvs[materialParams.aoIndex];
149 uv = (vec3(uv, 1.0) * materialParams.occlusionUvMatrix).xy;
150 material.ambientOcclusion = texture(materialParams_occlusionMap, uv).r *
151 materialParams.aoStrength;
152 }
153 if (materialParams.emissiveIndex > -1) {
154 highp float2 uv = uvs[materialParams.emissiveIndex];
155 uv = (vec3(uv, 1.0) * materialParams.emissiveUvMatrix).xy;
156 material.emissive.rgb *= texture(materialParams_emissiveMap, uv).rgb;
157 }
158 #endif
159 }
160 }