vertex-shader

three.js webgl custom shader sharing texture with new offset

一世执手 提交于 2019-11-29 10:34:58
I am splitting a texture 1024 x 1024 over 32x32 tiles * 32, Im not sure if its possible to share the texture with an offset or would i need to create a new texture for each tile with the offset.. to create the offset i am using a uniform value = 32 * i and updating the uniform through each loop instance of creating tile, all the tiles seem to be the same offset? as basically i wanting an image to appear like its one image not broken up into little tiles.But the current out-put is the same x,y-offset on all 32 tiles..Im using the vertex-shader with three.js r71... Would i need to create a new

What is the relationship between gl_Color and gl_FrontColor in both vertex and fragment shaders

跟風遠走 提交于 2019-11-29 06:04:48
问题 I have pass-through vertex and fragment shaders. vertex shader void main(void) { gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } fragment shader void main(void) { gl_FragColor = gl_Color; } Those produce empty rendering (black not background color like glClearBuffer does). If I modify the vertex shader to set the gl_FrontColor to gl_Color it does render untouched OpenGl buffer ... with is the expected behavior of pass-through shaders. void main

glGetAttribLocation returns -1 when retrieving existing shader attribute

这一生的挚爱 提交于 2019-11-28 23:34:16
I'm trying to pass in attributes to my vertex shader but for some reason it keeps giving me a -1 on the 3rd attribute location I'm asking openGl to retrieve via glGetAttribLocation(). Currently it keeps giving me a -1 for the texCoord attribute and if I switch the texAttrib and colAttrib around (switching the lines in code) it gives me a -1 on the color property instead of the texture and I have no idea why? Since a -1 is being passed to glVertexAttribPointer I get the 1281 OpenGL error: GL_INVALID_VALUE. My vertex shader: #version 150 in vec3 position; in vec3 color; in vec2 texcoord; out

In OpenGL vertex shaders, what is w, and why do I divide by it?

六月ゝ 毕业季﹏ 提交于 2019-11-28 17:00:01
void main(void) { vec4 clipCoord = glModelViewProjectionmatrix * gl_Vertex; gl_Position = clipCoord; gl_FrontColor = gl_Color; vec3 ndc = clipCoord.xyz / clipCoord.w; So the clipCoord is just doing standard fixed pipeline transforms. Why do I divide by w , and what do I get from this? Luca W is the fourth coordinate of a three dimensional vertex; This vertex is called homogeneous vertex coordinate. In few words, the W component is a factor which divides the other vector components. When W is 1.0, the homogeneous vertex coordinates are "normalized". To compare two vertices, you should normalize

Vertex shader vs Fragment Shader [duplicate]

梦想与她 提交于 2019-11-28 15:14:24
This question already has an answer here: What are Vertex and Pixel shaders? 5 answers I've read some tutorials regarding Cg, yet one thing is not quite clear to me. What exactly is the difference between vertex and fragment shaders? And for what situations is one better suited than the other? The Surrican A fragment shader is the same as pixel shader. One main difference is that a vertex shader can manipulate the attributes of vertices. which are the corner points of your polygons. The fragment shader on the other hand takes care of how the pixels between the vertices look. They are

HLSL: Enforce Constant Register Limit at Compile Time

青春壹個敷衍的年華 提交于 2019-11-28 14:27:41
In HLSL, is there any way to limit the number of constant registers that the compiler uses? Specifically, if I have something like: float4 foobar[300]; In a vs_2_0 vertex shader, the compiler will merrily generate the effect with more than 256 constant registers. But a 2.0 vertex shader is only guaranteed to have access to 256 constant registers, so when I try to use the effect, it fails in an obscure and GPU-dependent way at runtime. I would much rather have it fail at compile time. This problem is especially annoying as the compiler itself allocates constant registers behind the scenes, on

Retrieve Vertices Data in THREE.js

試著忘記壹切 提交于 2019-11-28 07:48:16
I'm creating a mesh with a custom shader. Within the vertex shader I'm modifying the original position of the geometry vertices. Then I need to access to this new vertices position from outside the shader, how can I accomplish this? In lieu of transform feedback (which WebGL 1.0 does not support), you will have to use a passthrough fragment shader and floating-point texture (this requires loading the extension OES_texture_float ). That is the only approach to generate a vertex buffer on the GPU in WebGL. WebGL does not support pixel buffer objects either, so reading the output data back is

Can you tell if a vertex attribute is enabled from within a vertex shader?

人盡茶涼 提交于 2019-11-28 07:31:52
问题 I was wondering if there was a way to tell if a vertex attribute is enabled from within a vertex shader? I know that if the vertex attribute is disabled all the values will be treated as 0.0, so I could do a test like the following: if (attribute == 0) { // Do something different to normal. } else { // Use the attribute. } But this has the obvious problem for the case that the attribute is enabled and the value is just set to 0 (it will be treated as if it's disabled)! The other solution

glGetAttribLocation returns -1 when retrieving existing shader attribute

坚强是说给别人听的谎言 提交于 2019-11-27 21:21:38
问题 I'm trying to pass in attributes to my vertex shader but for some reason it keeps giving me a -1 on the 3rd attribute location I'm asking openGl to retrieve via glGetAttribLocation(). Currently it keeps giving me a -1 for the texCoord attribute and if I switch the texAttrib and colAttrib around (switching the lines in code) it gives me a -1 on the color property instead of the texture and I have no idea why? Since a -1 is being passed to glVertexAttribPointer I get the 1281 OpenGL error: GL

Drawing a border on a 2d polygon with a fragment shader

倖福魔咒の 提交于 2019-11-27 18:12:02
I have some simple polygons (fewer than 20 vertices) rendering flat on a simple xy plane, using GL_TRIANGLES and a flat color, a 2d simulation. I would like to add a border of variable thickness and a different color to these polygons. I have something implemented using the same vertices and glLineWidth/GL_LINE_LOOP, which works, but is another rendering pass and repeats all the vertex transforms. I think I should be able to do this in the fragment shader using gl_FragCoord and the vertex data and/or texture coordinates, but I'm not sure, and my naive attempts have been obviously incorrect. I