shader

Trouble with Phong Shading

試著忘記壹切 提交于 2019-12-09 06:38:16
问题 I am writing a shader according to the Phong Model. I am trying to implement this equation: where n is the normal, l is direction to light, v is the direction to the camera, and r is the light reflection. The equations are described in more detail in the Wikipedia article. As of right now, I am only testing on directional light sources so there is no r^2 falloff. The ambient term is added outside the below function and it works well. The function maxDot3 returns 0 if the dot product is

OO architecture for rendering in shader based games

大城市里の小女人 提交于 2019-12-09 04:44:22
问题 I keep hitting this problem when building game engines where my classes want to look like this: interface Entity { draw(); } class World { draw() { for (e in entities) e.draw(); } } That's just pseudo-code to show roughly how the drawing happens. Each entity subclass implements its own drawing. The world loops through all the entities in no particular order and tells them to draw themselves one by one. But with shader based graphics, this tends to be horribly inefficient or even infeasible.

Precise control over texture bits in GLSL

自古美人都是妖i 提交于 2019-12-09 02:51:43
问题 I am trying to implement an octree traversal scheme using OpenGL and GLSL, and would like to keep the data in textures. While there is a big selection of formats to use for the texture data (floats and integers of different sizes) I have some trouble figuring out if there is a way to have more precise control over the bits and thus achieving greater efficiency and compact storage. This might be a general problem, not only applying to OpenGL and GLSL. As a simple toy example, let's say that I

hazy artefact on OS X WebGL on sides of volume rendering

谁都会走 提交于 2019-12-08 20:00:32
Does anyone know how to sort this weird effect? The sides of the volume we're trying to render seem artificially hazy. I'm running it on 2014 MacBook Pro, Intel Iris 1536 MB GPU, Yosemite v 10.10.2 (14C1514). I've heard that this is only a problem on machines running OS X, and it doesn't appear on Windows machines. I've also noticed it in some other places e.g. Leberba khronos.org/bugzilla/show_bug.cgi?id=1337 Bug reported so closing 来源: https://stackoverflow.com/questions/29493673/hazy-artefact-on-os-x-webgl-on-sides-of-volume-rendering

Three.js - problems smooth shading a Lambert material on custom geometry

纵然是瞬间 提交于 2019-12-08 15:46:42
问题 I have created a custom geometry in Three.js. Now, I would like to create a mesh that uses a smooth-shaded Lambert material. Using a loop, I have created the array of vertices, then faces, and afterwards I have called geometry.computeCentroids(); geometry.computeFaceNormals(); geometry.computeVertexNormals(); var colorMaterial = new THREE.MeshLambertMaterial( {color: 0x0000ff, side: THREE.DoubleSide} ); var mesh = new THREE.Mesh( geometry, colorMaterial ); scene.add(mesh); The result is

Are 1D Textures Supported in WebGL yet?

我的未来我决定 提交于 2019-12-08 15:24:30
问题 I've been trying to find a clear answer, but it seems no one has clearly asked the question. Can I use a 1D sampler and 1D texture in WebGL Chrome, Firefox, Safari, IE, etc? EDIT Understandably 1 is indeed a power of 2 (2^0=1) meaning you could effectively use a 2D sampler and texture using a height of 1 and a width of 256 or 512 etc. to replicate a 1D texture. 1D textures are not moot, they exist because they not only have a purpose, but are intended to translate into optimizations on the

Best practices for coding , compiling, debugging and maintaining shader programs in opengl? [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-08 14:21:54
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I'm a newbie.. trying to learn shaders. I feel like its not that easy to code and debug it. Examples and tutorials I see on internet allows to code them in text files and read them as char pointer to pass them to shader compiler. Is there any best practices for coding - with intellisence , compiling , debugging (

webgl 灰度shader

给你一囗甜甜゛ 提交于 2019-12-08 14:16:55
var canvasElement=document.getElementById('webgl'); var gl=canvasElement.getContext('webgl'); //顶点着色器源码 var vertexShaderSource = '' + 'attribute vec4 a_Position;'+//顶点位置坐标 'attribute vec2 a_TexCoord;' +//纹理坐标 'varying vec2 v_TexCoord;'+//插值后纹理坐标 'void main(){' + 'gl_Position = a_Position;' +//逐顶点处理 'v_TexCoord = a_TexCoord;' +//纹理坐标插值计算 '}'; //片元着色器源码 var fragShaderSource = '' + 'precision highp float;' +//所有float类型数据的精度是lowp 'varying vec2 v_TexCoord;'+//接收插值后的纹理坐标 'uniform sampler2D u_Sampler;' +//纹理图片像素数据 'void main(){' + //采集纹素 'vec4 texture = texture2D(u_Sampler,v_TexCoord);' + /

我的webgl学习之路(五)用webgl画彩色三角形

别等时光非礼了梦想. 提交于 2019-12-08 14:16:35
要想做彩色三角线必须知道uniform、attribute、varying这三个声明; uniform 表示一次渲染过程中保存不变的 attribute 表示是实时在改变的 varying 用来着色器之间的通讯,也就是顶点着色器和片段着色去之间的桥梁 还需要注意的是varying 在顶点和片元着色器两个中都声明一个一样的变量;那么它就会自动默认,两个有关系,但并不是相同的;片元着色器中得到的varying 是经过插值运行得到后的值;要想改变三角形的颜色,就得改变顶点颜色,它是通过顶点的颜色,来进行计算的;就以线来说:两个顶点的颜色不同,那么中间的颜色怎么办,只能通过两端点的颜色进行插值计算;怎么插值,就像渐变一样,想象一下,在取色器中,连接任意两个点,它是不是是以一种渐变的方式进行变化;这些计算方式都是渲染管进行自动计算,你只需要把顶点额颜色传入; 代码如下: <!DOCTYPE html > < html lang= "en" > < head > < meta charset= "UTF-8" > < title > 多彩三角形 </ title > < script src= "../js/minMatrix.js" ></ script > < script id= "vs" type= "x-shader/x-vertex" > attribute vec3

Shader wireframe of an object

百般思念 提交于 2019-12-08 13:48:32
问题 I want to see a wireframe of an object without the diagonals like Currently, I add lines according to the vertices, the problem is after I have several of those I experience a major performance degradation. The examples here are either too new for my version of Three or don't work (I commented there about it). So I want to try to implement a shader instead. I tried to use this shader: https://stackoverflow.com/a/31610464/4279201 but it breaks the shape to parts and I'm getting WebGL errors.