Skip to content

Commit

Permalink
Merge pull request #300 from JujieX/feat/upgradeBranch
Browse files Browse the repository at this point in the history
Merge dev/1.3 Updates into Main Branch
  • Loading branch information
JujieX authored Aug 2, 2024
2 parents d630224 + 1ede3e9 commit 2ca0822
Show file tree
Hide file tree
Showing 106 changed files with 3,205 additions and 1,318 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"pnpm": {
"overrides": {
"@galacean/engine": "^1.2.0-alpha.5"
"@galacean/engine": "^1.3.0-beta.6"
}
}
}
4 changes: 2 additions & 2 deletions packages/auxiliary-lines/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-toolkit-auxiliary-lines",
"version": "1.2.0",
"version": "1.3.0-beta.2",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
Expand All @@ -24,7 +24,7 @@
"types/**/*"
],
"peerDependencies": {
"@galacean/engine": "^1.2.0-alpha.5"
"@galacean/engine": "^1.3.0-beta.6"
},
"dependencies": {
"@galacean/engine-toolkit-custom-material": "workspace:*"
Expand Down
4 changes: 2 additions & 2 deletions packages/controls/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-toolkit-controls",
"version": "1.2.0",
"version": "1.3.0-beta.2",
"license": "MIT",
"publishConfig": {
"access": "public",
Expand All @@ -24,6 +24,6 @@
"types/**/*"
],
"peerDependencies": {
"@galacean/engine": "^1.2.0-alpha.5"
"@galacean/engine": "^1.3.0-beta.6"
}
}
4 changes: 2 additions & 2 deletions packages/custom-gltf-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-toolkit-custom-gltf-parser",
"version": "1.2.0",
"version": "1.3.0-beta.2",
"license": "MIT",
"scripts": {
"b:types": "tsc"
Expand All @@ -23,6 +23,6 @@
"types/**/*"
],
"peerDependencies": {
"@galacean/engine": "^1.2.0-alpha.5"
"@galacean/engine": "^1.3.0-beta.6"
}
}
4 changes: 2 additions & 2 deletions packages/custom-material/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-toolkit-custom-material",
"version": "1.2.0",
"version": "1.3.0-beta.2",
"license": "MIT",
"scripts": {
"b:types": "tsc",
Expand All @@ -24,6 +24,6 @@
"types/**/*"
],
"peerDependencies": {
"@galacean/engine": "^1.2.0-alpha.5"
"@galacean/engine": "^1.3.0-beta.6"
}
}
58 changes: 58 additions & 0 deletions packages/custom-material/src/advanced-shader/eye/Eye.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Shader "DigitalHuman/Eye.gs" {
EditorProperties {
Header("Sclera") {
material_ScleraColor("Sclera Color", Color) = (1,1,1,1);
material_ScleraSize("Sclera Size", Range(0, 5, 0.01)) = 1.0;
material_Metal("Sclera Specular", Range(0,1,0.01) ) = 0.2;
material_Roughness("Sclera Roughness", Range( 0, 1, 0.01 ) ) = 0.2;
material_ScleraNormalStrength("Sclera NormalStrength", Range(0, 5, 0.01)) = 1;
material_ScleraTexture("Sclera Texture", Texture2D);
material_ScleraNormal("Sclera NormalTexture", Texture2D);
material_ScleraMask("Sclera Mask", Texture2D);
}
Header("Iris") {
material_IrisColor("Iris Color", Color) = (1,1,1,1);
material_PupilSize("Pupil Dilation", Vector2) =(0.3, 0.3);
material_Limbal("Limbal Ring Amount", Range(0, 1, 0.01)) = 0.5;
material_IrisSize("Iris Size", Range(0, 5, 0.01)) = 2;
material_Parallax("Parallax Layer", Range(0, 0.5, 0.01)) = 0.08;
material_IrisNormalStrength("Iris NormalStrength", Range(0, 5, 0.01)) = 1;

material_IrisTexture("Iris Texture", Texture2D);
material_IrisNormal("Iris NormalTexture", Texture2D);
}

Header("Common") {
material_AlphaCutoff( "AlphaCutoff", Range(0, 1, 0.01) ) = 0;
}
}

EditorMacros {
Header("Conditional Macors") {
MATERIAL_IS_TRANSPARENT("IS_TRANSPARENT");
MATERIAL_IS_ALPHA_CUTOFF("IS_ALPHA_CUTOFF");
MATERIAL_HAS_SCLERA_NORMAL("HAS_SCLERA_NORMAL");
MATERIAL_HAS_IRIS_NORMAL("HAS_IRIS_NORMAL");
MATERIAL_HAS_SCLERA_MASK("HAS_SCLERA_MASK");
MATERIAL_HAS_IRIS_TEXTURE("HAS_IRIS_TEXTURE");
MATERIAL_HAS_SCLERA_TEXTURE("HAS_SCLERA_TEXTURE");
}

}

SubShader "Default" {
UsePass "pbr/Default/ShadowCaster"

Pass "Forward Pass" {
Tags { pipelineStage = "Forward"}

#define IS_METALLIC_WORKFLOW

VertexShader = PBRVertex;
FragmentShader = PBRFragment;

#include "./EyeForwardPass.glsl"
}
}
}

