glsl

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

What extensions does github support, for syntax highlighting and for code/language recognition?

瘦欲@ 提交于 2020-02-22 07:48:06
问题 For my Open GL shaders, GitHub seems to recognize fragment shader ( extension .fs ) but not vertex shaders ( extension .vs ) Since GLSL has no defined extensions (it loads text) what is a good extension to use so I get my code recognized. As an example my shaders Example Shaders Note how .fs looks pretty and .vs like plain text 回答1: See if a .gitattributes linguistic directive, as I mentioned in "Github changes repository to wrong language", would be enough: *.vs linguist-detectable *.vs

Second order functions in GLSL?

巧了我就是萌 提交于 2020-02-21 12:35:28
问题 I'm looking for a way to use a function as an argument to another function in GLSL. In regular C, it can be simulated by passing a function pointer as a function argument. It also seems that other languages (like HLSL) now provide ways to deal with high-level constructs like higher-order functions, or can simulate them with clever use of HLSL structures. unfortunately I'm stuck with GLSL for now, and I can't find any way to simulate higher-order functions. Is it really impossible in current

Second order functions in GLSL?

拈花ヽ惹草 提交于 2020-02-21 12:33:43
问题 I'm looking for a way to use a function as an argument to another function in GLSL. In regular C, it can be simulated by passing a function pointer as a function argument. It also seems that other languages (like HLSL) now provide ways to deal with high-level constructs like higher-order functions, or can simulate them with clever use of HLSL structures. unfortunately I'm stuck with GLSL for now, and I can't find any way to simulate higher-order functions. Is it really impossible in current

GLSL point inside box test

孤街浪徒 提交于 2020-02-21 11:18:04
问题 Below is a GLSL fragment shader that outputs a texel if the given texture coord is inside a box, otherwise a color is output. This just feels silly and the there must be a way to do this without branching? uniform sampler2D texUnit; varying vec4 color; varying vec2 texCoord; void main() { vec4 texel = texture2D(texUnit, texCoord); if (any(lessThan(texCoord, vec2(0.0, 0.0))) || any(greaterThan(texCoord, vec2(1.0, 1.0)))) gl_FragColor = color; else gl_FragColor = texel; } Below is a version

GLSL 变量属性

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-09 09:09:23
1. attribute变量 为这个attribute变量指定一个位置(用无符号值表示):glBindAttribLocation 利用这个“位置”来指定需要传给shader里的attribue变量的数据:glVertexAttribPointer 2.uniform变量 Uniform是一种从CPU中的应用向GPU中的着色器发送数据的方式,但uniform和顶点属性有些不同。首先,uniform是全局的(Global)。全局意味着uniform变量必须在每个着色器程序对象中都是独一无二的,而且它可以被着色器程序的任意着色器在任意阶段访问。第二,无论你把uniform值设置成什么,uniform会一直保存它们的数据,直到它们被重置或更新。 我们通常在shaderProgram链接后获取一个uniform变量的位置,然后向这个位置传送数据(glGetUniformLocation/glUniform)。 但是要特别注意的一点是:我们只有在启用了一个shaderProgram后,才能做这样的事情 如果你声明了一个uniform却在GLSL代码中没用过,编译器会静默移除这个变量,导致最后编译出的版本中并不会包含它,这可能导致几个非常麻烦的错误 注意,查询uniform地址不要求你之前使用过着色器程序,但是更新一个unform之前你 必须 先使用程序(调用glUseProgram)

Vulkan SDK 之 Shaders

北战南征 提交于 2020-02-07 10:28:07
Compiling GLSL Shaders into SPIR-V 1、SPIR-V 是vulkan的底层shader语言。GLSL可以通过相关接口转换为SPIR-V。 Creating Vulkan Shader Modules 来源: https://www.cnblogs.com/khacker/p/12271897.html

OpenGL 简明教程(三)着色器

拟墨画扇 提交于 2020-02-06 13:25:06
3.1 开始 着色器(Shader)是运行在GPU上的小程序,上一篇中我们学会了如何使用着色器来将顶点数组变成我们想要的图形——三角形,在本篇中我们要作出其它图形,比如矩形;着色器的配置方法,还有图形的颜色的配置,实现一些其他色彩等等。 3.2 矩形 3.2.1 添加顶点 如果只运用上一篇的知识,要绘制一个矩形,可以看作绘制两个相连的三角形。如此一来只要向着色器程序中传入两个三角形——6个顶点数据即可,着色器程序也不需要改动。 GLfloat vertices [ ] = { // 第一个三角形 0.5f , 0.5f , 0.0f , // 右上角 0.5f , - 0.5f , 0.0f , // 右下角 - 0.5f , 0.5f , 0.0f , // 左上角 // 第二个三角形 0.5f , - 0.5f , 0.0f , // 右下角 - 0.5f , - 0.5f , 0.0f , // 左下角 - 0.5f , 0.5f , 0.0f // 左上角 } ; 只要主循环中的绘制函数作些许改动,就能实现一个矩形的绘制。 // 将原来的 3改为 6,绘制 6个顶点的三角形 glDrawArrays ( GL_TRIANGLES , 0 , 6 ) ; 3.2.2 索引方式 绘制矩形要使用 6个顶点有些浪费机能,实际上矩形只有 4个顶点,OpenGL 提供了索引绘制方式

OpenGL gluLookat not working with shaders on

一世执手 提交于 2020-02-05 13:57:08
问题 When i want to use gluLookat and have the shaders on it doesnt move the "camera" when i turn the shaders off it works correctly. Is there something missing in my shaders, i cant figure out what. void display(void) { glClear(GL_COLOR_BUFFER_BIT); glClearColor(0.8, 0.8, 0.8, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.5,0,1,0.5,0,0,0,1,0); glColor3f(0, 0, 0); glDrawArrays(GL_TRIANGLES, 0, 6); glDrawArrays(GL_LINES, 6, 6); glDrawArrays(GL_TRIANGLES, 12,6); glDrawArrays(GL_LINES

OpenGL ES 2.0 / GLSL not rendering data (Kotlin)

本秂侑毒 提交于 2020-02-05 02:53:50
问题 I am trying to implement a basic shading program with GLES 2/3, and have pieced together this code from various tutorials. Everything looks correct to me, and it compiles fine, but nothing appears on my screen. It rendered fine until I added Normal and Light Position data, then it broke and I haven't been able to find a way to fix it. Can anyone see what's wrong here? class MyRenderer:GLSurfaceView.Renderer{ var glProgram = -1 var uMV = -1 var uMVP = -1 var uLightPos = -1 var aPosition = -1