Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
510705cd
T
three.js
项目概览
车家大少爷
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
510705cd
编写于
8月 09, 2021
作者:
W
WestLangley
提交者:
GitHub
8月 09, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up formatting (#22296)
上级
49dd5f11
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
63 addition
and
66 deletion
+63
-66
src/renderers/shaders/ShaderChunk/bsdfs.glsl.js
src/renderers/shaders/ShaderChunk/bsdfs.glsl.js
+11
-14
src/renderers/shaders/ShaderChunk/common.glsl.js
src/renderers/shaders/ShaderChunk/common.glsl.js
+8
-24
src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js
...enderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js
+2
-2
src/renderers/shaders/ShaderChunk/packing.glsl.js
src/renderers/shaders/ShaderChunk/packing.glsl.js
+4
-3
src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js
...ers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js
+1
-1
src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js
...rs/shaders/ShaderChunk/transmission_pars_fragment.glsl.js
+37
-22
未找到文件。
src/renderers/shaders/ShaderChunk/bsdfs.glsl.js
浏览文件 @
510705cd
...
...
@@ -73,6 +73,7 @@ vec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const
// See F_Schlick
float fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );
vec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;
return Fr * fresnel + F0;
...
...
@@ -326,30 +327,26 @@ vec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in Ge
} // validated
// source: http://simonstechblog.blogspot.ca/2011/12/microfacet-brdf.html
float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {
return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );
}
float BlinnExponentToGGXRoughness( const in float blinnExponent ) {
return sqrt( 2.0 / ( blinnExponent + 2.0 ) );
}
#if defined( USE_SHEEN )
// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L94
float D_Charlie(float roughness, float NoH) {
float D_Charlie( float roughness, float NoH ) {
// Estevez and Kulla 2017, "Production Friendly Microfacet Sheen BRDF"
float invAlpha = 1.0 / roughness;
float cos2h = NoH * NoH;
float sin2h = max(1.0 - cos2h, 0.0078125); // 2^(-14/2), so sin2h^2 > 0 in fp16
return (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);
float sin2h = max( 1.0 - cos2h, 0.0078125 ); // 2^(-14/2), so sin2h^2 > 0 in fp16
return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
}
// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L136
float V_Neubelt(float NoV, float NoL) {
float V_Neubelt( float NoV, float NoL ) {
// Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886"
return saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));
return saturate( 1.0 / ( 4.0 * ( NoL + NoV - NoL * NoV ) ) );
}
vec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {
...
...
src/renderers/shaders/ShaderChunk/common.glsl.js
浏览文件 @
510705cd
...
...
@@ -8,26 +8,30 @@ export default /* glsl */`
#ifndef saturate
// <tonemapping_pars_fragment> may have defined saturate() already
#define saturate(
a
) clamp( a, 0.0, 1.0 )
#define saturate(
a
) clamp( a, 0.0, 1.0 )
#endif
#define whiteComplement(
a
) ( 1.0 - saturate( a ) )
#define whiteComplement(
a
) ( 1.0 - saturate( a ) )
float pow2( const in float x ) { return x*x; }
float pow3( const in float x ) { return x*x*x; }
float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }
// expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.
// do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
highp float rand( const in vec2 uv ) {
const highp float a = 12.9898, b = 78.233, c = 43758.5453;
highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
return fract(sin(sn) * c);
return fract( sin( sn ) * c );
}
#ifdef HIGH_PRECISION
float precisionSafeLength( vec3 v ) { return length( v ); }
#else
float max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }
float precisionSafeLength( vec3 v ) {
float maxComponent = max3( abs( v ) );
return length( v / maxComponent ) * maxComponent;
...
...
@@ -71,26 +75,6 @@ vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
}
vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
float distance = dot( planeNormal, point - pointOnPlane );
return - distance * planeNormal + point;
}
float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
return sign( dot( point - pointOnPlane, planeNormal ) );
}
vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {
return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;
}
mat3 transposeMat3( const in mat3 m ) {
mat3 tmp;
...
...
src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js
浏览文件 @
510705cd
...
...
@@ -29,13 +29,13 @@ export default /* glsl */`
#else
normal = perturbNormal2Arb( -vViewPosition, normal, mapN, faceDirection );
normal = perturbNormal2Arb( -
vViewPosition, normal, mapN, faceDirection );
#endif
#elif defined( USE_BUMPMAP )
normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd(), faceDirection );
normal = perturbNormalArb( -
vViewPosition, normal, dHdxy_fwd(), faceDirection );
#endif
`
;
src/renderers/shaders/ShaderChunk/packing.glsl.js
浏览文件 @
510705cd
...
...
@@ -26,9 +26,10 @@ float unpackRGBAToDepth( const in vec4 v ) {
}
vec4 pack2HalfToRGBA( vec2 v ) {
vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ));
return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w);
vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 )
);
return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w
);
}
vec2 unpackRGBATo2Half( vec4 v ) {
return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
}
...
...
@@ -45,7 +46,7 @@ float orthographicDepthToViewZ( const in float linearClipZ, const in float near,
// NOTE: https://twitter.com/gonnavis/status/1377183786949959682
float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
return (
( near + viewZ ) * far ) / (
( far - near ) * viewZ );
return (
( near + viewZ ) * far ) / (
( far - near ) * viewZ );
}
float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {
return ( near * far ) / ( ( far - near ) * invClipZ - far );
...
...
src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js
浏览文件 @
510705cd
export
default
/* glsl */
`
#ifndef saturate
// <common> may have defined saturate() already
#define saturate(
a
) clamp( a, 0.0, 1.0 )
#define saturate(
a
) clamp( a, 0.0, 1.0 )
#endif
uniform float toneMappingExposure;
...
...
src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js
浏览文件 @
510705cd
...
...
@@ -29,61 +29,76 @@ export default /* glsl */`
varying vec3 vWorldPosition;
vec3 getVolumeTransmissionRay(vec3 n, vec3 v, float thickness, float ior, mat4 modelMatrix) {
vec3 getVolumeTransmissionRay( vec3 n, vec3 v, float thickness, float ior, mat4 modelMatrix ) {
// Direction of refracted light.
vec3 refractionVector = refract(
-v, normalize(n), 1.0 / ior
);
vec3 refractionVector = refract(
- v, normalize( n ), 1.0 / ior
);
// Compute rotation-independant scaling of the model matrix.
vec3 modelScale;
modelScale.x = length(
vec3(modelMatrix[0].xyz)
);
modelScale.y = length(
vec3(modelMatrix[1].xyz)
);
modelScale.z = length(
vec3(modelMatrix[2].xyz)
);
modelScale.x = length(
vec3( modelMatrix[ 0 ].xyz )
);
modelScale.y = length(
vec3( modelMatrix[ 1 ].xyz )
);
modelScale.z = length(
vec3( modelMatrix[ 2 ].xyz )
);
// The thickness is specified in local space.
return normalize(refractionVector) * thickness * modelScale;
return normalize( refractionVector ) * thickness * modelScale;
}
float applyIorToRoughness(float roughness, float ior) {
float applyIorToRoughness( float roughness, float ior ) {
// Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and
// an IOR of 1.5 results in the default amount of microfacet refraction.
return roughness * clamp(ior * 2.0 - 2.0, 0.0, 1.0);
return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
}
vec3 getTransmissionSample(vec2 fragCoord, float roughness, float ior) {
float framebufferLod = log2(transmissionSamplerSize.x) * applyIorToRoughness(roughness, ior);
return texture2DLodEXT(transmissionSamplerMap, fragCoord.xy, framebufferLod).rgb;
vec3 getTransmissionSample( vec2 fragCoord, float roughness, float ior ) {
float framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
return texture2DLodEXT( transmissionSamplerMap, fragCoord.xy, framebufferLod ).rgb;
}
vec3 applyVolumeAttenuation(vec3 radiance, float transmissionDistance, vec3 attenuationColor, float attenuationDistance) {
if (attenuationDistance == 0.0) {
vec3 applyVolumeAttenuation( vec3 radiance, float transmissionDistance, vec3 attenuationColor, float attenuationDistance ) {
if ( attenuationDistance == 0.0 ) {
// Attenuation distance is +∞ (which we indicate by zero), i.e. the transmitted color is not attenuated at all.
return radiance;
} else {
// Compute light attenuation using Beer's law.
vec3 attenuationCoefficient = -log(
attenuationColor
) / attenuationDistance;
vec3 transmittance = exp(
-attenuationCoefficient * transmissionDistance
); // Beer's law
vec3 attenuationCoefficient = -log(
attenuationColor
) / attenuationDistance;
vec3 transmittance = exp(
- attenuationCoefficient * transmissionDistance
); // Beer's law
return transmittance * radiance;
}
}
vec3 getIBLVolumeRefraction(vec3 n, vec3 v, float perceptualRoughness, vec3 baseColor, vec3 specularColor,
vec3 getIBLVolumeRefraction(
vec3 n, vec3 v, float perceptualRoughness, vec3 baseColor, vec3 specularColor,
vec3 position, mat4 modelMatrix, mat4 viewMatrix, mat4 projMatrix, float ior, float thickness,
vec3 attenuationColor, float attenuationDistance) {
vec3 transmissionRay = getVolumeTransmissionRay(n, v, thickness, ior, modelMatrix);
vec3 attenuationColor, float attenuationDistance ) {
vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
vec3 refractedRayExit = position + transmissionRay;
// Project refracted vector on the framebuffer, while mapping to normalized device coordinates.
vec4 ndcPos = projMatrix * viewMatrix * vec4(
refractedRayExit, 1.0
);
vec4 ndcPos = projMatrix * viewMatrix * vec4(
refractedRayExit, 1.0
);
vec2 refractionCoords = ndcPos.xy / ndcPos.w;
refractionCoords += 1.0;
refractionCoords /= 2.0;
// Sample framebuffer to get pixel the refracted ray hits.
vec3 transmittedLight = getTransmissionSample(refractionCoords, perceptualRoughness, ior);
vec3 transmittedLight = getTransmissionSample( refractionCoords, perceptualRoughness, ior );
vec3 attenuatedColor = applyVolumeAttenuation( transmittedLight, length( transmissionRay ), attenuationColor, attenuationDistance );
vec3 attenuatedColor = applyVolumeAttenuation(transmittedLight, length(transmissionRay), attenuationColor, attenuationDistance)
;
return ( 1.0 - specularColor ) * attenuatedColor * baseColor
;
return (1.0 - specularColor) * attenuatedColor * baseColor;
}
#endif
`
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录