WebGL

Passing color to fragment shader from javascript

浪子不回头ぞ 提交于 2019-12-04 17:15:21
I am currently learning webgl and have a question. I am trying to make a triangle and passing the color info into fragment shader from js file. The following is my js code. var VSHADER_SOURCE = 'attribute vec4 a_Position;\n'+ 'attribute vec4 a_Color;\n'+ 'varying vec4 v_Color;\n'+ 'void main(){\n'+ 'gl_Position = a_Position;\n'+ 'v_Color = a_Color;\n'+ '}\n'; var FSHADER_SOURCE = 'precision highp float;\n'+ 'varying vec4 v_Color;\n'+ 'void main() {\n'+ 'gl_FragColor = v_Color;\n'+ '}\n'; function main(){ var canvas = document.getElementById('webgl'); var gl = getWebGLContext(canvas); if(!gl){

Unproject results for object picking

最后都变了- 提交于 2019-12-04 16:17:34
There are several references to this around the web, including from stackoverflow. I have an unproject method which returns x,y coordinates which are returning in range of -1 and 1. Im wondering if these values are correct. If so, then what do i do with these values, multiply b the cameras position? Reference: How to convert mouse coordinate on screen to 3D coordinate Updated I found a bug in my matrix library, where I was missing some matrix components, I think it was in the multiplication method. After fixing this, I am no longer getting the -1 to 1 range. Now my data (freshly returned from

Mesh becomes very angular after substracting with ThreeCSG

怎甘沉沦 提交于 2019-12-04 16:03:20
问题 I experience a problem when substracting a mesh from an other mesh using ThreeCSG. My main mesh is a ring and the mesh to substract is a diamond. Before the process to scene looks like this: Mesh fine. But after substracting the meshes the ring becomes angular: Mesh Broken. I do apply the same material / shading as before. Here is the code I use: var ring_bsp = new ThreeBSP(ring); var stone_bsp = new ThreeBSP(stone); var substract_bsp = ring_bsp.subtract( stone_bsp ); var result = substract

How do I add a tag/label to appear on top of several objects so that the tag always faces the camera when the user clicks the object?

烂漫一生 提交于 2019-12-04 14:14:56
问题 Essentially, what I am saying is I want to create a tag or label that appears on top of/on the surface of an object so that the tag always faces the camera when the user clicks the object even when the object is rotated. How do I go about doing so? I was told to use Orthogonal camera (but I'm not sure how?) and CSS for the label (see previous post: How can I make my text labels face the camera at all times? Perhaps using sprites?) The label in CSS and html is below. However, I want to do this

Texture shape extrude in three.js

被刻印的时光 ゝ 提交于 2019-12-04 14:10:34
I'm trying to texture an extruded shape in Three.js. In the following code I create a curved shape, extrude the shape, then create a mesh with the geometry and a material I've loaded from a Jpg file. The wireframe displays but the texture does not. The texture is 512*512px in size. Am I using the correct approach? Do I need to manually UV map the texture? I'd like the texture to wrap to the entire extruded face instead of each individual quad. var x = -50, y = 20, z = 150; var rx = 0, ry = Math.PI/4, rz = 0; var scale = 1; var color = 0x00ff00; var shape = new THREE.Shape(); shape.moveTo( x, y

Three.js: texture to datatexture

人盡茶涼 提交于 2019-12-04 14:09:16
问题 I'm trying to implement a delayed webcam viewer in javascript, using Three.js for WebGL capabilities. I need to store frames grabbed from webcam, so they can be shown after some time (some milliseconds to some seconds). I'm able to do this without Three.js, using canvas and getImageData() . You can find an example on jsfidle. I'm trying to find a way to do this without canvas, but using Three.js Texture or DataTexture object. Here an example of what I'm trying. The problem is that I cannot

flat shading in webGL

痞子三分冷 提交于 2019-12-04 14:03:37
I'm trying to implement flat-shading in webgl, I knew that varying keyword in vertex shader will interpolation that value and pass it to fragment shader. I'm trying to disable interpolation, and I found that flat keyword can do this, but it seems cannot use in webgl? flat varying vec4 fragColor; always getting error: Illegal use of reserved word 'flat' BrunoLevy I think 'flat' is not supported by the version of GLSL used in WebGL. If you want flat shading, there are several options: 1) replicate the polygon's normal in each vertex. It is the simplest solution, but I find it a bit

google maps using three.js and webgl

不打扰是莪最后的温柔 提交于 2019-12-04 13:33:19
问题 I have thousands of points that need to be plotted on google maps and got a very responsive maps using the example from https://github.com/ubilabs/google-maps-api-threejs-layer . Did anyone have a play at this and wondering if it is possible to have different colored markers and possible marker click events? Appreciate any pointers or examples online. 回答1: Millions of clickable data points can be painted on a google map using webgl. A data point is represented by an x,y pair for a location on

Enable WebGL in the Mac OS application on WebKit

拜拜、爱过 提交于 2019-12-04 13:14:19
问题 I am writing an application for Mac OS - browser on WebKit to use for the some site on WebGL. All is ready, the application correctly displays normal HTML sites, but WebGL doesn't work. How can enable WebGL in my app? 回答1: Once you have a WebView, there is an undocumented method which can enable WebGL: WebPreferences *p = [webView preferences]; if ([p respondsToSelector:@selector(setWebGLEnabled:)]) { [p setWebGLEnabled:YES]; } In this example I have protected it with respondsToSelector: to

Creating a Gradient Color in Fragment Shader

孤人 提交于 2019-12-04 13:04:33
I'm trying to achieve making a gradient color as the design apps (Photoshop for example) does, but can't get the exact result i want. My shader creates very nice 'gradients' but also contains other colors that are different from the colors I want to switch in. It looks nice but, my aim is adding blending functions later and make a kind of color correction shader. but first of all I have to get the right colors. Here is my fragment shader http://player.thebookofshaders.com/?log=171119111216 uniform vec2 u_resolution; void main() { vec2 st = gl_FragCoord.xy/u_resolution.xy; vec3 color1 = vec3(1