glsl

THREE.js custom tangent attribute how do i load it

倖福魔咒の 提交于 2019-12-13 05:31:52
问题 I'm looking at this example: http://threejs.org/examples/webgl_custom_attributes.html and notice that the custom displacement attribute gets filled by vertices.length for ( var v = 0; v < vertices.length; v++ ) { values[ v ] = 0; noise[ v ] = Math.random() * 5; } My question is, how does this relate to the number of normals, uvs and tangents? When i export my model from 3ds max, i have more UVs than vertices. I need to assign tangents per this UV number because they are different at seams. I

Reconstructing world position from linear depth

这一生的挚爱 提交于 2019-12-13 05:12:53
问题 i have issues reconstructing world positions from previously stored linear depth in glsl. I read lots of info online, but can't find my problem... So this is what I got: VS (storing depth to 32F): float linDepth(float z) { return (-z-zNear)/(zFar-zNear); } void main() { vec4 position = uViewMatrix * uModelMatrix * vec4(aPosition, 1); depth = linDepth(position.z); //store linear view-depth } FS (reconstuction): void main() { vec3 vUV = vec2(0..1, 0..1); (from screen aligned quad) vec3 ndc =

GLSL Shader (compilation error)

邮差的信 提交于 2019-12-13 04:59:55
问题 I've read all recommended posts, I've tried those solutions, but non of them helped. In short problem lies in the third argument of glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); This code work: const char *vertexShaderSource = "#version 120 \n" "attribute vec3 pos;\n" "attribute vec2 texCoord;\n" "varying vec2 texCoord0;\n" "uniform mat4 transform;\n" "void main()\n" "{\n" " gl_Position = transform * vec4(pos, 1.0);\n" " texCoord0 = texCoord;\n" "}\0"; But I want to read it from

C++ GLSL data alignment/padding

我与影子孤独终老i 提交于 2019-12-13 04:48:55
问题 I have a C++ class Matrix4x4 which has an array of 16 floats and no virtual methods: class Matrix4x4 { public: float values[16]; Matrix4x4(); Matrix4x4(float v0, float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8, float v9, float v10, float v11, float v12, float v13, float v14, float v15); Matrix4x4(const Quaternion &quat, const Vector3 &pos); void convertToQuatPos(Quaternion &quat, Vector3 &pos); void loadIdentity(); void setValues(float v0, float v1, float v2,

Writing to gl_FragColor causes glUseProgram to throw GL_INVALID_OPERATION

◇◆丶佛笑我妖孽 提交于 2019-12-13 04:28:47
问题 I'm trying to write a blur filter in GLSL ES 2.0 and I'm getting an Error with the line assigning gl_FragColor. I've not been able to figure out why #extension GL_OES_EGL_image_external : require precision mediump float; varying vec2 textureCoordinate; uniform samplerExternalOES s_texture; void main() { float gaus[25] = float[25](0.01739, 0.03478, 0.04347, 0.03478, 0.01739, 0.03478, 0.07282, 0.10434, 0.07282, 0.03478, 0.04347, 0.10434, 0.13043, 0.10434, 0.04347, 0.03478, 0.07282, 0.10434, 0

How to implement textureCube using 6 sampler2D

爷,独闯天下 提交于 2019-12-13 04:25:30
问题 Before I used a samplerCube to render the cube This is my previous fragmentShader code "uniform samplerCube tCubeTgt;", "varying vec3 posTgt;", "void main() {", "vec4 reflectedColorTgt = textureCube( tCubeTgt, vec3( -posTgt.x, posTgt.yz ) );", "gl_FragColor = reflectedColorTgt ;", "}" Now I want to use 6 sampler2D to render a cube. what should I do 回答1: Why? In any case looking up how cube mapping works there's a function and table in the OpenGL ES 2.0 spec showing how cube mapping works

Simple color GLSL shader doesn't output anything

冷暖自知 提交于 2019-12-13 04:23:51
问题 I'm trying to draw a sphere with just a diffuse color, but nothing shows up. All the OpenGL code should be correct, because if I swap the "color" shader with "textured" shader, everything shows up nicely. This is the shader selection code. The if-branch is for the textured objects, and the else-branch is for color-only objects. GL.Disable(EnableCap.Blend); if (phong.diffuseTexture != 0) { texturedShader.Enable(); GL.UniformMatrix4(texturedShader.GetUniformLocation("view"), false, ref camView)

Converting text (string into const char*) in C++

◇◆丶佛笑我妖孽 提交于 2019-12-13 03:28:03
问题 EDIT I've read all recommended posts, I've tried those solutions, but non of them helped. In short problem lies in the third argument of glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); This code work: const char *vertexShaderSource = "#version 120 \n" "attribute vec3 pos;\n" "attribute vec2 texCoord;\n" "varying vec2 texCoord0;\n" "uniform mat4 transform;\n" "void main()\n" "{\n" " gl_Position = transform * vec4(pos, 1.0);\n" " texCoord0 = texCoord;\n" "}\0"; But I want to read it

GLSL vertex shader performance with early return and branching

ぃ、小莉子 提交于 2019-12-13 03:24:06
问题 I have a vertex shader as such void main (){ vec4 wPos = modelMatrix * vec4( position , 1. ); vWorldPosition = wPos.xyz; float mask = step( 0., dot( cameraDir, normalize(normalMatrix * aNormal) ) ); gl_PointSize = mask * uPointSize; gl_Position = projectionMatrix * viewMatrix * wPos; } I'm not entirely sure how to test the performance of the shader, and exclude other factors like overdraw. I imagine a point of size 1, arranged in a grid in screen space without any overlap would work?

How do I create free hand mask on Image Like below using glsl Shader In android?

こ雲淡風輕ζ 提交于 2019-12-13 03:16:51
问题 I'm new to OpenGL and GLSL Programming. Recently I need to do freehand masking on an image like below Image. How could I achieve this using Fragment Shader? Currently, I am trying this with below fragment shader but Nothing Change on Image. precision mediump float; varying vec2 v_TexCoordinate; varying vec2 v_TexCoordinate2; uniform sampler2D u_Texture; uniform sampler2D u_Texture2; uniform bool u_alpha_test_enable; void main() { float mask = texture2D(u_Texture, v_TexCoordinate).a; // if (u