diff --git a/show-material/assets/effects/standard-fresnel-ibl.effect b/show-material/assets/effects/standard-fresnel-ibl.effect index 9f2af22..3603c6f 100644 --- a/show-material/assets/effects/standard-fresnel-ibl.effect +++ b/show-material/assets/effects/standard-fresnel-ibl.effect @@ -13,13 +13,14 @@ CCEffect %{ alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST, slide: true, range: [0, 1.0], step: 0.001 } } occlusion: { value: 1.0, target: pbrParams.x, editor: { slide: true, range: [0, 1.0], step: 0.001 } } roughness: { value: 0.8, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } } + metallic: { value: 0.6, target: pbrParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } } + SpecularIntensity: { value: 0.5, target: pbrParams.w, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } } highlightColor: { value: [0.8, 0.8, 0.8, 1.0], editor: { displayName: Highlight Color, type: color } } Fresnelcol: { value: [0.9, 0.9, 0.9, 1.0], editor: { displayName: Fresnel Color, type: color } } - _fresnelBase: { value: 0.1, target: rampParams.x, editor: { range: [0.1, 1.0] } } - _fresnelScale: { value: 0.5, target: rampParams.y, editor: { range: [0.1, 1.0] } } - _fresnelIndensity: { value: 5.0, target: rampParams.z, editor: { range: [0.0, 5.0] } } - metallic: { value: 0.6, target: pbrParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } } - normalStrenth: { value: 1.0, target: pbrParams.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 1.0], step: 0.001 } } + _fresnelBase: { value: 0.1, target: rampParams.x, editor: { slide: true, range: [0.1, 1.0], step: 0.001 } } + _fresnelScale: { value: 0.5, target: rampParams.y, editor: { slide: true, range: [0.1, 1.0], step: 0.001 } } + _fresnelIndensity: { value: 5.0, target: rampParams.z, editor: { slide: true, range: [0.0, 5.0], step: 0.001 } } + normalStrenth: { value: 1.0, target: rampParams.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 1.0], step: 0.001 } } emissive: { value: [0.0, 0.0, 0.0, 1.0], editor: { type: color } } emissiveScale: { value: [1.0, 1.0, 1.0], target: emissiveScaleParam.xyz } mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } @@ -75,11 +76,6 @@ CCEffect %{ alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } } occlusion: { value: 1.0, target: pbrParams.x } roughness: { value: 0.8, target: pbrParams.y } - highlightColor: { value: [0.8, 0.8, 0.8, 1.0], editor: { displayName: Highlight Color, type: color } } - Fresnelcol: { value: [0.9, 0.9, 0.9, 1.0], editor: { displayName: Fresnel Color, type: color } } - _fresnelBase: { value: 0.1, target: rampParams.x, editor: { range: [0.1, 1.0] } } - _fresnelScale: { value: 0.5, target: rampParams.y, editor: { range: [0.1, 1.0] } } - _fresnelIndensity: { value: 5.0, target: rampParams.z, editor: { range: [0.0, 5.0] } } metallic: { value: 0.6, target: pbrParams.z } normalStrenth: { value: 1.0, target: pbrParams.w, editor: { parent: USE_NORMAL_MAP } } emissive: { value: [0.0, 0.0, 0.0, 1.0], editor: { type: color } } @@ -242,6 +238,7 @@ CCProgram standard-fs %{ #define OCCLUSION_CHANNEL r #define ROUGHNESS_CHANNEL g #define METALLIC_CHANNEL b + #define SpecularIntensity_CHANNEL w #if USE_ALPHA_TEST #pragma define ALPHA_TEST_CHANNEL options([a, r]) @@ -249,7 +246,8 @@ CCProgram standard-fs %{ void surf (out StandardSurface s) { vec4 baseColor = albedo; - #if USE_VERTEX_COLORnp + #if USE_VERTEX_COLOR + baseColor.rgb *= SRGBToLinear(v_color.rgb);//use linear baseColor *= v_color; #endif #if USE_ALBEDO_MAP @@ -267,7 +265,24 @@ CCProgram standard-fs %{ float fresnel = fresnelBase + fresnelScale*pow(1.0 - dot(N, viewDir), fresnelIndensity); s.albedo = baseColor; s.albedo.rgb *= albedoScaleAndCutoff.xyz; - s.albedo.rgb += mix((s.albedo.rgb)+(highlightColor.rgb), Fresnelcol.rgb, fresnel) * Fresnelcol.a; + + vec3 fresnel_color = Fresnelcol.rgb; + #if CC_USE_IBL + vec3 RR = -viewDir; + vec4 envmap = fragTextureLod(cc_environment, RR, cc_ambientGround.w); + #if CC_USE_IBL == IBL_RGBE + vec3 env = unpackRGBE(envmap); + #else + vec3 env = SRGBToLinear(envmap.rgb); + #endif + fresnel_color = env * cc_ambientSky.w * 50.0; + #endif + + + + + + s.albedo.rgb += mix((s.albedo.rgb)+(highlightColor.rgb),fresnel_color.rgb, fresnel) * Fresnelcol.a; #if USE_ALPHA_TEST @@ -284,20 +299,24 @@ CCProgram standard-fs %{ #if USE_NORMAL_MAP vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5); s.normal = - (nmmp.x * pbrParams.w) * normalize(v_tangent) + - (nmmp.y * pbrParams.w) * normalize(v_bitangent) + + (nmmp.x * rampParams.w) * normalize(v_tangent) + + (nmmp.y * rampParams.w) * normalize(v_bitangent) + nmmp.z * normalize(s.normal); #endif s.position = v_position; vec4 pbr = pbrParams; + #if USE_PBR_MAP vec4 res = texture(pbrMap, PBR_UV); pbr.x *= res.OCCLUSION_CHANNEL; pbr.y *= res.ROUGHNESS_CHANNEL; pbr.z *= res.METALLIC_CHANNEL; + pbr.w *= res.SpecularIntensity_CHANNEL;//F0 #endif + + #if USE_METALLIC_ROUGHNESS_MAP vec4 metallicRoughness = texture(metallicRoughnessMap, PBR_UV); pbr.z *= metallicRoughness.METALLIC_CHANNEL; @@ -309,6 +328,7 @@ CCProgram standard-fs %{ s.occlusion = clamp(pbr.x, 0.0, 0.96); s.roughness = clamp(pbr.y, 0.04, 1.0); s.metallic = pbr.z; + s.SpecularIntensity = pbr.w; s.emissive = emissive.rgb * emissiveScaleParam.xyz; #if USE_EMISSIVE_MAP