Skip to content

Commit aa43bc9

Browse files
committed
add webgl techniques
1 parent 5a82f55 commit aa43bc9

13 files changed

+4866
-121
lines changed

demo/js/index.js

+14-115
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ function initList(){
3636
}
3737

3838
function initStage(){
39+
Hilo3d.semantic.TIME = {
40+
get:function(){
41+
return new Date().getTime() - 1577099833000;
42+
}
43+
}
44+
3945
camera = new Hilo3d.PerspectiveCamera({
4046
aspect: innerWidth / innerHeight,
4147
far: 100,
@@ -105,7 +111,8 @@ function showModel(id){
105111
var glTFUrl = `../models/${id}/glTF/model.gltf`;
106112
glTFLoader.load({
107113
src: glTFUrl,
108-
isUnQuantizeInShader:false
114+
isUnQuantizeInShader:false,
115+
isLoadAllTextures: true
109116
}).then(function(model) {
110117
loadingElem.style.display = 'none';
111118
try{
@@ -160,120 +167,12 @@ function initModel(model, modelInfo){
160167

161168
if (modelInfo.fire) {
162169
model.meshes.forEach(function(mesh){
163-
var src;
164-
if(mesh.material.baseColorMap) {
165-
var baseColorMap = mesh.material.baseColorMap;
166-
src = baseColorMap.src || '';
167-
if (src.indexOf('FireCore') > -1) {
168-
mesh.material = new Hilo3d.ShaderMaterial({
169-
renderOrder:-2,
170-
shaderCacheId: "FireCore",
171-
needBasicUnifroms: false,
172-
needBasicAttributes: false,
173-
fireCoreTexture: baseColorMap,
174-
side:Hilo3d.constants.FRONT_AND_BACK,
175-
uniforms:{
176-
u_modelViewProjectionMatrix:'MODELVIEWPROJECTION',
177-
u_fireCoreTexture:{
178-
get(mesh, material, programInfo) {
179-
return Hilo3d.semantic.handlerTexture(material.fireCoreTexture, programInfo.textureIndex);
180-
}
181-
},
182-
u_time:{
183-
get:function(mesh, material, programInfo){
184-
return new Date().getTime() - 1577099833000;
185-
}
186-
}
187-
},
188-
attributes:{
189-
a_position: 'POSITION',
190-
a_texcoord0:'TEXCOORD_0'
191-
},
192-
fs:`
193-
precision HILO_MAX_FRAGMENT_PRECISION float;
194-
varying vec2 v_texcoord0;
195-
uniform sampler2D u_fireCoreTexture;
196-
uniform float u_time;
197-
198-
void main(void) {
199-
float uOffset = u_time * 0.00;
200-
float vOffset = u_time * 0.001;
201-
vec4 fireCore = texture2D(u_fireCoreTexture, vec2(v_texcoord0.x + uOffset, v_texcoord0.y + vOffset));
202-
if (fireCore.r < 0.5) {
203-
discard;
204-
}
205-
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
206-
}
207-
`,
208-
vs:`
209-
precision HILO_MAX_VERTEX_PRECISION float;
210-
attribute vec3 a_position;
211-
attribute vec2 a_texcoord0;
212-
uniform mat4 u_modelViewProjectionMatrix;
213-
varying vec2 v_texcoord0;
214-
215-
void main(void) {
216-
vec4 pos = vec4(a_position, 1.0);
217-
gl_Position = u_modelViewProjectionMatrix * pos;
218-
v_texcoord0 = a_texcoord0;
219-
}
220-
`
221-
});
222-
} else if (src.indexOf('FireSten') > -1) {
223-
mesh.material = mesh.material = new Hilo3d.ShaderMaterial({
224-
shaderCacheId: "FireSten",
225-
needBasicUnifroms: false,
226-
needBasicAttributes: false,
227-
fireCoreTexture: baseColorMap,
228-
renderOrder:-1,
229-
depthMask:false,
230-
uniforms:{
231-
u_modelViewProjectionMatrix:'MODELVIEWPROJECTION',
232-
u_fireSten:{
233-
get(mesh, material, programInfo) {
234-
return Hilo3d.semantic.handlerTexture(material.fireCoreTexture, programInfo.textureIndex);
235-
}
236-
},
237-
u_time:{
238-
get:function(mesh, material, programInfo){
239-
return new Date().getTime() - 1577099833000;
240-
}
241-
}
242-
},
243-
attributes:{
244-
a_position: 'POSITION',
245-
a_texcoord0:'TEXCOORD_0'
246-
},
247-
fs:`
248-
precision HILO_MAX_FRAGMENT_PRECISION float;
249-
varying vec2 v_texcoord0;
250-
uniform sampler2D u_fireSten;
251-
uniform float u_time;
252-
void main(void) {
253-
float gradient_start = 1.0;
254-
vec2 gradient = vec2(0, -1.0);
255-
vec4 fireSten = texture2D(u_fireSten, v_texcoord0);
256-
vec3 col1 = vec3(1.0, 0.0, 0.0);
257-
vec3 col2 = vec3(1.0, 1.0, 0.0);
258-
vec3 col = col1 + (col2 - col1) * max(0.0, min(gradient_start+dot(v_texcoord0, gradient)+(fireSten.x-0.5)*0.1, 1.0));
259-
gl_FragColor = vec4(col, 1);
260-
}
261-
`,
262-
vs:`
263-
precision HILO_MAX_VERTEX_PRECISION float;
264-
attribute vec3 a_position;
265-
attribute vec2 a_texcoord0;
266-
uniform mat4 u_modelViewProjectionMatrix;
267-
varying vec2 v_texcoord0;
268-
269-
void main(void) {
270-
vec4 pos = vec4(a_position, 1.0);
271-
gl_Position = u_modelViewProjectionMatrix * pos;
272-
v_texcoord0 = a_texcoord0;
273-
}
274-
`
275-
});
276-
}
170+
var material = mesh.material;
171+
if (material.name.indexOf('fireCore') > -1){
172+
material.renderOrder = -2;
173+
} else if(material.name.indexOf('fireSten') > -1){
174+
material.depthMask = false;
175+
material.renderOrder = -1;
277176
}
278177
});
279178
}

0 commit comments

Comments
 (0)