-
-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support clearcoat * feat: support Specular AA
- Loading branch information
Showing
20 changed files
with
394 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
#ifndef OMIT_NORMAL | ||
#ifdef O3_HAS_NORMAL | ||
vec3 normal = vec3( NORMAL ); | ||
#endif | ||
|
||
vec3 normal = vec3( NORMAL ); | ||
|
||
#if defined( O3_HAS_TANGENT ) && defined( O3_NORMAL_TEXTURE ) | ||
|
||
#ifdef O3_HAS_TANGENT | ||
vec4 tangent = vec4( TANGENT ); | ||
|
||
#endif | ||
|
||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,55 @@ | ||
vec3 getNormal() | ||
{ | ||
#ifdef O3_NORMAL_TEXTURE | ||
#ifndef O3_HAS_TANGENT | ||
#ifdef HAS_DERIVATIVES | ||
vec3 pos_dx = dFdx(v_pos); | ||
vec3 pos_dy = dFdy(v_pos); | ||
vec3 tex_dx = dFdx(vec3(v_uv, 0.0)); | ||
vec3 tex_dy = dFdy(vec3(v_uv, 0.0)); | ||
vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t); | ||
#ifdef O3_HAS_NORMAL | ||
vec3 ng = normalize(v_normal); | ||
#else | ||
vec3 ng = normalize( cross(pos_dx, pos_dy) ); | ||
#endif | ||
t = normalize(t - ng * dot(ng, t)); | ||
vec3 b = normalize(cross(ng, t)); | ||
mat3 tbn = mat3(t, b, ng); | ||
#else | ||
#ifdef O3_HAS_NORMAL | ||
vec3 ng = normalize(v_normal); | ||
#else | ||
vec3 ng = vec3(0.0, 0.0, 1.0); | ||
#endif | ||
mat3 tbn = mat3(vec3(0.0), vec3(0.0), ng); | ||
#endif | ||
#else | ||
mat3 tbn = v_TBN; | ||
#endif | ||
vec3 n = texture2D(u_normalTexture, v_uv ).rgb; | ||
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_normalIntensity, u_normalIntensity, 1.0))); | ||
#else | ||
vec3 getNormal(){ | ||
#ifdef O3_HAS_NORMAL | ||
vec3 n = normalize(v_normal); | ||
vec3 normal = v_normal; | ||
#elif defined(HAS_DERIVATIVES) | ||
vec3 pos_dx = dFdx(v_pos); | ||
vec3 pos_dy = dFdy(v_pos); | ||
vec3 n = normalize( cross(pos_dx, pos_dy) ); | ||
vec3 normal = normalize( cross(pos_dx, pos_dy) ); | ||
#else | ||
vec3 n= vec3(0.0,0.0,1.0); | ||
vec3 normal = vec3(0, 0, 1); | ||
#endif | ||
#endif | ||
|
||
n *= float( gl_FrontFacing ) * 2.0 - 1.0; | ||
normal *= float( gl_FrontFacing ) * 2.0 - 1.0; | ||
return normal; | ||
} | ||
|
||
vec3 getNormalByNormalTexture(mat3 tbn, sampler2D normalTexture, float normalIntensity, vec2 uv){ | ||
vec3 normal = texture2D(normalTexture, uv).rgb; | ||
normal = normalize(tbn * ((2.0 * normal - 1.0) * vec3(normalIntensity, normalIntensity, 1.0))); | ||
normal *= float( gl_FrontFacing ) * 2.0 - 1.0; | ||
|
||
return n; | ||
return normal; | ||
} | ||
|
||
mat3 getTBN(){ | ||
#if defined(O3_HAS_NORMAL) && defined(O3_HAS_TANGENT) && ( defined(O3_NORMAL_TEXTURE) || defined(HAS_CLEARCOATNORMALTEXTURE) ) | ||
mat3 tbn = v_TBN; | ||
#else | ||
vec3 normal = getNormal(); | ||
vec3 position = v_pos; | ||
vec2 uv = gl_FrontFacing? v_uv: -v_uv; | ||
|
||
#ifdef HAS_DERIVATIVES | ||
// ref: http://www.thetenthplanet.de/archives/1180 | ||
// get edge vectors of the pixel triangle | ||
vec3 dp1 = dFdx(position); | ||
vec3 dp2 = dFdy(position); | ||
vec2 duv1 = dFdx(uv); | ||
vec2 duv2 = dFdy(uv); | ||
|
||
// solve the linear system | ||
vec3 dp2perp = cross(dp2, normal); | ||
vec3 dp1perp = cross(normal, dp1); | ||
vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x; | ||
vec3 binormal = dp2perp * duv1.y + dp1perp * duv2.y; | ||
|
||
// construct a scale-invariant frame | ||
float invmax = inversesqrt(max(dot(tangent, tangent), dot(binormal, binormal))); | ||
mat3 tbn = mat3(tangent * invmax, binormal * invmax, normal); | ||
#else | ||
mat3 tbn = mat3(vec3(0.0), vec3(0.0), normal); | ||
#endif | ||
#endif | ||
|
||
return tbn; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
#ifdef O3_HAS_NORMAL | ||
|
||
#if defined( O3_HAS_TANGENT ) && defined( O3_NORMAL_TEXTURE ) | ||
|
||
varying mat3 v_TBN; | ||
|
||
#else | ||
|
||
varying vec3 v_normal; | ||
|
||
#ifndef OMIT_NORMAL | ||
#ifdef O3_HAS_NORMAL | ||
varying vec3 v_normal; | ||
#if defined(O3_HAS_TANGENT) && ( defined(O3_NORMAL_TEXTURE) || defined(HAS_CLEARCOATNORMALTEXTURE) ) | ||
varying mat3 v_TBN; | ||
#endif | ||
#endif | ||
|
||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
#ifndef OMIT_NORMAL | ||
#ifdef O3_HAS_NORMAL | ||
|
||
#if defined( O3_HAS_TANGENT ) && defined( O3_NORMAL_TEXTURE ) | ||
|
||
vec3 normalW = normalize( mat3(u_normalMat) * normal.xyz ); | ||
vec3 tangentW = normalize( mat3(u_normalMat) * tangent.xyz ); | ||
vec3 bitangentW = cross( normalW, tangentW ) * tangent.w; | ||
v_TBN = mat3( tangentW, bitangentW, normalW ); | ||
|
||
#else | ||
|
||
v_normal = normalize( mat3(u_normalMat) * normal ); | ||
|
||
#endif | ||
#if defined(O3_HAS_TANGENT) && ( defined(O3_NORMAL_TEXTURE) || defined(HAS_CLEARCOATNORMALTEXTURE) ) | ||
vec3 normalW = normalize( mat3(u_normalMat) * normal.xyz ); | ||
vec3 tangentW = normalize( mat3(u_normalMat) * tangent.xyz ); | ||
vec3 bitangentW = cross( normalW, tangentW ) * tangent.w; | ||
|
||
v_TBN = mat3( tangentW, bitangentW, normalW ); | ||
#endif | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.