Skip to content

update effect #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v3.3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions show-material/assets/effects/standard-fresnel-ibl.effect
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }
Expand Down Expand Up @@ -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 } }
Expand Down Expand Up @@ -242,14 +238,16 @@ 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])
#endif

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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand Down