Support 2 uv maps.
This commit is contained in:
parent
a2667d8dca
commit
eabe0bd64e
|
@ -48,6 +48,9 @@ in vec4 matColor;
|
|||
#ifdef _Tex
|
||||
in vec2 texCoord;
|
||||
#endif
|
||||
#ifdef _Tex1
|
||||
in vec2 texCoord1;
|
||||
#endif
|
||||
#ifdef _NorTex
|
||||
in mat3 TBN;
|
||||
#else
|
||||
|
@ -77,7 +80,12 @@ float distanceBox(vec3 point, vec3 center, vec3 halfExtents) {
|
|||
void main() {
|
||||
|
||||
#ifdef _NorTex
|
||||
vec3 n = (texture(snormal, texCoord).rgb * 2.0 - 1.0);
|
||||
#ifdef _NorTex1
|
||||
vec3 n = texture(snormal, texCoord1).rgb * 2.0 - 1.0;
|
||||
#else
|
||||
vec3 n = texture(snormal, texCoord).rgb * 2.0 - 1.0;
|
||||
#endif
|
||||
|
||||
n = normalize(TBN * normalize(n));
|
||||
#else
|
||||
vec3 n = normalize(normal);
|
||||
|
@ -87,30 +95,49 @@ void main() {
|
|||
#endif
|
||||
|
||||
vec3 baseColor = matColor.rgb;
|
||||
|
||||
#ifdef _BaseTex
|
||||
#ifdef _BaseTex1
|
||||
vec4 texel = texture(sbase, texCoord1);
|
||||
#else
|
||||
vec4 texel = texture(sbase, texCoord);
|
||||
#endif
|
||||
|
||||
#ifdef _AlphaTest
|
||||
if(texel.a < 0.4)
|
||||
discard;
|
||||
#endif
|
||||
|
||||
texel.rgb = pow(texel.rgb, vec3(2.2)); // Variant 1
|
||||
baseColor *= texel.rgb;
|
||||
#endif
|
||||
// baseColor = pow(baseColor, vec3(2.2)); // Variant 2
|
||||
|
||||
|
||||
#ifdef _MetTex
|
||||
#ifdef _MetTex1
|
||||
float metalness = texture(smetal, texCoord1).r;
|
||||
#else
|
||||
float metalness = texture(smetal, texCoord).r;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _RoughTex
|
||||
#ifdef _RoughTex1
|
||||
float roughness = texture(srough, texCoord1).r;
|
||||
#else
|
||||
float roughness = texture(srough, texCoord).r;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef _RoughStr
|
||||
roughness *= roughnessStrength;
|
||||
#endif
|
||||
|
||||
#ifdef _OccTex
|
||||
#ifdef _OccTex1
|
||||
float occ = texture(socclusion, texCoord1).r;
|
||||
#else
|
||||
float occ = texture(socclusion, texCoord).r;
|
||||
#endif
|
||||
#else
|
||||
float occ = occlusion;
|
||||
#endif
|
||||
|
|
|
@ -15,6 +15,9 @@ in vec3 nor;
|
|||
#ifdef _Tex
|
||||
in vec2 tex;
|
||||
#endif
|
||||
#ifdef _Tex1
|
||||
in vec2 tex1;
|
||||
#endif
|
||||
#ifdef _VCols
|
||||
in vec3 col;
|
||||
#endif
|
||||
|
@ -50,6 +53,9 @@ out vec4 matColor;
|
|||
#ifdef _Tex
|
||||
out vec2 texCoord;
|
||||
#endif
|
||||
#ifdef _Tex1
|
||||
out vec2 texCoord1;
|
||||
#endif
|
||||
#ifdef _NorTex
|
||||
out mat3 TBN;
|
||||
#else
|
||||
|
@ -107,6 +113,9 @@ void main() {
|
|||
#ifdef _Tex
|
||||
texCoord = tex;
|
||||
#endif
|
||||
#ifdef _Tex1
|
||||
texCoord1 = tex1;
|
||||
#endif
|
||||
|
||||
matColor = baseCol;
|
||||
|
||||
|
|
|
@ -99,6 +99,9 @@ in vec3 position;
|
|||
#ifdef _Tex
|
||||
in vec2 texCoord;
|
||||
#endif
|
||||
#ifdef _Tex1
|
||||
in vec2 texCoord1;
|
||||
#endif
|
||||
in vec4 lampPos;
|
||||
in vec4 matColor;
|
||||
in vec3 eyeDir;
|
||||
|
@ -133,8 +136,13 @@ float shadowTest(vec4 lPos) {
|
|||
|
||||
void main() {
|
||||
|
||||
#ifdef _NorTex
|
||||
#ifdef _NorTex
|
||||
#ifdef _NorTex1
|
||||
vec3 n = texture(snormal, texCoord1).rgb * 2.0 - 1.0;
|
||||
#else
|
||||
vec3 n = texture(snormal, texCoord).rgb * 2.0 - 1.0;
|
||||
#endif
|
||||
|
||||
n = normalize(TBN * normalize(n));
|
||||
|
||||
// vec3 normal = texture(snormal, texCoord).rgb * 2.0 - 1.0;
|
||||
|
@ -176,12 +184,19 @@ void main() {
|
|||
#endif
|
||||
|
||||
vec3 baseColor = matColor.rgb;
|
||||
|
||||
#ifdef _BaseTex
|
||||
#ifdef _BaseTex1
|
||||
vec4 texel = texture(sbase, texCoord1);
|
||||
#else
|
||||
vec4 texel = texture(sbase, texCoord);
|
||||
#endif
|
||||
|
||||
#ifdef _AlphaTest
|
||||
if (texel.a < 0.4)
|
||||
discard;
|
||||
#endif
|
||||
|
||||
texel.rgb = pow(texel.rgb, vec3(2.2));
|
||||
baseColor *= texel.rgb;
|
||||
#endif
|
||||
|
@ -195,13 +210,22 @@ void main() {
|
|||
float dotVH = dot(v, h);
|
||||
|
||||
#ifdef _MetTex
|
||||
#ifdef _MetTex1
|
||||
float metalness = texture(smetal, texCoord1).r;
|
||||
#else
|
||||
float metalness = texture(smetal, texCoord).r;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
vec3 albedo = surfaceAlbedo(baseColor, metalness);
|
||||
vec3 f0 = surfaceF0(baseColor, metalness);
|
||||
|
||||
#ifdef _RoughTex
|
||||
#ifdef _RoughTex1
|
||||
float roughness = texture(srough, texCoord1).r;
|
||||
#else
|
||||
float roughness = texture(srough, texCoord).r;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef _RoughStr
|
||||
roughness *= roughnessStrength;
|
||||
|
@ -383,7 +407,11 @@ void main() {
|
|||
fragColor = vec4(vec3(direct * visibility + indirect), 1.0);
|
||||
|
||||
#ifdef _OccTex
|
||||
vec3 occ = texture(socclusion, texCoord).rgb;
|
||||
#ifdef _OccTex1
|
||||
float occ = texture(socclusion, texCoord1).r;
|
||||
#else
|
||||
float occ = texture(socclusion, texCoord).r;
|
||||
#endif
|
||||
fragColor.rgb *= occ;
|
||||
#else
|
||||
fragColor.rgb *= occlusion;
|
||||
|
|
|
@ -19,6 +19,9 @@ in vec3 nor;
|
|||
#ifdef _Tex
|
||||
in vec2 tex;
|
||||
#endif
|
||||
#ifdef _Tex1
|
||||
in vec2 tex1;
|
||||
#endif
|
||||
#ifdef _VCols
|
||||
in vec3 col;
|
||||
#endif
|
||||
|
@ -56,6 +59,9 @@ out vec3 position;
|
|||
#ifdef _Tex
|
||||
out vec2 texCoord;
|
||||
#endif
|
||||
#ifdef _Tex1
|
||||
out vec2 texCoord1;
|
||||
#endif
|
||||
out vec4 lampPos;
|
||||
out vec4 matColor;
|
||||
out vec3 eyeDir;
|
||||
|
@ -106,6 +112,9 @@ void main() {
|
|||
#ifdef _Tex
|
||||
texCoord = tex;
|
||||
#endif
|
||||
#ifdef _Tex1
|
||||
texCoord1 = tex1;
|
||||
#endif
|
||||
|
||||
matColor = baseCol;
|
||||
|
||||
|
|
|
@ -88,6 +88,9 @@ in vec3 position;
|
|||
#ifdef _Tex
|
||||
in vec2 texCoord;
|
||||
#endif
|
||||
#ifdef _Tex1
|
||||
in vec2 texCoord1;
|
||||
#endif
|
||||
in vec4 lampPos;
|
||||
in vec4 matColor;
|
||||
in vec3 eyeDir;
|
||||
|
@ -113,7 +116,12 @@ float shadowTest(vec4 lPos) {
|
|||
void main() {
|
||||
|
||||
#ifdef _NorTex
|
||||
vec3 n = (texture(snormal, texCoord).rgb * 2.0 - 1.0);
|
||||
#ifdef _NorTex1
|
||||
vec3 n = texture(snormal, texCoord1).rgb * 2.0 - 1.0;
|
||||
#else
|
||||
vec3 n = texture(snormal, texCoord).rgb * 2.0 - 1.0;
|
||||
#endif
|
||||
|
||||
n = normalize(TBN * normalize(n));
|
||||
#else
|
||||
vec3 n = normalize(normal);
|
||||
|
@ -141,12 +149,19 @@ void main() {
|
|||
#endif
|
||||
|
||||
vec3 baseColor = matColor.rgb;
|
||||
|
||||
#ifdef _BaseTex
|
||||
#ifdef _BaseTex1
|
||||
vec4 texel = texture(sbase, texCoord1);
|
||||
#else
|
||||
vec4 texel = texture(sbase, texCoord);
|
||||
#endif
|
||||
|
||||
#ifdef _AlphaTest
|
||||
if (texel.a < 0.4)
|
||||
discard;
|
||||
#endif
|
||||
|
||||
texel.rgb = pow(texel.rgb, vec3(2.2));
|
||||
baseColor *= texel.rgb;
|
||||
#endif
|
||||
|
@ -162,13 +177,22 @@ void main() {
|
|||
float dotVH = dot(v, h);
|
||||
|
||||
#ifdef _MetTex
|
||||
#ifdef _MetTex1
|
||||
float metalness = texture(smetal, texCoord1).r;
|
||||
#else
|
||||
float metalness = texture(smetal, texCoord).r;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
vec3 albedo = surfaceAlbedo(baseColor, metalness);
|
||||
vec3 f0 = surfaceF0(baseColor, metalness);
|
||||
|
||||
#ifdef _RoughTex
|
||||
#ifdef _RoughTex1
|
||||
float roughness = texture(srough, texCoord1).r;
|
||||
#else
|
||||
float roughness = texture(srough, texCoord).r;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef _RoughStr
|
||||
roughness *= roughnessStrength;
|
||||
|
@ -214,7 +238,11 @@ void main() {
|
|||
outputColor = vec4(vec3(direct * visibility + indirect), 1.0);
|
||||
|
||||
#ifdef _OccTex
|
||||
vec3 occ = texture(socclusion, texCoord).rgb;
|
||||
#ifdef _OccTex1
|
||||
float occ = texture(socclusion, texCoord1).r;
|
||||
#else
|
||||
float occ = texture(socclusion, texCoord).r;
|
||||
#endif
|
||||
outputColor.rgb *= occ;
|
||||
#else
|
||||
outputColor.rgb *= occlusion;
|
||||
|
|
|
@ -15,6 +15,9 @@ in vec3 nor;
|
|||
#ifdef _Tex
|
||||
in vec2 tex;
|
||||
#endif
|
||||
#ifdef _Tex1
|
||||
in vec2 tex1;
|
||||
#endif
|
||||
#ifdef _VCols
|
||||
in vec3 col;
|
||||
#endif
|
||||
|
@ -47,6 +50,9 @@ out vec3 position;
|
|||
#ifdef _Tex
|
||||
out vec2 texCoord;
|
||||
#endif
|
||||
#ifdef _Tex1
|
||||
out vec2 texCoord1;
|
||||
#endif
|
||||
out vec4 lampPos;
|
||||
out vec4 matColor;
|
||||
out vec3 eyeDir;
|
||||
|
@ -93,6 +99,9 @@ void main() {
|
|||
#ifdef _Tex
|
||||
texCoord = tex;
|
||||
#endif
|
||||
#ifdef _Tex1
|
||||
texCoord1 = tex1;
|
||||
#endif
|
||||
|
||||
matColor = baseCol;
|
||||
|
||||
|
|
|
@ -1623,11 +1623,11 @@ class ArmoryExporter:
|
|||
ta['values'] = t0data
|
||||
om['vertex_arrays'].append(ta)
|
||||
if num_uv_layers > 1:
|
||||
ta2 = {}
|
||||
ta2['attrib'] = "texcoord1"
|
||||
ta2['size'] = 2
|
||||
ta2['values'] = t1data
|
||||
om['vertex_arrays'].append(ta2)
|
||||
ta1 = {}
|
||||
ta1['attrib'] = "texcoord1"
|
||||
ta1['size'] = 2
|
||||
ta1['values'] = t1data
|
||||
om['vertex_arrays'].append(ta1)
|
||||
if num_colors > 0:
|
||||
ca = {}
|
||||
ca['attrib'] = "color"
|
||||
|
@ -1769,6 +1769,9 @@ class ArmoryExporter:
|
|||
# arbitrary stage in the modifier stack.
|
||||
exportMesh = bobject.to_mesh(scene, applyModifiers, "RENDER", True, False)
|
||||
|
||||
if len(exportMesh.uv_layers) > 2:
|
||||
print('Armory Warning: ' + oid + ' exceeds maximum of 2 UV Maps supported')
|
||||
|
||||
# Process meshes
|
||||
if ArmoryExporter.option_optimize_mesh:
|
||||
unifiedVertexArray = self.export_mesh_quality(exportMesh, bobject, fp, o, om)
|
||||
|
@ -2662,6 +2665,13 @@ class ArmoryExporter:
|
|||
# Get decal context from render paths
|
||||
decal_context = bpy.data.cameras[0].last_decal_context
|
||||
|
||||
# Set uv layers to support multiple texcoords
|
||||
if material in self.materialToObjectDict:
|
||||
mat_user = self.materialToObjectDict[material][0]
|
||||
make_material.uvlayers = []
|
||||
for layer in mat_user.data.uv_layers:
|
||||
make_material.uvlayers.append(layer.name)
|
||||
|
||||
# Parse from material output
|
||||
if decal_uv_layer == None:
|
||||
make_material.parse(self, material, c, defs)
|
||||
|
|
|
@ -6,6 +6,9 @@ import os
|
|||
import nodes
|
||||
import log
|
||||
|
||||
# UV Map names of current material user
|
||||
uvlayers = ['']
|
||||
|
||||
def is_pow(num):
|
||||
return ((num & (num - 1)) == 0) and num != 0
|
||||
|
||||
|
@ -423,11 +426,27 @@ def add_normal_strength(self, c, defs, f):
|
|||
const['name'] = 'normalStrength'
|
||||
const['float'] = f
|
||||
|
||||
def parse_image_vector(node, defs, tree, def_name):
|
||||
# Check attribute linked to image vector to figure out referenced uvmap
|
||||
vector_input = node.inputs[0]
|
||||
if vector_input.is_linked:
|
||||
vector_node = nodes.find_node_by_link(tree, node, vector_input)
|
||||
if vector_node.type == 'ATTRIBUTE':
|
||||
if vector_node.outputs[1].is_linked:
|
||||
# References second uv map
|
||||
if vector_node.attribute_name == uvlayers[1]:
|
||||
if def_name not in defs:
|
||||
defs.append(def_name)
|
||||
if '_Tex1' not in defs:
|
||||
defs.append('_Tex1')
|
||||
|
||||
def parse_base_color_socket(self, base_color_input, material, c, defs, tree, node, factor):
|
||||
if base_color_input.is_linked:
|
||||
color_node = nodes.find_node_by_link(tree, node, base_color_input)
|
||||
if color_node.type == 'TEX_IMAGE':
|
||||
add_albedo_tex(self, color_node, material, c, defs)
|
||||
parse_image_vector(color_node, defs, tree, '_BaseTex1')
|
||||
|
||||
elif color_node.type == 'TEX_CHECKER':
|
||||
pass
|
||||
elif color_node.type == 'ATTRIBUTE': # Assume vcols for now
|
||||
|
@ -455,6 +474,8 @@ def parse_metalness_socket(self, metalness_input, material, c, defs, tree, node,
|
|||
if metalness_input.is_linked:
|
||||
metalness_node = nodes.find_node_by_link(tree, node, metalness_input)
|
||||
add_metalness_tex(self, metalness_node, material, c, defs)
|
||||
parse_image_vector(metalness_node, defs, tree, '_MetTex1')
|
||||
|
||||
elif '_MetTex' not in defs:
|
||||
res = metalness_input.default_value
|
||||
add_metalness_const(res, c, factor, minimum_val, sqrt_val)
|
||||
|
@ -474,6 +495,8 @@ def parse_roughness_socket(self, roughness_input, material, c, defs, tree, node,
|
|||
if roughness_input.is_linked:
|
||||
roughness_node = nodes.find_node_by_link(tree, node, roughness_input)
|
||||
add_roughness_tex(self, roughness_node, material, c, defs)
|
||||
parse_image_vector(roughness_node, defs, tree, '_RoughTex1')
|
||||
|
||||
elif '_RoughTex' not in defs:
|
||||
res = parse_float_input(tree, node, roughness_input)
|
||||
add_roughness_const(res, c, factor, minimum_val, sqrt_val)
|
||||
|
@ -482,6 +505,7 @@ def parse_normal_map_socket(self, normal_input, material, c, defs, tree, node, f
|
|||
if normal_input.is_linked:
|
||||
normal_node = nodes.find_node_by_link(tree, node, normal_input)
|
||||
add_normal_tex(self, normal_node, material, c, defs)
|
||||
parse_image_vector(normal_node, defs, tree, '_NorTex1')
|
||||
|
||||
def add_occlusion_const(res, c, factor):
|
||||
if parse.const_occlusion == None:
|
||||
|
@ -494,6 +518,8 @@ def parse_occlusion_socket(self, occlusion_input, material, c, defs, tree, node,
|
|||
if occlusion_input.is_linked:
|
||||
occlusion_node = nodes.find_node_by_link(tree, node, occlusion_input)
|
||||
add_occlusion_tex(self, occlusion_node, material, c, defs)
|
||||
parse_image_vector(occlusion_node, defs, tree, '_OccTex1')
|
||||
|
||||
elif '_OccTex' not in defs:
|
||||
res = occlusion_input.default_value[0] # Take only one channel
|
||||
add_occlusion_const(res, c, factor)
|
||||
|
@ -502,6 +528,7 @@ def parse_height_socket(self, height_input, material, c, defs, tree, node, facto
|
|||
if height_input.is_linked:
|
||||
height_node = nodes.find_node_by_link(tree, node, height_input)
|
||||
add_height_tex(self, height_node, material, c, defs)
|
||||
parse_image_vector(height_node, defs, tree, '_HeightTex1')
|
||||
|
||||
def parse_pbr_group(self, material, c, defs, tree, node, factor):
|
||||
# Albedo Map
|
||||
|
|
Loading…
Reference in a new issue