124 changes: 124 additions & 0 deletions packages/custom-material/src/advanced-shader/eye/EyeForwardPass.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#ifndef FORWARD_PASS_PBR_INCLUDED
#define FORWARD_PASS_PBR_INCLUDED

#include "Common.glsl"
#include "Fog.glsl"

#include "AttributesPBR.glsl"
#include "VaryingsPBR.glsl"
#include "LightDirectPBR.glsl"
#include "LightIndirectPBR.glsl"

#include "VertexPBR.glsl"
#include "FragmentPBR.glsl"

#include "./EyeFunction.glsl"

Varyings PBRVertex(Attributes attributes) {
Varyings varyings;

// Don't need tilling offest
varyings.uv = attributes.TEXCOORD_0;

#ifdef RENDERER_HAS_UV1
varyings.uv1 = attributes.TEXCOORD_1;
#endif

#ifdef RENDERER_ENABLE_VERTEXCOLOR
varyings.vertexColor = attributes.COLOR_0;
#endif


VertexInputs vertexInputs = getVertexInputs(attributes);

// positionWS
varyings.positionWS = vertexInputs.positionWS;

// positionVS
#if SCENE_FOG_MODE != 0
varyings.positionVS = vertexInputs.positionVS;
#endif

// normalWS、tangentWS、bitangentWS
#ifdef RENDERER_HAS_NORMAL
varyings.normalWS = vertexInputs.normalWS;
#ifdef RENDERER_HAS_TANGENT
varyings.tangentWS = vertexInputs.tangentWS;
varyings.bitangentWS = vertexInputs.bitangentWS;
#endif
#endif

// ShadowCoord
#if defined(NEED_CALCULATE_SHADOWS) && (SCENE_SHADOW_CASCADED_COUNT == 1)
varyings.shadowCoord = getShadowCoord(vertexInputs.positionWS);
#endif

gl_Position = renderer_MVPMat * vertexInputs.positionOS;

return varyings;
}


void PBRFragment(Varyings varyings) {
BRDFData brdfData;


// Get aoUV
vec2 aoUV = varyings.uv;
#if defined(MATERIAL_HAS_OCCLUSION_TEXTURE) && defined(RENDERER_HAS_UV1)
if(material_OcclusionTextureCoord == 1.0){
aoUV = varyings.uv1;
}
#endif

SurfaceData surfaceData = getSurfaceData(varyings, aoUV, gl_FrontFacing);

#ifdef RENDERER_HAS_TANGENT
mat3 tbn = mat3(surfaceData.tangent, surfaceData.bitangent, surfaceData.normal);
#else
mat3 tbn = getTBNByDerivatives(aoUV, normal, varyings.positionWS, gl_FrontFacing);
#endif

// Modify surfaceData by eye algorithm
surfaceData.albedoColor = calculateEyeColor(varyings.uv, tbn, surfaceData);
surfaceData.normal =calculateEyeNormal(varyings.uv, tbn, gl_FrontFacing);
surfaceData.f0 = 0.04;


// Can modify surfaceData here
initBRDFData(surfaceData, brdfData);

vec4 color = vec4(0, 0, 0, surfaceData.opacity);

// Get shadow attenuation
float shadowAttenuation = 1.0;
#if defined(SCENE_DIRECT_LIGHT_COUNT) && defined(NEED_CALCULATE_SHADOWS)
#if SCENE_SHADOW_CASCADED_COUNT == 1
vec3 shadowCoord = varyings.shadowCoord;
#else
vec3 shadowCoord = getShadowCoord(varyings.positionWS);
#endif
shadowAttenuation *= sampleShadowMap(varyings.positionWS, shadowCoord);
#endif

// Evaluate direct lighting
evaluateDirectRadiance(varyings, surfaceData, brdfData, shadowAttenuation, color.rgb);

// IBL
evaluateIBL(varyings, surfaceData, brdfData, color.rgb);

// Emissive
color.rgb += surfaceData.emissiveColor;

#if SCENE_FOG_MODE != 0
color = fog(color, varyings.positionVS);
#endif

#ifndef ENGINE_IS_COLORSPACE_GAMMA
color = linearToGamma(color);
#endif

gl_FragColor = color;
}

#endif
132 changes: 132 additions & 0 deletions packages/custom-material/src/advanced-shader/eye/EyeFunction.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
float material_ScleraSize;
float material_IrisSize;
vec2 material_PupilSize;
float material_Limbal;
float material_Parallax;
float material_ScleraNormalStrength;
float material_IrisNormalStrength;
vec4 material_ScleraColor;
vec4 material_IrisColor;

#ifdef MATERIAL_HAS_SCLERA_NORMAL
sampler2D material_ScleraNormal;
#endif

#ifdef MATERIAL_HAS_SCLERA_TEXTURE
sampler2D material_ScleraTexture;
#endif

