WebGL

WebGL gl_FragColor alpha behave differently in Chrome with Firefox

杀马特。学长 韩版系。学妹 提交于 2019-12-12 13:12:05
问题 Code below draws three triangles alpha value 0.5 with {premultipliedAlpha: false} . const gl = document.querySelector('canvas').getContext('webgl', {premultipliedAlpha: false}); const canvasWidthHeight = 300; gl.clearColor(1, 0, 0, 0.4); // gl.clear(gl.COLOR_BUFFER_BIT); const vertexShaderSource = ` attribute vec2 position; uniform vec2 resolution; // All shaders have a main function void main() { vec2 glSpacePosition = (position / resolution) * 2.0 - 1.0; gl_Position = vec4(glSpacePosition *

Is updating the entire VBO on each frame the most efficient way to draw many changing unique triangles?

假装没事ソ 提交于 2019-12-12 09:39:53
问题 Answers to my previous question suggested that I use a Vertex Buffer Object and merge my position data with my color data into a single array, which I have now done in this simple test case: http://jsfiddle.net/headchem/r28mm/14/ Pseudo code for every frame: function drawFrame() { // clear global vertex[] array containing both position and color // recreate it with new triangles and colors (determined elsewhere) drawShapes(); // put the vertex array into the VBO using gl.bufferData // finish

WebGL and HTML shader-type

吃可爱长大的小学妹 提交于 2019-12-12 09:30:37
问题 I declare my GLSL ES shader program within a HTML file, using this code: <script id="shader-fs" type="x-shader/x-fragment">..shader-code..</script> as seen in the learning WebGL examples. Everything works fine, but I dont understand why I should use the type attribute of the script tag. I want to know where the "x-shader/x-fragment" value is specified. Who does that.. the W3C, the Khronos Group or the browser developers? Can anybody help me? Tahnk you. 回答1: There is no official organization

Three.js WebGL Draw a circle custom fill and border color from shader

风格不统一 提交于 2019-12-12 09:24:28
问题 I'm using Three.js with the WebGLRenderer. I'm trying to figure out or see an example for how to draw circles using CircleGeometry and be able to control their fill and border color from a vertex or fragment shader. Is this even possible without using an image for the texture? Sorry if this is really simple, I'm still trying to wrap my head around Three.js and WebGL so any help is appreciated. 回答1: Geometry presentation of the circle is imprefect because roundness depends on the number of

browser refresh does not do garbage collection

爱⌒轻易说出口 提交于 2019-12-12 07:49:05
问题 I have found this on all browsers tested - IE, Firefox, Chrome and Safari on Window sand Safari on Apple. Allegedly, a browser refresh, back button or forward link should dump the browser nodes and javascript variables and objects, etc. This appears to not be the case for WebGL. I first noticed it when developing a complex WebGL application that requires about 100MB to 200MB of memory. While developing, I have to do a lot of refreshes and my computer would start to slow down and freeze after

WebGL image rendering bad quality

旧城冷巷雨未停 提交于 2019-12-12 07:38:36
问题 I have a problem with image rendering in WebGL: I have a canva, with a quad that takes the whole canvas, and a texture which is supposed to be mapped onto the whole quad (I have set the correct texture coordinates). The image is a Uint8array containing RGB data (in this order) and the image is 1024*768 pixels. I have the correct buffer. Here is the link to the image. The problem is the following: when rendered into WebGL, my picture becomes blurry and fuzzy, even if I have a canva that is the

How Do I Use an HTML5 Canvas as a WebGL Texture

送分小仙女□ 提交于 2019-12-12 07:33:44
问题 I want to: Set Uniform values for case i. Render compute shader for case i to an HTML5 <canvas> tag. Use the <canvas> contents (case i render output) as a texture in the next render pass. Repeat for all cases. Extract answers into JS from color data. I'm trying to make a compute shader and need to carry a value per pixel (fragment) on each render pass. A simple example would be incrementing the blue value of a pixel on each render call. I.e. pass 1: b=1 pass 2: b=2 pass 2: b=3 etc. Is this

THREE.js - Billboard Vertex Shader

风流意气都作罢 提交于 2019-12-12 07:22:29
问题 I have the need to orientate an instance of THREE.Mesh to always face the camera. I know I could just use the [THREE.Mesh].lookAt() method, but I'm trying to work on my GLSL chops a bit more and want to be able to do this in a vertex shader. I've read through NeHe's Billboarding tutorial, and it makes sense to me. Well, all apart from the bit where one applies these orientation vectors to each vertex. I feel like I'm very close to getting this working, but as it stands at the moment, my

Atmosphere Scattering for Earth from space and on the ground

心不动则不痛 提交于 2019-12-12 06:15:37
问题 Please provide prompt how to make the atmosphere of the Earth so that it is visible from space and from the ground (as shown in the image) a model of the earth: Earth = new THREE.Mesh(new THREE.SphereGeometry(6700,32,32),ShaderMaterialEarth); model of the cosmos: cosmos= new THREE.Mesh(new THREE.SphereGeometry(50000,32,32),ShaderMaterialCosmos); and a light source: sun = new THREE.DirectionalLight(); where to start, just I do not know. Perhaps this should do ShaderMaterialCosmos , where to

map world coordinate to a texture's value in fragment shader

ε祈祈猫儿з 提交于 2019-12-12 05:28:22
问题 I am trying to map a world coordinate to a texture's value in the fragment shader using threeJS. The generated 'color' is only black but webgl doesn't return any error. Here is what I get: in the 3D, what I get in webgl (black slice instead of an image) in the 2D canvas, what I should in webgl. My shaders: <script id="vertShader" type="shader"> varying vec4 vPos; void main() { vPos = modelViewMatrix * vec4(position, 1.0 ); gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0