shader

OpenGL 编程指南 (4)

旧时模样 提交于 2020-02-25 20:49:41
1、OpenGL用户裁剪需要使用一个vertex shader的内置变量gl_ClipDistance,它是一个声明的时没有指定大小的数组,因此需要重新声明它的大小或者将它作为一个编译时的常量使用(啥意思???)。 gl_ClipDistance每一个元素对应一个平面,平面数目有限通常为8个,可以通过gl_MaxClipDistances获取平台支持的最大值。这个数组大小包括了已经启用的其它裁剪面,vertex shader必须写入所有已经启用裁剪面的距离,否则表现不可预测,通过裁剪的片元可以读取裁剪面插值后的结果。 2、transform feedback 是顶点处理结束之后,图元装配和光栅化之前的步骤,它能够重获获取顶点数据后选择性地部分或全部传递到缓冲对象中。 void glGenTransformFeedbacks(GLsizei n, GLuint* ids) void glBindTransformFeedback(GLenum target, GLuint id)//target 必须是 GL_TRANSFORM_FEEDBACK 系统有一个默认的transform feedback对象,id为0。可以同时给transform feedback对象绑定多个缓冲,也可以绑定缓冲对象的多个子块,甚至可以将统一个缓冲对象的不同子块同时绑定到不用的transform

How to fix this OpenGL error? “unexpected tokens following preprocessor directive - expected a newline”

梦想的初衷 提交于 2020-02-25 05:41:51
问题 I am trying to complete my first JOGL OpenGL program using shaders. I am just starting with a simple Vertex shader which does a compilation error. The shader is expected to receive a vec2(0.5, 0.5) which is basically (x,y) coordinates and it generates a proper vec4(x-1.0,y-1.0,0.0,1.0) pixel. The program actually displays the pixel, but it is not using the shader as the shader gives compilation error. How can I get more information on what is failing? Nowhere in the JOGL API code is specified

How to fix this OpenGL error? “unexpected tokens following preprocessor directive - expected a newline”

有些话、适合烂在心里 提交于 2020-02-25 05:41:06
问题 I am trying to complete my first JOGL OpenGL program using shaders. I am just starting with a simple Vertex shader which does a compilation error. The shader is expected to receive a vec2(0.5, 0.5) which is basically (x,y) coordinates and it generates a proper vec4(x-1.0,y-1.0,0.0,1.0) pixel. The program actually displays the pixel, but it is not using the shader as the shader gives compilation error. How can I get more information on what is failing? Nowhere in the JOGL API code is specified

Pack depth information in a RGBA texture using mediump precison

陌路散爱 提交于 2020-02-24 21:53:16
问题 Trying to understand the many issues related to the WebGL development for a generic mobile target, now I need to store depth information in a texture attachment for later retrieval and post-processing. JavaScript: var depthRB = gl.createRenderbuffer(); gl.bindRenderbuffer(gl.RENDERBUFFER, depthRB); gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, w, h); gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthRB); gl.bindRenderbuffer(gl.RENDERBUFFER,

Pack depth information in a RGBA texture using mediump precison

做~自己de王妃 提交于 2020-02-24 21:51:33
问题 Trying to understand the many issues related to the WebGL development for a generic mobile target, now I need to store depth information in a texture attachment for later retrieval and post-processing. JavaScript: var depthRB = gl.createRenderbuffer(); gl.bindRenderbuffer(gl.RENDERBUFFER, depthRB); gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, w, h); gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthRB); gl.bindRenderbuffer(gl.RENDERBUFFER,

Pack depth information in a RGBA texture using mediump precison

ぐ巨炮叔叔 提交于 2020-02-24 21:50:21
问题 Trying to understand the many issues related to the WebGL development for a generic mobile target, now I need to store depth information in a texture attachment for later retrieval and post-processing. JavaScript: var depthRB = gl.createRenderbuffer(); gl.bindRenderbuffer(gl.RENDERBUFFER, depthRB); gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, w, h); gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthRB); gl.bindRenderbuffer(gl.RENDERBUFFER,

Differing floating point behaviour between uniform and constants in GLSL

五迷三道 提交于 2020-02-24 10:23:41
问题 I am trying to implement emulated double-precision in GLSL, and I observe a strange behaviour difference leading to subtle floating point errors in GLSL. Consider the following fragment shader, writing to a 4-float texture to print the output. layout (location = 0) out vec4 Output uniform float s; void main() { float a = 0.1f; float b = s; const float split = 8193.0; // = 2^13 + 1 float ca = split * a; float cb = split * b; float v1a = ca - (ca - a); float v1b = cb - (cb - b); Output = vec4(a

Differing floating point behaviour between uniform and constants in GLSL

孤街浪徒 提交于 2020-02-24 10:23:26
问题 I am trying to implement emulated double-precision in GLSL, and I observe a strange behaviour difference leading to subtle floating point errors in GLSL. Consider the following fragment shader, writing to a 4-float texture to print the output. layout (location = 0) out vec4 Output uniform float s; void main() { float a = 0.1f; float b = s; const float split = 8193.0; // = 2^13 + 1 float ca = split * a; float cb = split * b; float v1a = ca - (ca - a); float v1b = cb - (cb - b); Output = vec4(a

游戏 图形方面 面试题

∥☆過路亽.° 提交于 2020-02-23 19:34:49
图形学渲染流程(管线)说一下 答: 传统的前向渲染管线流程是这样的 顶点和索引到顶点着色器,这里主要是对顶点进行变换,然后是光栅化,这里将剔除视锥体之外的元素,光栅化后三角形内的像素将进入到片元着色器(像素着色器),经过深度测试(模板测试)后写入到Target缓冲区内。 其实还有计算shader,用于曲面细分的三个shader,几何shader,RayTrace shader等,不展开了。 BDRF函数 答:BRDF函数是射出光线的辐照度和摄入光线辐射率的比值,在现代引擎中BRDF一般使用Cook-Torrance 的公式,定义为F菲涅尔(F0,NV) G(L,N,V) 几何函数 D(N,H,Roughness) 法线分布函数(H为L,V的半角向量) 除以4*(NL)*(NV) IBL基本原理 答: 在PBR渲染公式中,我们不仅仅算直接光源,也要考虑来自环境的间接光源,因此把来自环境光的信息储存在cubeMap中供计算,这就是IBL,基于图形的光照,在这种情况下需要对光照方程进行分割,分为环境光和镜面光两部分,为了提高速度一般都会把这些卷积的结果存储在贴图里面,对于漫反射,存不同法线下的卷积结果,对于高光需要先分拆为 预滤波环境贴图和预计算BRDF,这里有一个N=V=R的假设,基于重要性采样,可以把第二项看为参数为NWi和Roughness参数的二维函数,就可以预计算贴图

Normal mapping GLSL using LibGDX

一世执手 提交于 2020-02-23 09:30:47
问题 I try to implement normal mapping using LibGDX. So I got some positive results when I calculate diffuse and specular color in vertex shader (at least I think so). Vertex shader: attribute vec4 a_position; attribute vec2 a_texCoord0; attribute vec3 a_normal; varying vec2 v_texCoord; varying float v_diffuse; varying vec3 v_specular; varying vec3 v_lightVec; uniform mat4 u_worldTrans; uniform mat4 u_projTrans; uniform mat4 u_matViewInverseTranspose; uniform mat4 u_matModelView; const vec3