add eye shader (#14758)

This commit is contained in:
jk20012001
2023-04-10 17:21:39 +08:00
committed by GitHub
parent db5ed8653d
commit d570fd9aa2
6 changed files with 597 additions and 1 deletions
+168
View File
@@ -0,0 +1,168 @@
#include <common/graph-expression/base>
vec3 lerp_3Color(vec3 A, vec3 B, vec3 C, float alpha)
{
float alpha1 = saturate(alpha * 2.0);
float alpha2 = saturate(alpha * 2.0 - 1.0);
vec3 AB = lerp(A, B, alpha1);
return lerp(AB, C, alpha2);
}
vec3 GetIrisUVMask(float IrisUVRadius)
{
const float IrisBorderWidth = 0.04, IrisBleedWidth = 0.035, IrisMaskWidth = 0.045;
vec3 arg3_LimbusUVWidth = vec3(IrisBorderWidth, IrisBleedWidth, IrisMaskWidth);
float arg8_IrisUVRadius = IrisUVRadius * 0.03 + 0.15;
// vec3 out_IrisUVMask = Custom1(IrisUVRadius,UV,LimbusUVWidth)
{
float IrisUVRadiusTemp = arg8_IrisUVRadius;
vec2 UV = FSInput_texcoord;
vec3 LimbusUVWidth = arg3_LimbusUVWidth;
UV = UV - vec2(0.5, 0.5);
vec3 r = (vec3(length(UV)) - (vec3(IrisUVRadiusTemp) - LimbusUVWidth)) / LimbusUVWidth;
return smoothstep(0.0, 1.0, saturate(vec3(1.0) - r));
}
}
vec2 GetIrisUV(vec2 refractedUV, float IrisUVRadius, float PupilScale)
{
// code between Refract->Parallax, for control pupil size
const float PupilShiftX = 0.0, PupilShiftY = 0.0, ScaleIrisWithinMask = 1.0;
float uvRadius = (IrisUVRadius*0.03+0.15) * 2.0;
vec2 UV1 = refractedUV - vec2(0.5);
vec2 UV =(UV1 / uvRadius) + vec2(0.5);
vec2 UVscaled;// = ScalePupils(UV,PupilScale1,PupilShiftX1,PupilShiftY1)
{
float ShiftMask = pow(saturate(-4.0 * (distance(vec2(0.5), UV) - 0.45)),0.7);
vec2 UVshifted = UV + vec2(PupilShiftX * (ShiftMask * -0.1), PupilShiftY * (ShiftMask * 0.1));
vec2 UVcentered = UVshifted - vec2(0.5, 0.5);
float UVlength = length(UVcentered);
// UV on circle at distance 0.5 from the center, in direction of original UV
vec2 UVmax = normalize(UVcentered) * 0.5;
UVscaled = lerp(UVmax, vec2(0.0, 0.0), saturate((1.0 - UVlength * 2.0) * PupilScale)) + vec2(0.5, 0.5);
}
float TextureScale = ScaleIrisWithinMask;
vec2 UVs_out;// = ScaleUVsByCenter(UVscaled,TextureScale)
{
UVs_out = (UVscaled - vec2(0.5)) * TextureScale + vec2(0.5);
}
return UVs_out;
}
vec3 GetGeneratedColorForIris(vec2 irisUV, sampler2D irisColorMap, float IrisColor1U, float IrisColor2U, float IrisColor1Bright, float IrisColor2Bright)
{
//MF_irisGenerator
// custom pupil spherical scaling, should after refraction
/* vec2 centeredUV = (irisUV - vec2(0.5)) * 2.0;
float lengthUV = length(centeredUV);
vec2 dirUV = normalize(centeredUV);
irisUV = pow(lengthUV, pupilScale) * dirUV * 0.5 + vec2(0.5);
*/
const float IrisColor1V = 0.3, IrisColor2V = 0.3, IrisColorValueVariation = 0.25, IrisColorHueVariation = 0.1;
const float IrisColorBalance = 0.5, IrisColorBalanceSmoothness = 0.5, IrisSaturationVariation = 0.25;
const float RadialStructuralBlendSwitch = 0.0, LimbusDarkAmount = 0.5, AOinIris = 0.7;
vec4 M_Tex = texture(irisColorMap/*T_Iris_A_M*/, irisUV);
vec2 uv1 = vec2(IrisColor2U - IrisColorHueVariation, IrisColor2V + IrisColorValueVariation);
vec2 uv2 = vec2(IrisColor2U + IrisColorHueVariation, IrisColor2V - IrisColorHueVariation);
vec2 uv3 = vec2(IrisColor1U - IrisColorHueVariation, IrisColor1V + IrisColorValueVariation);
vec2 uv4 = vec2(IrisColor1U + IrisColorHueVariation, IrisColor1V - IrisColorValueVariation);
vec3 col2 = SRGBToLinear(texture(irisGradientMap, vec2(IrisColor2U, IrisColor2V)).rgb) * IrisColor2Bright;
vec3 col2_hue1 = SRGBToLinear(texture(irisGradientMap, uv1).rgb) * IrisColor2Bright;
vec3 col2_hue2 = SRGBToLinear(texture(irisGradientMap, uv2).rgb) * IrisColor2Bright;
vec3 col1 = SRGBToLinear(texture(irisGradientMap, vec2(IrisColor1U, IrisColor1V)).rgb) * IrisColor1Bright;
vec3 col1_hue1 = SRGBToLinear(texture(irisGradientMap, uv3).rgb) * IrisColor1Bright;
vec3 col1_hue2 = SRGBToLinear(texture(irisGradientMap, uv4).rgb) * IrisColor1Bright;
float minValue = IrisColorBalance - IrisColorBalanceSmoothness;
float maxValue = IrisColorBalance + IrisColorBalanceSmoothness;
vec2 invMaskRB = vec2(1.0) - M_Tex.rb;
vec2 alphaRB = smoothstep(minValue, maxValue, invMaskRB);
float Fraction = lerp(-1.0, 1.0, M_Tex.r) * IrisSaturationVariation;
vec3 desat_col1 = Desaturation(lerp_3Color(col1_hue2, col1, col1_hue1, M_Tex.r), Fraction);
vec3 desat_col2 = Desaturation(lerp_3Color(col2_hue2, col2, col2_hue1, M_Tex.r), Fraction);
vec3 b = lerp(desat_col2, desat_col1, alphaRB.x);
vec3 a = lerp(desat_col2, desat_col1, alphaRB.y);
vec3 lerpedColor = lerp(a, b, RadialStructuralBlendSwitch) * M_Tex.a;
vec3 base = lerpedColor * lerp(1.0, M_Tex.g, AOinIris);
float radius = distance(irisUV - vec2(0.5), vec2(0.0));
float alpha = smoothstep(0.275, 0.5, radius);
return lerp(base, pow(base, vec3(LimbusDarkAmount + 1.0)), alpha);
}
vec3 GetBlendColorForIrisAndSclera(vec3 irisUVMask, vec3 irisGeneratedColor, sampler2D irisHeightMapAlpha, sampler2D scleraDiffuse, sampler2D T_Veins_D, vec3 scleraTintColor, float VeinsPower, float scleraBright)
{
const float ScleraCornerDarkRadius = 0.6, ScleraCornerDarkHardness = 0.4, ScleraBrightness = 0.5, ScleraPower = 1.0, ScleraTintU = 0.2, ScleraTintV = 0.2, ScleraRotate = 0.0;
const float VeinsRotate = 0.0, IrisBrightness = 1.0, IrisSaturation = 0.5, CloudyIrisRadius = 0.13, CloudyIrisHardness = 0.0;
const vec4 ScleraCornerDarkColor = vec4(0.745,0.213,0.237,1), IrisBleedTint = vec4(1.0,1.0,1.0,1.0), CloudyIrisColor = vec4(0.009684,0.011247,0.015625,1.0);
float heightAlpha = texture(irisHeightMapAlpha, FSInput_texcoord).r;
vec2 scleraUV = Rotator(FSInput_texcoord, vec2(0.5,0.5), heightAlpha * ScleraRotate, 6.283);
vec2 veinsUV = Rotator(FSInput_texcoord, vec2(0.5,0.5), heightAlpha * VeinsRotate, 6.283);
vec3 scleraTexColor = SRGBToLinear(texture(/*T_Sclera_D*/scleraDiffuse, scleraUV).rgb) * scleraBright;
vec3 veinsTexColor = SRGBToLinear(texture(T_Veins_D, veinsUV).rgb) * scleraBright;
// use fixed color for optimizing, scleraTintColor = texture(T_sclera_tint_picker, vec2(ScleraTintU,ScleraTintV)).rgb;
vec3 scleraColor = pow(scleraTexColor, vec3(ScleraPower))*ScleraBrightness*1.1 + vec3(0.8);
scleraColor *= scleraTintColor;
vec3 bleededScleraColor = lerp(scleraColor, IrisBleedTint.rgb * scleraColor, irisUVMask.g);
vec3 veinsColor = pow(veinsTexColor, vec3(VeinsPower));
vec3 ScleraColor = bleededScleraColor * veinsColor;
vec3 irisColor = Desaturation(irisGeneratedColor * IrisBrightness, (IrisSaturation - 0.5) * -2.0);
vec3 lerpedScleraAndIris = lerp(ScleraColor, irisColor, irisUVMask.r);
vec3 cloudyPupilAddColor = SphereMask(FSInput_texcoord, vec2(0.5), CloudyIrisRadius, CloudyIrisHardness) * CloudyIrisColor.rgb;
float scleraCornerDarkMask = SphereMask(FSInput_texcoord, vec2(0.5), ScleraCornerDarkRadius, ScleraCornerDarkHardness);
vec3 ScleraCorner = lerp(ScleraCornerDarkColor.rgb, vec3(1.0), scleraCornerDarkMask);
vec3 BaseColor = ScleraCorner * (cloudyPupilAddColor + lerpedScleraAndIris);
return BaseColor;
}
// unused
// out_RefractedUV = GetRefractedUV(out_IrisUVMask, irisHeightMap, irisNormalMap, viewDir, IrisUVRadius, CONREAL_IOR);
vec2 GetRefractedUV(vec3 irisUVMask, sampler2D irisHeightMap, sampler2D T_Eye_N, vec3 viewDir, float IrisUVRadius, float internalIoR)
{
const float RefractionDepthScale = 1.2;
vec3 normalW = normalize(FSInput_worldNormal), cameraW = viewDir;
vec3 RefractionDirection;
// RefractionDirection = custom2(internalloR,normalW,cameraW)
{
float n = internalIoR;
float facing = dot(normalW, cameraW);
float w = n * facing;
float k = sqrt(1.0+(w-n)*(w+n));
vec3 t;
t = (w - k)*normalW - n*cameraW;
t = normalize(t);
RefractionDirection = -t;
}
float arg8_IrisUVRadius = IrisUVRadius * 0.03 + 0.15;
vec2 arg2_UV = FSInput_texcoord;
float arg4_DepthScale = RefractionDepthScale;
float arg5_DepthPlaneOffset = SampleTextureExr(irisHeightMap, vec2(arg8_IrisUVRadius + 0.5, 0.5)).r;
vec3 arg6_MidPlaneDisplacement = SampleTextureExr(irisHeightMap, FSInput_texcoord).rgb;
vec3 arg7_EyeDirectionWorld = TransformNormalMap(texture(T_Eye_N, FSInput_texcoord).rgb);
vec3 a5 = max(arg6_MidPlaneDisplacement - arg5_DepthPlaneOffset, vec3(0.0)) * arg4_DepthScale;
float b5 = lerp(0.325, 1.0, dot(cameraW,arg7_EyeDirectionWorld) * dot(cameraW,arg7_EyeDirectionWorld));
vec3 heightW = a5 / b5;
vec3 b3 = RefractionDirection*heightW;
vec3 a3 = normalize(FSInput_worldTangent - dot(FSInput_worldTangent, arg7_EyeDirectionWorld) * arg7_EyeDirectionWorld);
vec3 a4 = cross(a3,arg7_EyeDirectionWorld);
vec3 b4 = b3;
vec2 b2 = vec2(dot(a3,b3),dot(a4,b4));
// float VectorLength = distance(vec2(0.0), vec2(arg8_IrisUVRadius*vec2(-1.0,1.0)*b2));
// float out_Transparency = VectorLength - arg8_IrisUVRadius;
vec2 a1 = arg2_UV;
vec2 b1 = vec2(arg8_IrisUVRadius) * vec2(-1.0,1.0)*b2 + arg2_UV;
float alpha1 = irisUVMask.r;
return lerp(a1,b1,alpha1);
}
@@ -0,0 +1,9 @@
{
"ver": "1.0.7",
"importer": "effect-header",
"imported": true,
"uuid": "bce797be-05d4-400e-8eb8-f2816147b869",
"files": [],
"subMetas": {},
"userData": {}
}
+408
View File
@@ -0,0 +1,408 @@
// Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
CCEffect %{
techniques:
- name: opaque
passes:
- vert: standard-vs
frag: standard-fs
properties: &props
occlusion: { value: 1.0, target: pbrParams.x, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
roughness: { value: 0.07, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
metallic: { value: 0.0, target: pbrParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
specularIntensity: { value: 1.0, target: pbrParams.w, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
normalStrength: { value: 1.0, target: emissiveScaleParam.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } }
mainTexture: { value: grey, target: albedoMap, editor: { displayName: ScleraColorMap, tooltip: 'T_Sclera_D' } }
normalMap: { value: normal, editor: { displayName: ScleraNormalMap, tooltip: 'T_Sclera_N' } }
occlusionMap: { value: white }
irisGradientMap: { value: white, editor: { tooltip: 'T_Eye_Gradient' } }
irisColorMaskMap: { value: black, editor: { tooltip: 'T_Iris_A_M' } }
veinsColorMap: { value: black, editor: { tooltip: 'T_Veins_D' } }
irisNormalMap: { value: normal, editor: { parent: USE_IRIS_REFRACTION, tooltip: 'normalMap with conreal shape like T_Eye_N' } }
irisHeightMap: { value: black, editor: { tooltip: 'T_EyeMidPlaneDisplacement' } }
irisHeightMapAlpha: { value: black, editor: { tooltip: 'T_EyeMidPlaneDisplacement Alpha Channel' } }
irisHeightScale: { value: 1.0, target: irisParams.x, editor: { parent: USE_IRIS_REFRACTION, slide: true, range: [0, 5.0], step: 0.001 } }
irisScale: { value: 0.5, target: irisParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
pupilScale: { value: 1.0, target: irisParams.w, editor: { slide: true, range: [1.0, 3.0], step: 0.001 } }
veinsBleeding: { value: 1.5, target: irisParams.y, editor: { slide: true, range: [0.0, 3.0], step: 0.001 } }
irisMainColor: { value: 0.8, target: irisColorParams.x, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
irisMainBright: { value: 1.0, target: irisColorParams.y, editor: { slide: true, range: [0.0, 5.0], step: 0.001 } }
irisEdgeColor: { value: 0.5, target: irisColorParams.z, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
irisEdgeBright: { value: 1.0, target: irisColorParams.w, editor: { slide: true, range: [0.0, 5.0], step: 0.001 } }
reflectionEnhancement: { value: 1.5, target: emissiveScaleParam.x, editor: { slide: true, range: [1.0, 3.0], step: 0.001 } }
scleraBright: { value: 1.0, target: emissiveScaleParam.y, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
causticsPosition: { value: 0.3, target: causticsParams.x, editor: { parent: USE_IRIS_CAUSTICS, slide: true, range: [0.0, 1.0], step: 0.001 } }
causticsWidth: { value: 0.3, target: causticsParams.y, editor: { parent: USE_IRIS_CAUSTICS, slide: true, range: [0.0, 1.0], step: 0.001 } }
causticsIntensity: { value: 1.0, target: causticsParams.w, editor: { parent: USE_IRIS_CAUSTICS, slide: true, range: [0.0, 3.0], step: 0.001 } }
- &forward-add
vert: standard-vs
frag: standard-fs
phase: forward-add
propertyIndex: 0
embeddedMacros: { CC_FORWARD_ADD: true }
depthStencilState:
depthFunc: equal
depthTest: true
depthWrite: false
blendState:
targets:
- blend: true
blendSrc: one
blendDst: one
blendSrcAlpha: zero
blendDstAlpha: one
- &shadow-caster
vert: shadow-caster-vs
frag: shadow-caster-fs
phase: shadow-caster
propertyIndex: 0
rasterizerState:
cullMode: front
properties:
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
- &reflect-map
vert: standard-vs
frag: reflect-map-fs
phase: reflect-map
propertyIndex: 0
- name: transparent
passes:
- vert: standard-vs
frag: standard-fs
embeddedMacros: { CC_FORCE_FORWARD_SHADING: true }
depthStencilState:
depthTest: true
depthWrite: false
blendState:
targets:
- blend: true
blendSrc: src_alpha
blendDst: one_minus_src_alpha
blendDstAlpha: one_minus_src_alpha
properties: *props
- *forward-add
- *shadow-caster
}%
CCProgram shared-ubos %{
uniform Constants {
vec4 pbrParams;
vec4 emissiveScaleParam;
vec4 irisParams;
vec4 irisColorParams;
vec4 causticsParams;
};
}%
CCProgram macro-remapping %{
// depend on UI macros
#if USE_NORMAL_MAP
#define CC_SURFACES_USE_TANGENT_SPACE 1
#endif
}%
CCProgram surface-vertex %{
out vec4 v_planeN;
out vec4 v_planeT;
#define CC_SURFACES_VERTEX_MODIFY_LOCAL_SHARED_DATA
void SurfacesVertexModifyLocalSharedData(inout SurfacesStandardVertexIntermediate In)
{
mat4 matWorld, matWorldIT;
CCGetWorldMatrixFull(matWorld, matWorldIT);
v_planeN.xyz = normalize((matWorldIT * vec4(0.0, 0.0, 1.0, 0.0)).xyz); // meta human exported mesh is facing to Z-Axis
v_planeT.xyz = normalize((matWorldIT * vec4(1.0, 0.0, 0.0, 0.0)).xyz);
v_planeN.w = v_planeT.w = 1.0;
}
}%
CCProgram surface-fragment %{
uniform sampler2D albedoMap;
#if USE_NORMAL_MAP
uniform sampler2D normalMap;
#endif
#if USE_OCCLUSION_MAP
uniform sampler2D occlusionMap;
#endif
////////////////////////////////////////////////////////////////User Define
in vec4 v_planeN;
in vec4 v_planeT;
#if USE_IRIS_REFRACTION
uniform sampler2D irisNormalMap;
#endif
uniform sampler2D irisHeightMap;
uniform sampler2D irisHeightMapAlpha;
uniform sampler2D irisColorMaskMap;
uniform sampler2D irisGradientMap;
uniform sampler2D veinsColorMap;
#define CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL
vec3 SurfacesFragmentModifyWorldNormal()
{
vec3 normal = FSInput_worldNormal;
#if USE_NORMAL_MAP
vec3 nmmp = texture(normalMap, FSInput_texcoord).xyz - vec3(0.5);
normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleParam.w, normal.xyz, FSInput_worldTangent, FSInput_mirrorNormal);
#endif
return normalize(normal);
}
#define CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS
vec4 SurfacesFragmentModifyPBRParams()
{
vec4 pbr = pbrParams;
pbr.x = 1.0;
#if USE_OCCLUSION_MAP
pbr.x = mix(1.0, texture(occlusionMap, FSInput_texcoord).r, pbrParams.x);
#endif
return pbr;
}
#include <common/texture/texture-misc>
#include <common/lighting/functions>
#include <eye>
#define CONREAL_IOR 1.336
vec2 GetEllipseRefractionOffset(vec3 planeN, vec3 planeT, vec3 planeB, vec3 conrealNormal, vec3 refractDir, float height)
{
float NoR = dot(conrealNormal, -refractDir);
float lenR = height / max(NoR, EPSILON_LOWP);
vec3 refract = refractDir * lenR;
// project R onto plane UV space, -B for Y -> V dir correction
return vec2(dot(refract, planeT), dot(refract, -planeB));
}
// definition of SurfacesMaterialData structure with corresponding shading-model
#include <surfaces/data-structures/standard>
//see <surfaces/default-functions/XXXX> for more overrided functions, XXXX is shading-model name
#define CC_SURFACES_FRAGMENT_MODIFY_SHARED_DATA
void SurfacesFragmentModifySharedData(inout SurfacesMaterialData surfaceData)
{
vec3 worldPos;
HIGHP_VALUE_FROM_STRUCT_DEFINED(worldPos, surfaceData.worldPos);
float irisHeightScale = irisParams.x;
float IrisUVRadius = irisParams.z * 2.0; // default is 0.5
float PupilScale = irisParams.w;
float VeinsPower = irisParams.y;
float IrisColor1U = irisColorParams.x; // default is 0.8 for asian
float IrisColor2U = irisColorParams.z; // default is 0.5 for asian
float IrisColor1Bright = irisColorParams.y;
float IrisColor2Bright = irisColorParams.w;
float scleraBright = emissiveScaleParam.y;
vec3 scleraTintColor = vec3(1.0);
vec3 viewDir = normalize(cc_cameraPos.xyz - worldPos);
// vec2 irisUV = (FSInput_texcoord - vec2(0.5)) / IrisScale + vec2(0.5);
// if (irisUV.x > 0.0 && irisUV.y > 0.0 && irisUV.x < 1.0 && irisUV.y < 1.0)
// Iris Mask with Limbus Ring falloff
vec3 out_IrisUVMask = GetIrisUVMask(IrisUVRadius);
// Refraction
vec2 out_RefractedUV = FSInput_texcoord;
#if USE_IRIS_REFRACTION
float texHeight = SampleTextureExr(irisHeightMap, FSInput_texcoord).x;
float height = texHeight * irisHeightScale;
vec3 irisN = normalize(FSInput_worldNormal);
vec3 R = CalculateRefractDirection(irisN, viewDir, dot(irisN, viewDir), CONREAL_IOR);
vec3 receivePlaneN = v_planeN.xyz;
vec3 receivePlaneT = v_planeT.xyz;
vec3 receivePlaneB = CalculateBinormal(receivePlaneN, receivePlaneT, 1.0);
vec2 uv_offset = GetEllipseRefractionOffset(receivePlaneN, receivePlaneT, receivePlaneB, irisN, normalize(R), height);
out_RefractedUV = saturate(FSInput_texcoord + uv_offset /** texHeight*/ * 0.1); //需要边缘位移稍微小一点的话就加texHeight
#endif
// scaling pupil
vec2 out_IrisUV = GetIrisUV(out_RefractedUV, IrisUVRadius, PupilScale);
// generating iris color
vec3 out_IrisGeneratedColor = GetGeneratedColorForIris(out_IrisUV, irisColorMaskMap, IrisColor1U, IrisColor2U, IrisColor1Bright, IrisColor2Bright);
// blend iris and sclera use IrisMask
surfaceData.baseColor.rgb = GetBlendColorForIrisAndSclera(out_IrisUVMask, out_IrisGeneratedColor, irisHeightMapAlpha, albedoMap, veinsColorMap, scleraTintColor, VeinsPower, scleraBright);
// flatterned normal for iris area
surfaceData.worldNormal = normalize(lerp(surfaceData.worldNormal, FSInput_worldNormal, out_IrisUVMask.r));
// iris area flag (UVMask) and attenuation for caustics
// irisUVMask area is a little bit larger than irisGeneratedColor
float irisAttenuation = saturate(out_IrisUVMask.r * length(out_IrisGeneratedColor) * 10.0);
surfaceData.ior = irisAttenuation;
surfaceData.emissive = out_IrisUVMask;
}
// see <lighting-models/default-functions/XXXX> for more overrided functions, XXXX is lighting-model name
#include <lighting-models/includes/standard>
#define CC_SURFACES_LIGHTING_MODIFY_FINAL_RESULT
void SurfacesLightingModifyFinalResult(inout LightingResult result, in LightingIntermediateData lightingData, in SurfacesMaterialData surfaceData, in LightingMiscData miscData)
{
#if USE_IRIS_REFRACTION
vec3 worldPos;
HIGHP_VALUE_FROM_STRUCT_DEFINED(worldPos, surfaceData.worldPos);
vec3 L = lightingData.L;
vec3 viewDir = normalize(cc_cameraPos.xyz - worldPos);
LightingIntermediateData lightingDataRefract = lightingData;
vec3 newL = -CalculateRefractDirection(surfaceData.worldNormal, L, dot(surfaceData.worldNormal, L), CONREAL_IOR);
CCSurfacesLightingGetIntermediateData_PerLight(lightingDataRefract, newL);
if (surfaceData.emissive.x > 0.0) {
result.directSpecular = CalculateDirectSpecular(lightingDataRefract, miscData.lightColorAndIntensity);
#if !CC_FORWARD_ADD
lightingDataRefract.V = -CalculateRefractDirection(surfaceData.worldNormal, viewDir, dot(surfaceData.worldNormal, viewDir), CONREAL_IOR);
result.environmentSpecular = CalculateEnvironmentSpecular(lightingDataRefract, cc_ambientSky.w);
#endif
}
#endif
// enhanced more contrast for brighter part
result.environmentSpecular = pow(result.environmentSpecular, vec3(emissiveScaleParam.x));
#if USE_SCLERA_SSS
LightingIntermediateData lightingData3S = lightingData;
lightingData3S.N = normalize(FSInput_worldNormal);
CCSurfacesLightingGetIntermediateData_PerLight(lightingData3S, lightingData.L);
result.directDiffuse = CalculateDirectDiffuse(lightingData3S, miscData.lightColorAndIntensity);
#endif
#if USE_IRIS_CAUSTICS
vec3 receivePlaneN = v_planeN.xyz;
vec3 receivePlaneT = v_planeT.xyz;
vec3 receivePlaneB = CalculateBinormal(receivePlaneN, receivePlaneT, 1.0);
// conreal back face normal has inverse projector dir with plane T B
float projectorN = dot(surfaceData.worldNormal, receivePlaneN);
float projectorT = dot(surfaceData.worldNormal, receivePlaneT);
float projectorB = dot(surfaceData.worldNormal, receivePlaneB);
vec3 backN = normalize(projectorN * receivePlaneN - projectorT * receivePlaneT - projectorB * receivePlaneB);
LightingIntermediateData lightingDataCaustics = lightingData;
lightingDataCaustics.N = backN;
CCSurfacesLightingGetIntermediateData_PerLight(lightingDataCaustics, lightingData.L);
float causticsIntensity = causticsParams.w;
float irisMaskAttenuation = surfaceData.ior;
#if USE_IRIS_CAUSTICS_RANGE
// rangeFilter results according to UV distribution, 5.0 can be modified to match different UVs
float uvLength = saturate(length(FSInput_texcoord - vec2(0.5)) * 5.0);
float start = causticsParams.x, end = saturate(start + causticsParams.y), widthAtten = 0.2;
float rangeFilter = saturate(smoothstep(start, end, uvLength)) * (1.0 - saturate(smoothstep(end, saturate(end + widthAtten), uvLength)));
// rangeFilter can be ignored
irisMaskAttenuation *= rangeFilter;
#endif
vec3 directCaustics = vec3(pow(lightingDataCaustics.NoLSat, 10.0)) * 2.0;
result.directDiffuse += directCaustics * causticsIntensity * irisMaskAttenuation * miscData.lightColorAndIntensity.rgb * miscData.lightColorAndIntensity.w;
#if !CC_FORWARD_ADD
vec3 envCaustics = CalculateEnvironmentDiffuse(lightingDataCaustics, 1.0);
envCaustics = pow(envCaustics, vec3(4.0)) * 0.5;
result.environmentDiffuse += envCaustics * causticsIntensity * irisMaskAttenuation * cc_ambientSky.w;
#endif
#endif
// restore emissive
result.emissive = vec3(0.0);
}
}%
CCProgram standard-vs %{
precision highp float;
// 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
#include <macro-remapping>
#include <surfaces/effect-macros/common-macros>
// 2. common include with corresponding shader stage, include before surface functions
#include <surfaces/includes/common-vs>
// 3. user surface functions that can use user (effect) parameters (ubo Constants)
// see surfaces/default-functions/xxx.chunk
#include <shared-ubos>
#include <surface-vertex>
// 4. surface include with corresponding shader stage and shading-model (optional)
#include <surfaces/includes/standard-vs>
// 5. shader entry with corresponding shader stage and technique usage/type
#include <shading-entries/main-functions/render-to-scene/vs>
}%
CCProgram shadow-caster-vs %{
precision highp float;
#include <surfaces/effect-macros/render-to-shadowmap>
#include <surfaces/includes/common-vs>
#include <shared-ubos>
#include <surface-vertex>
#include <shading-entries/main-functions/render-to-shadowmap/vs>
}%
CCProgram standard-fs %{
// shading-model : standard
// lighting-model : standard (isotropy / anisotropy pbr)
// shader stage : fs
// technique usage/type : render-to-scene
precision highp float;
// 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
#include <macro-remapping>
#include <surfaces/effect-macros/common-macros>
// 2. common include with corresponding shader stage, include before surface functions
#include <surfaces/includes/common-fs>
// 3. user surface functions that can use user (effect) parameters (ubo Constants)
// see surfaces/default-functions/xxx.chunk
#include <shared-ubos>
#include <surface-fragment>
// 4. lighting-model (optional)
#include <lighting-models/includes/standard>
// 5. surface include with corresponding shader stage and shading-model (optional)
#include <surfaces/includes/standard-fs>
// 6. shader entry with corresponding shader stage and technique usage/type
#include <shading-entries/main-functions/render-to-scene/fs>
}%
CCProgram shadow-caster-fs %{
precision highp float;
#include <surfaces/effect-macros/render-to-shadowmap>
#include <surfaces/includes/common-fs>
#include <shared-ubos>
#include <surface-fragment>
#include <shading-entries/main-functions/render-to-shadowmap/fs>
}%
CCProgram reflect-map-fs %{
precision highp float;
#include <macro-remapping>
#include <surfaces/effect-macros/common-macros>
#include <surfaces/includes/common-fs>
#include <shared-ubos>
#include <surface-fragment>
#include <lighting-models/includes/standard>
#include <surfaces/includes/standard-fs>
#include <shading-entries/main-functions/render-to-reflectmap/fs>
}%
@@ -0,0 +1,11 @@
{
"ver": "1.7.0",
"importer": "effect",
"imported": true,
"uuid": "f0475923-826e-45dc-85cc-b5d9c2b220e9",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}
Binary file not shown.
File diff suppressed because one or more lines are too long