#ifdef MATERIAL_HAS_SCLERA_MASK
sampler2D material_ScleraMask;
#endif

#ifdef MATERIAL_HAS_IRIS_TEXTURE
sampler2D material_IrisTexture;
#endif

#ifdef MATERIAL_HAS_IRIS_NORMAL
sampler2D material_IrisNormal;
#endif

vec2 parallaxOffset( float heighttex, float height, vec3 viewDir )
{
float heightTex = heighttex * height- height/2.0;
vec3 s = viewDir;
s.z += 0.42;
return heightTex * (s.xy / s.z);
}

vec3 calculateEyeColor(Varyings varyings, mat3 tbn, SurfaceData surfaceData)
{
// Sclera UV
vec2 scleraUV = (varyings.uv * material_ScleraSize)-((material_ScleraSize-1.0)/2.0);

// Sclera Texture
#ifdef MATERIAL_HAS_SCLERA_TEXTURE
vec4 scleraColor = texture2D(material_ScleraTexture, scleraUV);
scleraColor *= material_ScleraColor;
#ifndef ENGINE_IS_COLORSPACE_GAMMA
scleraColor = gammaToLinear(scleraColor);
#endif
#else
vec4 scleraColor = vec4(1.0);
#endif

// Iris Size For Mask
vec2 irisSizeUV = (varyings.uv * material_IrisSize) - ((material_IrisSize-1.0)/2.0);
float irisSize = material_IrisSize * 0.6;

// Pupil Size
vec2 pupilSize = mix(vec2(mix(0.5,0.2,irisSize/5.0)),vec2(mix(1.2,0.75,irisSize/5.0)),material_PupilSize.xy);

// Parallax UV
vec2 parallaxUV = mix((varyings.uv * 0.75)-((0.75-1.0)/2.0) ,(varyings.uv * pupilSize)-((pupilSize-1.0)/2.0),varyings.uv );

// Get Mask
float heighttexture = 0.0;
#ifdef MATERIAL_HAS_SCLERA_MASK
vec3 irisMaskTex = (texture2D(material_ScleraMask, irisSizeUV)).rgb;
float uvmask = 1.0 - (texture2D(material_ScleraMask, varyings.uv )).b;
heighttexture = (texture2D(material_ScleraMask, parallaxUV)).b;
#else
vec3 irisMaskTex = vec3(1.0);
float uvmask = 1.0;
heighttexture = 1.0;
#endif

// Transform ViewdirWS To ViewdirTS
vec3 vDir = surfaceData.viewDir;
vec3 viewDirInTBN = tbn * vDir;

vec2 offset = parallaxOffset(heighttexture, material_Parallax, viewDirInTBN);

// Iris UV And Pupil UV
vec2 irisUV = (varyings.uv * irisSize) - ((irisSize-1.0)/2.0);
vec2 pupilUV = irisUV * ((-1.0 + (uvmask * pupilSize)))-( 0.5 *(uvmask * pupilSize));

// Parallax Color
vec4 parallax = vec4(0.0);
#ifdef MATERIAL_HAS_IRIS_TEXTURE
parallax = texture2D(material_IrisTexture, pupilUV - offset);
#ifndef ENGINE_IS_COLORSPACE_GAMMA
parallax = gammaToLinear(parallax);
#endif
parallax.rgb *= material_IrisColor.rgb;
#endif

vec4 baseColor = mix(scleraColor,parallax,irisMaskTex.r);

// Limbus
vec4 limbalstrength = (0.0 - (material_Limbal * 10.0 )) * baseColor;
float limbalRadius = saturate(irisMaskTex.g * (1.0 - irisMaskTex.r));
baseColor = mix(baseColor,limbalstrength,limbalRadius);
return baseColor.rgb;
}

vec3 calculateEyeNormal(Varyings varyings, mat3 tbn, bool isFrontFacing)
{
// Sclera UV
vec2 scleraUV = (varyings.uv * material_ScleraSize)-((material_ScleraSize-1.0)/2.0);
// Iris UV
vec2 irisSizeUV = (varyings.uv * material_IrisSize) - ((material_IrisSize-1.0)/2.0);

#ifdef MATERIAL_HAS_SCLERA_MASK
vec3 irisMaskTex = (texture2D(material_ScleraMask, irisSizeUV)).rgb;
#else
vec3 irisMaskTex = vec3(1.0);
#endif

// Normal
#ifdef MATERIAL_HAS_SCLERA_NORMAL
vec3 scleraNormal = getNormalByNormalTexture(tbn, material_ScleraNormal, material_ScleraNormalStrength, scleraUV, isFrontFacing);
#else
vec3 scleraNormal = tbn[2];
#endif

#ifdef MATERIAL_HAS_IRIS_NORMAL
vec3 irisNormal = getNormalByNormalTexture(tbn, material_IrisNormal, material_IrisNormalStrength, irisSizeUV, isFrontFacing);
#else
vec3 irisNormal = tbn[2];
#endif
return mix(scleraNormal,irisNormal,irisMaskTex.r);
}
Loading

0 comments on commit 2ca0822

Please sign in to comment.