Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
23b9a851
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,发现更多精彩内容 >>
未验证
提交
23b9a851
编写于
7月 25, 2019
作者:
W
WestLangley
提交者:
GitHub
7月 25, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17073 from higharc/use-onbeforecompile
Use onBeforeCompile to customize shader for instancing
上级
ebb01773
7b23555d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
106 addition
and
136 deletion
+106
-136
examples/webgl_buffergeometry_instancing_lambert.html
examples/webgl_buffergeometry_instancing_lambert.html
+106
-136
未找到文件。
examples/webgl_buffergeometry_instancing_lambert.html
浏览文件 @
23b9a851
...
...
@@ -34,147 +34,120 @@
import
{
OrbitControls
}
from
'
./jsm/controls/OrbitControls.js
'
;
import
{
Curves
}
from
'
./jsm/curves/CurveExtras.js
'
;
THREE
.
ShaderLib
.
customDepthRGBA
=
{
// this is a cut-and-paste of the depth shader -- modified to accommodate instancing for this app
// this is a cut-and-paste of the depth shader -- modified to accommodate instancing for this app
var
customDepthVertexShader
=
`
// instanced
attribute vec3 instanceOffset;
attribute float instanceScale;
uniforms
:
THREE
.
ShaderLib
.
depth
.
uniforms
,
#include <common>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
vertexShader
:
`
// instanced
#ifdef INSTANCED
attribute vec3 instanceOffset;
attribute float instanceScale;
#endif
#include <common>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
#include <skinbase_vertex>
#ifdef USE_DISPLACEMENTMAP
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinnormal_vertex>
#endif
#include <begin_vertex>
// instanced
#ifdef INSTANCED
transformed *= instanceScale;
transformed = transformed + instanceOffset;
#endif
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <displacementmap_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
}
`
,
void main() {
fragmentShader
:
THREE
.
ShaderChunk
.
depth_frag
#include <uv_vertex>
};
#include <skinbase_vertex>
THREE
.
ShaderLib
.
lambert
=
{
// this is a cut-and-paste of the lambert shader -- modified to accommodate instancing for this app
#ifdef USE_DISPLACEMENTMAP
uniforms
:
THREE
.
ShaderLib
.
lambert
.
uniforms
,
vertexShader
:
`
#define LAMBERT
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinnormal_vertex>
#ifdef INSTANCED
attribute vec3 instanceOffset;
attribute vec3 instanceColor;
attribute float instanceScale;
#endif
varying vec3 vLightFront;
varying vec3 vIndirectFront;
#include <begin_vertex>
#ifdef DOUBLE_SIDED
varying vec3 vLightBack;
varying vec3 vIndirectBack;
#endif
#include <common>
#include <uv_pars_vertex>
#include <uv2_pars_vertex>
#include <envmap_pars_vertex>
#include <bsdfs>
#include <lights_pars_begin>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
#include <uv2_vertex>
#include <color_vertex>
// vertex colors instanced
#ifdef INSTANCED
#ifdef USE_COLOR
vColor.xyz = instanceColor.xyz;
#endif
#endif
// instanced
transformed *= instanceScale;
transformed = transformed + instanceOffset;
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinbase_vertex>
#include <skinnormal_vertex>
#include <defaultnormal_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <displacementmap_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
#include <begin_vertex>
}
`
;
// this is a cut-and-paste of the lambert shader -- modified to accommodate instancing for this app
var
customLambertVertexShader
=
`
#define LAMBERT
// instanced
attribute vec3 instanceOffset;
attribute vec3 instanceColor;
attribute float instanceScale;
varying vec3 vLightFront;
varying vec3 vIndirectFront;
#ifdef DOUBLE_SIDED
varying vec3 vLightBack;
varying vec3 vIndirectBack;
#endif
#include <common>
#include <uv_pars_vertex>
#include <uv2_pars_vertex>
#include <envmap_pars_vertex>
#include <bsdfs>
#include <lights_pars_begin>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
#include <uv2_vertex>
#include <color_vertex>
// vertex colors instanced
#ifdef USE_COLOR
vColor.xyz = instanceColor.xyz;
#endif
// position instanced
#ifdef INSTANCED
transformed *= instanceScale;
transformed = transformed + instanceOffset;
#endif
#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinbase_vertex>
#include <skinnormal_vertex>
#include <defaultnormal_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
#include <begin_vertex>
#include <worldpos_vertex>
#include <envmap_vertex>
#include <lights_lambert_vertex>
#include <shadowmap_vertex>
#include <fog_vertex>
// position instanced
transformed *= instanceScale;
transformed = transformed + instanceOffset;
}
`
,
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>
#include <clipping_planes_vertex>
fragmentShader
:
THREE
.
ShaderLib
.
lambert
.
fragmentShader
#include <worldpos_vertex>
#include <envmap_vertex>
#include <lights_lambert_vertex>
#include <shadowmap_vertex>
#include <fog_vertex>
};
}
`
;
//
...
...
@@ -292,27 +265,24 @@
}
);
material
.
defines
=
material
.
defines
||
{};
material
.
defines
[
'
INSTANCED
'
]
=
""
;
material
.
onBeforeCompile
=
function
(
shader
)
{
shader
.
vertexShader
=
customLambertVertexShader
;
};
// custom depth material - required for instanced shadows
var
shader
=
THREE
.
ShaderLib
[
'
customDepthRGBA
'
]
;
var
customDepthMaterial
=
new
THREE
.
MeshDepthMaterial
()
;
var
uniforms
=
THREE
.
UniformsUtils
.
clone
(
shader
.
uniforms
);
customDepthMaterial
.
onBeforeCompile
=
function
(
shader
)
{
var
customDepthMaterial
=
new
THREE
.
ShaderMaterial
(
{
shader
.
vertexShader
=
customDepthVertexShader
;
defines
:
{
'
INSTANCED
'
:
""
,
'
DEPTH_PACKING
'
:
THREE
.
RGBADepthPacking
},
uniforms
:
uniforms
,
vertexShader
:
shader
.
vertexShader
,
fragmentShader
:
shader
.
fragmentShader
};
}
)
;
customDepthMaterial
.
depthPacking
=
THREE
.
RGBADepthPacking
;
//
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录