glsl

Compile GLSL shader asynchronously or in a different thread on Android

会有一股神秘感。 提交于 2019-12-21 05:47:10
问题 I'm writing an effect filter for Android devices, which has two-dimension loops in the fragment shader. For most of the devices, the shader can be compiled and run in reasonable time, but some of the devices takes several minutes to compile the shader at the first time. My fragment shader has a heavy two-dimension kernel convolution: const lowp int KERNEL_RADIUS = 19; .... for (int y = -KERNEL_RADIUS; y <= KERNEL_RADIUS; y++) { for (int x = -KERNEL_RADIUS; x <= KERNEL_RADIUS; x++) { .... } }

understanding the basics of dFdX and dFdY

人走茶凉 提交于 2019-12-21 05:22:27
问题 I've read numerous descriptions of the behavior of dFdX(n) and dFdY(n) and do believe I still have a handle on partial derivatives from school. What I don't follow is where does 'n' come from in the simplest possible example? Reading the glsl built-in functions dFdx(n) and dFdy(n) without any context other than mathematics I would interpret them as "I have some function of x and y: f(x,y) , I take the partial derivative of that function w.r.t. x d/dx(x,y) , and I evaluate the partial

GLSL Checkerboard Pattern

限于喜欢 提交于 2019-12-21 05:11:35
问题 i want to shade the quad with checkers: f(P)=[floor(Px)+floor(Py)]mod2. My quad is: glBegin(GL_QUADS); glVertex3f(0,0,0.0); glVertex3f(4,0,0.0); glVertex3f(4,4,0.0); glVertex3f(0,4, 0.0); glEnd(); The vertex shader file: varying float factor; float x,y; void main(){ x=floor(gl_Position.x); y=floor(gl_Position.y); factor = mod((x+y),2.0); } And the fragment shader file is: varying float factor; void main(){ gl_FragColor = vec4(factor,factor,factor,1.0); } But im getting this: It seems that the

Reflection/refraction with chromatic aberration - eye correction

Deadly 提交于 2019-12-21 04:51:17
问题 I am writing a GLSL shader that simulates chromatic aberration for simple objects. I am staying OpenGL 2.0 compatible, so I use the built-in OpenGL matrix stack. This is the simple vertex shader: uniform vec3 cameraPos; varying vec3 incident; varying vec3 normal; void main(void) { vec4 position = gl_ModelViewMatrix * gl_Vertex; incident = position.xyz / position.w - cameraPos; normal = gl_NormalMatrix * gl_Normal; gl_Position = ftransform(); } The cameraPos uniform is the position of the

When switching to GLSL 300, met the following error

隐身守侯 提交于 2019-12-21 04:42:06
问题 when I switch to use OpenGL ES 3 with GLSL 300, I met the following error in my frag shader undeclared identifier gl_FragColor when using GLSL 100, everything is fine. 回答1: Modern versions of GLSL do fragment shader outputs simply by declaring them as out values, and gl_FragColor is no longer supported, hence your error. Try this: out vec4 fragColor; void main() { fragColor = vec4(1.0, 0.0, 0.0, 1.0); } Note that gl_FragDepth hasn't changed and is still available. For more information see

Floating point textures in OpenGL ES 2.0 on iOS without clamping them to [0, 1]

只愿长相守 提交于 2019-12-21 04:34:08
问题 I need gl_FragColor to "paint" floating point values, which also can be negative (x < 0) and > 1.0. I then want to use the color attachement of the FBO this values where rendered to and use it as a texture in another FBO. Now I have read on http://www.khronos.org/opengles/sdk/docs/man/ (under glTexImage2D) that all values are clamped to a range of [0, 1] and also I didn't find a glClampColor instruction. Is there a possibility to find a workaround here or does somebody have an idea which

Reconstructing world coordinates from depth buffer and arbitrary view-projection matrix

我与影子孤独终老i 提交于 2019-12-21 04:23:14
问题 I'm trying to reconstruct 3D world coordinates from depth values in my deferred renderer, but I'm having a heck of a time. Most of the examples I find online assume a standard perspective transformation, but I don't want to make that assumption. In my geometry pass vertex shader, I calculate gl_Position using: gl_Position = wvpMatrix * vec4(vertexLocation, 1.0f); and in my lighting pass fragment shader, I try to get the world coordinates using: vec3 decodeLocation() { vec4 clipSpaceLocation;

What extractly mat3(a mat4 matrix) statement in glsl do?

*爱你&永不变心* 提交于 2019-12-21 03:37:17
问题 I'm doing a per fragment lighting and when correcting normal vecter, i got this code: vec3 f_normal = mat3(MVI) * normal; Where MVI is: mat4 MVI = transpose(inverse(ModelViewMatrix)); . So what is return after mat3(MVI) statement? 回答1: mat3(MVI) * normal Returns the upper 3x3 matrix from the 4x4 matrix and multiplies the normal by that. This matrix is called the 'normal matrix'. You use this to bring your normals from world space to eye space. The upper 3x3 portion of the matrix is important

OpenGL 资源汇编

泪湿孤枕 提交于 2019-12-20 13:49:33
本文收集和汇总了 OpenGL 的文档、教程和在线书籍,供学习和开发者參考。 OPENGL开发教程: http://www.linuxgraphics.cn/opengl/index.html OpenGL 教程 大名鼎鼎的 Nehe 教程: http://nehe.gamedev.net/ OpenGL 入门学习系列讲的很清楚,推荐。 OpenGL入门学习之中的一个——编写第一个OpenGL程序 OpenGL入门学习之二——绘制几何图形 OpenGL入门学习之三——绘制几何图形的一些细节问题 OpenGL入门学习之四——颜色的选择 OpenGL入门学习之五——三维的空间变换 OpenGL入门学习之六——动画的制作 OpenGL入门学习之七——使用光照来表现立体感 OpenGL入门学习之八——使用显示列表 OpenGL入门学习之九——使用混合来实现半透明效果 OpenGL入门学习之十——BMP文件与像素操作 OpenGL入门学习之十一——纹理的使用入门 OpenGL入门学习之十二——OpenGL片断測试 OpenGL入门学习之十三——OpenGL是一个状态机 OpenGL入门学习之十四——OpenGL版本号和OpenGL扩展 OpenGL入门学习之十五——从“绘制一个立方体”来看OpenGL的进化过程 OpenGL入门学习之十六——在Windows系统中显示文字 ZwqXin博客

Textures in OpenGL ES 2.0 for Android

筅森魡賤 提交于 2019-12-20 10:25:36
问题 I'm new to OpenGL and I'm teaching myself by making a 2D game for Android with ES 2.0. I am starting off by creating a "Sprite" class that creates a plane and renders a texture to it. To practice, I have two Sprite objects that are drawn alternating in the same place. I got this much working fine and well with ES 1.0, but now that I've switched to 2.0, I am getting a black screen with no errors . I'm exhausted trying to figure out what I'm doing wrong, but I have a strong feeling it has to do