glsl

Metal Shading Language - multidimensional array

空扰寡人 提交于 2019-12-25 09:09:01
问题 How can I convert this: const vec3 GDFVectors[19] = vec3[]( normalize(vec3(1, 0, 0)), normalize(vec3(0, 1, 0)), normalize(vec3(0, 0, 1)), normalize(vec3(1, 1, 1 )), normalize(vec3(-1, 1, 1)), normalize(vec3(1, -1, 1)), normalize(vec3(1, 1, -1)), normalize(vec3(0, 1, PHI+1)), normalize(vec3(0, -1, PHI+1)), normalize(vec3(PHI+1, 0, 1)), normalize(vec3(-PHI-1, 0, 1)), normalize(vec3(1, PHI+1, 0)), normalize(vec3(-1, PHI+1, 0)), normalize(vec3(0, PHI, 1)), normalize(vec3(0, -PHI, 1)), normalize

Cone from direction vector

此生再无相见时 提交于 2019-12-25 08:47:53
问题 I have a normalized direction vector (from a 3d position to a light position) and I would like this vector to be rotated by some angle so I can create a "cone". Id like to simulate cone tracing by using the direction vector as the center of the cone and create an X number of samples to create more rays to sample from. What I would like to know is basically the math behind: https://docs.unrealengine.com/latest/INT/BlueprintAPI/Math/Random/RandomUnitVectorinCone/index.html Which seems to do

imageStore in compute shader to depth texture

自古美人都是妖i 提交于 2019-12-25 08:17:37
问题 I can't for the life of me workout how to write to a depth texture using imageStore within a compute shader, I've checked what I'm doing against several examples (e.g. this and this), but I still can't spot the fault. I can write to the texture as a Framebuffer, and when calling glTexImage2D() , but for some reason executing this compute shader doesn't affect the named texture (which i'm checking via rendering to screen). You can skip straight to the below accepted answer if the above applies

GLSL #if directive with ==

佐手、 提交于 2019-12-25 03:48:13
问题 Some people are reporting bugs in shaders in our client software. Reports looks like this: ERROR: 0:63: error#71) Syntax error incorrect preprocessor directive WARNING: 0:63: warning#64) Unexpected tokens following the preprocessor directive - expected a newline(#if ) ERROR: 0:67: error#71) Syntax error incorrect preprocessor directive WARNING: 0:67: warning#64) Unexpected tokens following the preprocessor directive - expected a newline(#if ) ERROR: 0:71: error#71) Syntax error incorrect

OpenGL/ES 2.0 and Higher: How to Compile Multiple Shader Files Together

╄→гoц情女王★ 提交于 2019-12-25 03:42:56
问题 This question has been asked multiple times in different ways. My question is specific to OpenGL 2.0 / GLSL 1.10 and higher and potential compatibility with OpenGL ES 2.0 and its supported version of GLSL: What are recommended C/C++ APIs used to combine multiple files into one shader source to pass into glShaderSource. For example, if I have 3 files A.frag, B.frag, C.frag that have the following contents: /* A.frag */ struct A { vec3 val; }; /* B.frag */ struct B { vec3 val; }; /* C.frag */

OpenGL/ES 2.0 and Higher: How to Compile Multiple Shader Files Together

扶醉桌前 提交于 2019-12-25 03:42:32
问题 This question has been asked multiple times in different ways. My question is specific to OpenGL 2.0 / GLSL 1.10 and higher and potential compatibility with OpenGL ES 2.0 and its supported version of GLSL: What are recommended C/C++ APIs used to combine multiple files into one shader source to pass into glShaderSource. For example, if I have 3 files A.frag, B.frag, C.frag that have the following contents: /* A.frag */ struct A { vec3 val; }; /* B.frag */ struct B { vec3 val; }; /* C.frag */

Is there anything wrong with my glsl shader loading code?

妖精的绣舞 提交于 2019-12-25 02:10:05
问题 The problem is that, shaders (pretty simple ones, as I'm learning OpenGL) fail to compile in a seemingly random manner (and gives random error messages * ). The same shaders, however, compile after about 3 or 4 tries. Here is the code: Shader::Shader(GLenum Type,std::string filename) { shader_type = Type; std::ifstream ifs(filename); if(!ifs) throw(std::runtime_error("File:"+filename+" not opened.")); std::ostringstream stream; stream<<ifs.rdbuf(); const GLchar* data = stream.str().c_str();

How to make a billboard spherical

♀尐吖头ヾ 提交于 2019-12-25 02:01:23
问题 Following this turorial here I have managed to create a cylindrical billboard (it utilizes a geometry shader which takes points and produces quads). The problem is that when i move the camera so that it's higher than the billboard (using gluLookat) the billboard does not rotate to truly face the camera (as if it was a cylindrical billboard). How do I make it into spherical? if anyone interested, here is slightly modified geometry shader code: #version 330 //based on a great tutorial at http:/

GLSL vertex shader gl_Position for gl.POINTS with large gl.PointSize

隐身守侯 提交于 2019-12-25 01:43:52
问题 I'm trying to render a lot of points with large gl_PointSize. Looks vertex shader will automatically discard gl.POINTS rendering if the position is out if[-1, 1]. In my case, if the point's position is a little bit out of [-1, 1], part of it still should be shown on the canvas. Any way to let the shader keep rendering point, when position out of [-1, 1]? Here's the code to draw a point with position a little bit off the canvas. But it is expect to show nearly half of it on canvas. var

GLSL 三种变量类型(uniform,attribute和varying)

我只是一个虾纸丫 提交于 2019-12-25 01:23:35
1.uniform变量 uniform变量是外部程序传递给(vertex和fragment)shader的变量。因此它是application通过函数glUniform**()函数赋值的。在(vertex和fragment)shader程序内部,uniform变量就像是C语言里面的常量(const ),它不能被shader程序修改。(shader只能用,不能改) 如果uniform变量在vertex和fragment两者之间声明方式完全一样,则它可以在vertex和fragment共享使用。(相当于一个被vertex和fragment shader共享的全局变量) uniform变量一般用来表示:变换矩阵,材质,光照参数和颜色等信息。 以下是例子: uniform mat4 viewProjMatrix; //投影+视图矩阵 uniform mat4 viewMatrix; //视图矩阵 uniform vec3 lightPosition; //光源位置 uniform float lumaThreshold; uniform float chromaThreshold; uniform sampler2D SamplerY; uniform sampler2D SamplerUV; uniform mat3 colorConversionMatrix; 2