Debian Codegraph @

libs/gltfio/materials/gltflite.mat.in

raw
1 material {
2 name : gltflite_${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 parameters : [
12
13 // Base Color
14 { type : int, name : baseColorIndex },
15 { type : float4, name : baseColorFactor },
16 { type : sampler2d, name : baseColorMap },
17
18 // Metallic-Roughness Map
19 { type : int, name : metallicRoughnessIndex },
20 { type : float, name : metallicFactor },
21 { type : float, name : roughnessFactor },
22 { type : sampler2d, name : metallicRoughnessMap },
23
24 // Normal Map
25 { type : int, name : normalIndex },
26 { type : float, name : normalScale },
27 { type : sampler2d, name : normalMap },
28
29 // Ambient Occlusion
30 { type : int, name : aoIndex },
31 { type : float, name : aoStrength },
32 { type : sampler2d, name : occlusionMap },
33
34 // Emissive Map
35 { type : int, name : emissiveIndex },
36 { type : float3, name : emissiveFactor },
37 { type : sampler2d, name : emissiveMap }
38 ],
39 }
40
41 fragment {
42 void material(inout MaterialInputs material) {
43 float2 uvs[2];
44 uvs[0] = getUV0();
45 uvs[1] = getUV1();
46
47 #if !defined(SHADING_MODEL_UNLIT)
48 if (materialParams.normalIndex > -1) {
49 float2 uv = uvs[materialParams.normalIndex];
50 material.normal = texture(materialParams_normalMap, uv).xyz * 2.0 - 1.0;
51 material.normal.xy *= materialParams.normalScale;
52 }
53 #endif
54
55 prepareMaterial(material);
56 material.baseColor = materialParams.baseColorFactor;
57
58 if (materialParams.baseColorIndex > -1) {
59 float2 uv = uvs[materialParams.baseColorIndex];
60 material.baseColor *= texture(materialParams_baseColorMap, uv);
61 }
62
63 #if defined(BLEND_MODE_TRANSPARENT)
64 material.baseColor.rgb *= material.baseColor.a;
65 #endif
66
67 material.baseColor *= getColor();
68
69 #if !defined(SHADING_MODEL_UNLIT)
70
71 #if defined(SHADING_MODEL_LIT)
72 material.roughness = materialParams.roughnessFactor;
73 material.metallic = materialParams.metallicFactor;
74 #endif
75
76 material.emissive = vec4(materialParams.emissiveFactor.rgb, 0.0);
77
78 if (materialParams.metallicRoughnessIndex > -1) {
79 float2 uv = uvs[materialParams.metallicRoughnessIndex];
80
81 vec4 mr = texture(materialParams_metallicRoughnessMap, uv);
82 material.roughness *= mr.g;
83 material.metallic *= mr.b;
84 }
85
86 if (materialParams.aoIndex > -1) {
87 float2 uv = uvs[materialParams.aoIndex];
88 material.ambientOcclusion = texture(materialParams_occlusionMap, uv).r *
89 materialParams.aoStrength;
90 }
91 if (materialParams.emissiveIndex > -1) {
92 float2 uv = uvs[materialParams.emissiveIndex];
93 material.emissive.rgb *= texture(materialParams_emissiveMap, uv).rgb;
94 }
95 #endif
96 }
97 }