diff --git a/editor/assets/effects/dcc/imported-specular-glossiness.effect b/editor/assets/effects/dcc/imported-specular-glossiness.effect index 05af1fb76c..c7a00e21a4 100644 --- a/editor/assets/effects/dcc/imported-specular-glossiness.effect +++ b/editor/assets/effects/dcc/imported-specular-glossiness.effect @@ -200,12 +200,13 @@ CCProgram standard-fs %{ #pragma define-meta TEXTURE_UV options([v_uv, v_uv1]) - #pragma define-meta DCC_APP_NAME range([0, 4]) + #pragma define-meta DCC_APP_NAME range([0, 5]) #define DCC_APP_OTHERS 0 - #define DCC_APP_AUTODESK 1 + #define DCC_APP_MAX 1 #define DCC_APP_BLENDER 2 #define DCC_APP_CINEMA4D 3 #define DCC_APP_GLTF 4 + #define DCC_APP_MAYA 5 #if USE_SHININESS_MAP uniform sampler2D shininessExponentMap; @@ -230,6 +231,7 @@ CCProgram standard-fs %{ #endif #if USE_TRANSPARENCY_MAP uniform sampler2D transparencyMap; + #pragma define-meta TRANSPARENCY_MAP_CHANNEL options([a, r, g, b]) #endif #if USE_NORMAL_MAP @@ -250,7 +252,7 @@ CCProgram standard-fs %{ #if DCC_APP_NAME == DCC_APP_BLENDER // 2-100 float glossiness = clamp(sqrt(shininessExp) * 0.1/*/10.0*/, 0.0, 0.95); // glossiness=1 may leads to specular disappear - #elif DCC_APP_NAME == DCC_APP_AUTODESK + #elif DCC_APP_NAME == DCC_APP_MAX || DCC_APP_NAME == DCC_APP_MAYA // 2-1024 float l2 = clamp(log(shininessExp + EPSILON) * 0.1442695 /*/log(2.0)/10.0*/, 0.0, 1.0); float glossiness = pow(l2, 0.5); @@ -266,7 +268,7 @@ CCProgram standard-fs %{ float specularIntensityMultiplier = mix(1.0, 5.0, roughness); #elif DCC_APP_NAME == DCC_APP_CINEMA4D float specularIntensityMultiplier = mix(1.0, 50.0, roughness); - #elif DCC_APP_NAME == DCC_APP_AUTODESK + #elif DCC_APP_NAME == DCC_APP_MAX || DCC_APP_NAME == DCC_APP_MAYA float specularIntensityMultiplier = mix(1.0, 20.0, roughness); #else // DCC_APP_NAME == DCC_APP_GLTF / DCC_APP_OTHERS float specularIntensityMultiplier = 1.0; @@ -276,7 +278,8 @@ CCProgram standard-fs %{ vec4 getSpecularColorAndFactor() { - vec3 inSpecular = specularColor.rgb; + vec3 inSpecular = specularColor.rgb * specularFactor; + float inFactor = 1.0; //reserved #if USE_SPECULAR_GLOSSINESS_MAP inSpecular = SRGBToLinear(texture(specularGlossinessMap, TEXTURE_UV).rgb); #endif @@ -285,7 +288,7 @@ CCProgram standard-fs %{ specularTex.rgb = SRGBToLinear(specularTex.rgb); inSpecular = specularTex.rgb; #endif - return vec4(inSpecular, specularFactor); + return vec4(inSpecular, inFactor); } void surf (out StandardSurface s) { //diffuse @@ -305,7 +308,10 @@ CCProgram standard-fs %{ baseColor.rgb *= diffuseFactor; #if USE_TRANSPARENCY_MAP - baseColor.a = texture(transparencyMap, TEXTURE_UV).a; + baseColor.a = texture(transparencyMap, TEXTURE_UV).TRANSPARENCY_MAP_CHANNEL; + #if DCC_APP_NAME == DCC_APP_MAYA + baseColor.a = 1.0 - baseColor.a; + #endif #endif #if USE_ALPHA_TEST @@ -319,7 +325,7 @@ CCProgram standard-fs %{ vec4 specularColorAndFactor = getSpecularColorAndFactor(); //glossiness - float inGlossiness = 0.0, inSpecularIntensity = specularColorAndFactor.w; + float inGlossiness = 0.0, inSpecularIntensity = 1.0; #if HAS_EXPORTED_GLOSSINESS #if USE_SPECULAR_GLOSSINESS_MAP inGlossiness = 1.0 - texture(specularGlossinessMap, TEXTURE_UV).a; @@ -371,7 +377,7 @@ CCProgram standard-fs %{ s.roughness = 1.0 - inGlossiness; s.metallic = inMetallic; s.specularIntensity = inSpecularIntensity * 0.5; - s.emissive = vec3(0.0); + s.emissive = emissive.rgb; #if USE_EMISSIVE_MAP s.emissive = texture(emissiveMap, TEXTURE_UV).xyz; #endif @@ -445,6 +451,13 @@ CCProgram shadow-caster-fs %{ in highp vec2 v_clip_depth; #pragma define-meta TEXTURE_UV options([v_uv, v_uv1]) + #pragma define-meta DCC_APP_NAME range([0, 5]) + #define DCC_APP_OTHERS 0 + #define DCC_APP_MAX 1 + #define DCC_APP_BLENDER 2 + #define DCC_APP_CINEMA4D 3 + #define DCC_APP_GLTF 4 + #define DCC_APP_MAYA 5 #if USE_ALBEDO_MAP uniform sampler2D albedoMap; @@ -452,6 +465,7 @@ CCProgram shadow-caster-fs %{ #if USE_TRANSPARENCY_MAP uniform sampler2D transparencyMap; + #pragma define-meta TRANSPARENCY_MAP_CHANNEL options([a, r, g, b]) #endif #if USE_VERTEX_COLOR @@ -468,7 +482,10 @@ CCProgram shadow-caster-fs %{ alpha *= texture(albedoMap, TEXTURE_UV).a * transparencyFactor; #endif #if USE_TRANSPARENCY_MAP - alpha = texture(transparencyMap, TEXTURE_UV).a; + alpha = texture(transparencyMap, TEXTURE_UV).TRANSPARENCY_MAP_CHANNEL; + #if DCC_APP_NAME == DCC_APP_MAYA + alpha = 1.0 - alpha; + #endif #endif if (alpha < alphaThreshold) discard; #endif diff --git a/editor/assets/effects/dcc/surfaces-imported-specular-glossiness.effect b/editor/assets/effects/dcc/surfaces-imported-specular-glossiness.effect index 47c620cd7f..a13dc7d509 100644 --- a/editor/assets/effects/dcc/surfaces-imported-specular-glossiness.effect +++ b/editor/assets/effects/dcc/surfaces-imported-specular-glossiness.effect @@ -7,26 +7,27 @@ CCEffect %{ - vert: standard-vs frag: standard-fs properties: &props - mainTexture: { value: grey, target: albedoMap, editor: { displayName: DiffuseMap } } - mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: diffuseColor, linear: true, editor: { displayName: DiffuseColor, type: color } } - albedoScale: { value: 1.0, target: diffuseFactor, editor: { displayName: diffuseFactor } } - alphaThreshold: { value: 0.5, editor: { parent: USE_ALPHA_TEST, slide: true, range: [0, 1.0], step: 0.001 } } - emissive: { value: [0.0, 0.0, 0.0, 1.0], linear: true, editor: { type: color } } - emissiveMap: { value: grey } - shininessExponentMap: { value: grey, editor: { parent: '!HAS_EXPORTED_GLOSSINESS' } } - shininessExponent: { value: 100.0, editor: { parent: '!HAS_EXPORTED_GLOSSINESS' } } - specularColor: { value: [0.0, 0.0, 0.0, 0.0], linear: true, editor: { displayName: SpecularColor, type: color } } - specularMap: { value: grey, editor: { parent: '!HAS_EXPORTED_METALLIC' } } - specularFactor: { value: 1.0, editor: { parent: '!HAS_EXPORTED_METALLIC' } } - transparencyMap: { value: grey, editor: { displayName: TransparencyMap } } - transparencyFactor: { value: 1.0, editor: { slide: true, range: [0, 1.0], step: 0.001 } } - tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } - normalStrength: { value: 1.0, target: normalScale, editor: { displayName: bumpFactor, parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } } - normalMap: { value: normal } - glossiness: { value: 0.0, editor: { parent: HAS_EXPORTED_GLOSSINESS, slide: true, range: [0, 1.0], step: 0.001 } } - metallic: { value: 0.0, editor: { parent: HAS_EXPORTED_METALLIC, slide: true, range: [0, 1.0], step: 0.001 } } - metallicMap: { value: grey, editor: { parent: HAS_EXPORTED_METALLIC } } - occlusionMap: { value: white } + mainTexture: { value: grey, target: albedoMap, editor: { displayName: DiffuseMap } } + mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: diffuseColor, linear: true, editor: { displayName: DiffuseColor, type: color } } + albedoScale: { value: 1.0, target: diffuseFactor, editor: { displayName: diffuseFactor } } + alphaThreshold: { value: 0.5, editor: { parent: USE_ALPHA_TEST, slide: true, range: [0, 1.0], step: 0.001 } } + emissive: { value: [0.0, 0.0, 0.0, 1.0], linear: true, editor: { type: color } } + emissiveMap: { value: grey } + shininessExponentMap: { value: grey, editor: { parent: '!HAS_EXPORTED_GLOSSINESS' } } + shininessExponent: { value: 100.0, editor: { parent: '!HAS_EXPORTED_GLOSSINESS' } } + specularGlossinessMap: { value: grey, editor: { parent: '!HAS_EXPORTED_GLOSSINESS' } } + specularColor: { value: [0.0, 0.0, 0.0, 0.0], linear: true, editor: { displayName: SpecularColor, type: color } } + specularMap: { value: grey, editor: { parent: '!HAS_EXPORTED_METALLIC' } } + specularFactor: { value: 1.0, editor: { parent: '!HAS_EXPORTED_METALLIC' } } + transparencyMap: { value: grey, editor: { displayName: TransparencyMap } } + transparencyFactor: { value: 1.0, editor: { slide: true, range: [0, 1.0], step: 0.001 } } + tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } + normalStrength: { value: 1.0, target: normalScale, editor: { displayName: bumpFactor, parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } } + normalMap: { value: normal } + glossiness: { value: 0.0, editor: { parent: HAS_EXPORTED_GLOSSINESS, slide: true, range: [0, 1.0], step: 0.001 } } + metallic: { value: 0.0, editor: { parent: HAS_EXPORTED_METALLIC, slide: true, range: [0, 1.0], step: 0.001 } } + metallicMap: { value: grey, editor: { parent: HAS_EXPORTED_METALLIC } } + occlusionMap: { value: white } - &forward-add vert: standard-vs frag: standard-fs @@ -136,17 +137,21 @@ CCProgram surface-vertex %{ CCProgram surface-fragment %{ #pragma define-meta TEXTURE_UV options([v_uv, v_uv1]) - #pragma define-meta DCC_APP_NAME range([0, 4]) + #pragma define-meta DCC_APP_NAME range([0, 5]) #define DCC_APP_OTHERS 0 - #define DCC_APP_AUTODESK 1 + #define DCC_APP_MAX 1 #define DCC_APP_BLENDER 2 #define DCC_APP_CINEMA4D 3 #define DCC_APP_GLTF 4 + #define DCC_APP_MAYA 5 #if USE_SHININESS_MAP uniform sampler2D shininessExponentMap; #pragma define-meta GLOSSINESS_MAP_CHANNEL options([r,g,b,a]) #endif + #if USE_SPECULAR_GLOSSINESS_MAP + uniform sampler2D specularGlossinessMap; + #endif #if USE_SPECULAR_MAP uniform sampler2D specularMap; #endif @@ -159,6 +164,7 @@ CCProgram surface-fragment %{ #endif #if USE_TRANSPARENCY_MAP uniform sampler2D transparencyMap; + #pragma define-meta TRANSPARENCY_MAP_CHANNEL options([a, r, g, b]) #endif #if USE_EMISSIVE_MAP @@ -185,11 +191,11 @@ CCProgram surface-fragment %{ #if DCC_APP_NAME == DCC_APP_BLENDER // 2-100 float glossiness = clamp(sqrt(shininessExp) * 0.1/*/10.0*/, 0.0, 0.95); // glossiness=1 may leads to specular disappear - #elif DCC_APP_NAME == DCC_APP_AUTODESK + #elif DCC_APP_NAME == DCC_APP_MAX || DCC_APP_NAME == DCC_APP_MAYA // 2-1024 float l2 = clamp(log(shininessExp + EPSILON) * 0.1442695 /*/log(2.0)/10.0*/, 0.0, 1.0); float glossiness = pow(l2, 0.5); - #else // DCC_APP_NAME == DCC_APP_CINEMA4D、DCC_APP_GLTF、DCC_APP_OTHERS + #else // DCC_APP_NAME == DCC_APP_CINEMA4D / DCC_APP_GLTF / DCC_APP_OTHERS // 2-1024 float glossiness = clamp(log(shininessExp + EPSILON) * 0.1442695 /*/log(2.0)/10.0*/, 0.0, 1.0); #endif @@ -201,9 +207,9 @@ CCProgram surface-fragment %{ float specularIntensityMultiplier = mix(1.0, 5.0, roughness); #elif DCC_APP_NAME == DCC_APP_CINEMA4D float specularIntensityMultiplier = mix(1.0, 50.0, roughness); - #elif DCC_APP_NAME == DCC_APP_AUTODESK + #elif DCC_APP_NAME == DCC_APP_MAX || DCC_APP_NAME == DCC_APP_MAYA float specularIntensityMultiplier = mix(1.0, 20.0, roughness); - #else // DCC_APP_NAME == DCC_APP_GLTF、DCC_APP_OTHERS + #else // DCC_APP_NAME == DCC_APP_GLTF / DCC_APP_OTHERS float specularIntensityMultiplier = 1.0; #endif return specularIntensityMultiplier; @@ -211,13 +217,17 @@ CCProgram surface-fragment %{ vec4 getSpecularColorAndFactor() { - vec3 inSpecular = specularColor.rgb; + vec3 inSpecular = specularColor.rgb * specularFactor; + float inFactor = 1.0; //reserved + #if USE_SPECULAR_GLOSSINESS_MAP + inSpecular = SRGBToLinear(texture(specularGlossinessMap, TEXTURE_UV).rgb); + #endif #if USE_SPECULAR_MAP vec4 specularTex = texture(specularMap, TEXTURE_UV); specularTex.rgb = SRGBToLinear(specularTex.rgb); inSpecular = specularTex.rgb; #endif - return vec4(inSpecular, specularFactor); + return vec4(inSpecular, inFactor); } #define CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY @@ -232,7 +242,10 @@ CCProgram surface-fragment %{ alpha *= texture(albedoMap, TEXTURE_UV).a * transparencyFactor; #endif #if USE_TRANSPARENCY_MAP - alpha = texture(transparencyMap, TEXTURE_UV).a; + alpha = texture(transparencyMap, TEXTURE_UV).TRANSPARENCY_MAP_CHANNEL; + #if DCC_APP_NAME == DCC_APP_MAYA + alpha = 1.0 - alpha; + #endif #endif if (alpha < alphaThreshold) discard; #endif @@ -280,7 +293,10 @@ CCProgram surface-fragment %{ baseColor.rgb *= diffuseFactor; #if USE_TRANSPARENCY_MAP - baseColor.a = texture(transparencyMap, TEXTURE_UV).a; + baseColor.a = texture(transparencyMap, TEXTURE_UV).TRANSPARENCY_MAP_CHANNEL; + #if DCC_APP_NAME == DCC_APP_MAYA + baseColor.a = 1.0 - baseColor.a; + #endif #endif #if USE_ALPHA_TEST @@ -289,9 +305,13 @@ CCProgram surface-fragment %{ vec4 specularColorAndFactor = getSpecularColorAndFactor(); //glossiness - float inGlossiness = 0.0, inSpecularIntensity = specularColorAndFactor.w; + float inGlossiness = 0.0, inSpecularIntensity = 1.0; #if HAS_EXPORTED_GLOSSINESS - inGlossiness = glossiness; + #if USE_SPECULAR_GLOSSINESS_MAP + inGlossiness = 1.0 - texture(specularGlossinessMap, TEXTURE_UV).a; + #else + inGlossiness = glossiness; + #endif #else #if USE_SHININESS_MAP #if GLOSSINESS_MAP_USE_SINGLE_CHANNEL