WebGL

How to create latitudinal (horizontal) contour lines in GLSL?

心已入冬 提交于 2019-12-04 12:04:20
I'm aiming for this effect: (horizontal-only contour lines): I did find this example , however it creates horizontal and vertical contour lines. I can't quite wrap my head around how the call to fwidth() is generating the lines. uniform float gsize;//size of the grid uniform float gwidth;//grid lines'width in pixels varying vec3 P; void main() { vec3 f = abs(fract (P * gsize)-0.5); vec3 df = fwidth(P * gsize); float mi=max(0.0,gwidth-1.0), ma=max(1.0,gwidth);//should be uniforms vec3 g=clamp((f-df*mi)/(df*(ma-mi)),max(0.0,1.0-gwidth),1.0);//max(0.0,1.0-gwidth) should also be sent as uniform

WebGL iOS render to floating point texture

冷暖自知 提交于 2019-12-04 11:41:22
问题 I'm trying to get rendering to a floating point texture working in WebGL on iOS Safari (not in a native app). I have managed to get iOS to read a manually (e.g. from JavaScript) created floating point texture, however when I create a framebuffer of floating point type and use the GPU to render into it, it does not work. I've isolated the issue to code that renders to a floating point texture, which is then passed to another shader to be displayed. Here is what the result looks like applied to

Multitexture GL_TEXTURE1 issue on WebGL

烈酒焚心 提交于 2019-12-04 11:37:45
I am learning to use multitexture on WebGL. I have the following shader code snippets: uniform int flag; uniform sampler2D texture0; uniform sampler2D texture1; varying vec2 v_texCoord; void main() { vec2 texCoord = vec2(v_texCoord.s, 1.0 - v_texCoord.t); vec4 texel0 = texture2D(texture0, texCoord); vec4 texel1 = texture2D(texture1, texCoord); if (1 == flag) { gl_FragColor = texel1; } else { gl_FragColor = texel0; } } Also, my JavaScript code snippets: gl.uniform1i(gl.getUniformLocation(gl.program, "flag"), 1); gl.uniform1i(gl.getUniformLocation(gl.program, "texture0"), 0); // Texture Unit 0

How does ShaderToy load sounds into a texture

折月煮酒 提交于 2019-12-04 11:32:50
I've been trying to do the same things shadertoy does for passing audio frequency/waveform into the shader with three.js. https://www.shadertoy.com/view/Xds3Rr In this example it seems that IQ is putting frequency/waveform audio data into an image and then sampling that as a texture in the shader. How would I create that audio texture in Javascript? To be clear I don't need help loading the texture uniform into the shader. I just don't know how to create the audio texture from an audio file. var texture = new THREE.Texture(); shader.uniforms = { iChannel0: { type: 't', value: texture } }; I'm

Three.js attaching object to bone

风格不统一 提交于 2019-12-04 10:35:56
问题 Is there any way to attach mesh to bone? For example I load animated .js character and i want to attach weapon to it's hand. 回答1: It is possible using a few simple hacks on the Bone and Object3D prototype. Since bones inherit from Object3D, they may have children, so we can easily .add() a mesh to any bone. However, the SkinnedMesh will only call updateMatrixWorld() on non-Bone children, and update() for Bone children. Additionally, bones call update() for each of its children (regardless of

How to make WebGL canvas transparent

a 夏天 提交于 2019-12-04 10:08:02
问题 Is it possible to have WebGL canvas with transparent background? I want to have contents of web page visible through the canvas. This is what I have now: http://i50.tinypic.com/2vvq7h2.png As you can see, the text behind the WebGL canvas is not visible. When I change style of Canvas element in CSS and add opacity: 0.5; The page will look like this: http://i47.tinypic.com/302ys9c.png Which is almost what I want, but not entirely - the color of text due to the CSS alpha setting is of course not

using WebGL index buffers for drawing meshes

无人久伴 提交于 2019-12-04 09:52:44
3 index buffers asks a more difficult question, but I feel like their main problem boils down to mine: is there a way to use index buffers to visit the same vertex multiple times in WebGL rather than duplicating the vertices? All I was able to find is using index buffers to associate textures, normals, etc. to vertices in a model. I wasn't able to find a way to use an index buffer to tell drawArrays the order in which to visit the vertices in a position array. Yes, use gl.drawElements and upload the buffer with your vertex indices to gl.ELEMENT_ARRAY_BUFFER. ... upload vertex data to buffers,

Passing an array of vectors to a uniform

我怕爱的太早我们不能终老 提交于 2019-12-04 09:36:14
问题 I am trying to implement multiple lights in my shader but I have trouble to fill the uniform with my light data. My vertex shader: attribute vec3 aVertex; attribute vec3 aNormal; attribute vec2 aTexture; uniform mat4 uMVMatrix; uniform mat4 uPMatrix; uniform mat4 uNMatrix; uniform vec3 uAmbientColor; uniform vec3 uPointLightingLocation[16]; uniform vec3 uPointLightingColor[16]; varying vec2 vTexture; varying vec3 vLightWeighting; void main(void) { vec4 mvPosition = uMVMatrix * vec4(aVertex, 1

Three.js - Change Material on Runtime

可紊 提交于 2019-12-04 08:53:34
问题 I have some .js files exported from Blender and load them with THREE.JSONLoader(); my callback: var callback = function( geometry ) { createMesh(geometry); my loading: loader.load( "Models/sculp.js", callback ); my create method: function createMesh(geometry){ inArr[id] = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: 0xbbbbbb} ) ); inArr[id].scale.set( 100, 100, 100 ); scene.add( inArr[id] ); id++; } Now I want to change my material on runtime by using my keyboard (changes

Inline webgl shader code in javascript

故事扮演 提交于 2019-12-04 08:47:44
I'm writing a simple Javascript library that makes use of some WebGL code. I'd like to include the shader sources inline in the .js file, because my alternatives are to include them as script tags in each page, or to have them as separate files which are loaded as AJAX. Neither of these options are particularly modular. However, due to the lack of multi-line strings in javascript, I don't have any good ideas for how to inline the WebGL code. Is there an approach I'm not thinking of? Stefan Haustein Use a single string per line and then join them together, e.g. var shader = [ "// line1 ", "//