vertex-shader

What are the valid types for a WebGL vertex shader attribute?

柔情痞子 提交于 2019-12-12 15:56:27
问题 The following attribute seems fine: attribute vec4 coord; The following attribute complains that an attribute "cannot be bool or int": attribute int ty; The following attribute complains of a "syntax error": attribute uint ty; These results seem quite arbitrary. I can't find a list of the valid types for vertex shader attributes. What are the rules for whether an attribute type is valid in WebGL? 回答1: OpenGL ES Shading Language 1.00 specification, page 36, section 4.3.3: "Attribute": The

GLSL per vertex fixed size array

人走茶凉 提交于 2019-12-12 08:27:26
问题 Is it possible in desktop GLSL to pass a fixed size array of floats to the vertex shader as an attribute? If yes, how? I want to have per vertex weights for character animation so I would like to have something like the following in my vertex shader: attribute float weights[25]; How would I fill the attribute array from my C++ & OpenGL program? I have seen in another question that I could get the attribute location of the array attribute and then just add the index to that location. Could

OpenGL Reflection shader showing only grey

偶尔善良 提交于 2019-12-12 05:25:15
问题 I'm very new to OpenGL and I've been working with setting up sky boxes, and finally fixed it thanks to some help here but now the reflection shader I've tried to set up by editing some I've found (so a sphere will have a basic reflection effect based on the cube map of my sky box) will not show any color but grey as shown in the image. http://i.imgur.com/Th56Phg.png I'm having no luck figuring out, here is my shader code: Vertex Shader #version 330 core attribute vec3 position; attribute vec2

Shader Texture Always Facing The Camera

浪子不回头ぞ 提交于 2019-12-11 19:19:10
问题 I have this basic shader, though I ran into some trouble which really bugs me! I'm applying the texture using the fragment shader though however I move or rotate the camera, the texture on the face will always be facing the camera (I've added a GIF image as an example). So as you can see on the image above the texture keeps facing the camera, also if I move away of closer it will keep its scale. I'm trying to achive that I can move around and the texture will keep it's position, rotation and

Three.js: Objects intersected and shader material

你。 提交于 2019-12-11 07:18:23
问题 I have a scene with objects intersected using Lambert material, like in this jsFiddle. Now I need/want to switch the material of that plane to a Shader material and the plane turns into a background thing, like here. The question is, can I use different materials in objects and still preserve the intersection effect? Is this a Three.js limitation or this is how shaders works? Or am I missing a parameter in the renderer/material? At the moment is not an option no switch all my work to shader

WebGL heightmap using vertex shader, using 32 bits instead of 8 bits

元气小坏坏 提交于 2019-12-11 07:03:56
问题 I'm using the following vertex shader (courtesy http://stemkoski.github.io/Three.js/Shader-Heightmap-Textures.html) to generate terrain from a grayscale height map: uniform sampler2D bumpTexture; uniform float bumpScale; varying float vAmount; varying vec2 vUV; void main() { vUV = uv; vec4 bumpData = texture2D( bumpTexture, uv ); vAmount = bumpData.r; // assuming map is grayscale it doesn't matter if you use r, g, or b. // move the position along the normal vec3 newPosition = position +

OpenGL ES 2.0 - Multiple Programs or Shaders

佐手、 提交于 2019-12-11 05:57:02
问题 I currently have two programs, one program for solid lines and fills with a vertex-shader-for-solids and a fragment-shader-for-solids and a second program for textures with a vertex-shader-for-textures and a fragment-shader-for-textures. I swap the the two programs in and out using glUseProgram depending on what I am drawing. Is this a good solution? Or should I glAttachShader/glDetachShader from a single program? 回答1: Definitely, you're using the right solution. Binding a different program

Weird behavior of OpenGL / glGetUniformLocation()

旧巷老猫 提交于 2019-12-11 04:48:47
问题 I just wanna do the basics... give the shaders information from my application. I tried everything and nothing worked because I can never figure out what is new and what is deprecated in OpenGL Vertex Shader: #version 420 core layout(location = 0) in vec2 p_rect; layout(location = 1) in vec2 p_clipRect; out vec2 texturePoint; void main() { gl_Position = vec4( p_rect, 0.0, 1.0 ); texturePoint = p_clipRect; } Fragment Shader: #version 420 core uniform sampler2D p_texture; in vec2 texturePoint;

Can I load a shader into My JavaScript code from an external text file?

佐手、 提交于 2019-12-11 03:26:35
问题 I learn WebGL . I see the tutorial has the code of shaders inside of JavaScript code as a usual string. For example: var VSHADER_SOURCE = 'void main(){\n' + ' gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n' + ' gl_PointSize = 10.0;\n' + '}\n'; I want to place the code of my shaders into the external text files and load them into my JavaScript code when it necessary. How can I do it right? I don't want mix the JavaScript code and shader code in the same source code file. I looked the sample

glClipPlane - Is there an equivalent in webGL?

情到浓时终转凉″ 提交于 2019-12-11 02:16:10
问题 I have a 3D mesh. Is there any possibility to render the sectional view (clipping) like glClipPlane in OpenGL? I am using Three.js r65. The latest shader that I have added is: Fragment Shader: uniform float time; uniform vec2 resolution; varying vec2 vUv; void main( void ) { vec2 position = -1.0 + 2.0 * vUv; float red = abs( sin( position.x * position.y + time / 2.0 ) ); float green = abs( cos( position.x * position.y + time / 3.0 ) ); float blue = abs( cos( position.x * position.y + time / 4