vertex-shader

GLSL integration function

可紊 提交于 2019-12-07 06:36:24
问题 Any recommendation on how to implement efficient integral functions, like SumX and SumY, in GLSL shaders? SumX(u) = Integration with respect to x = I(u0,y) + I(u1,y) +... + I(uN,y); u=normalized x coordinate SumY(v) = Integration with respect to y = I(x,v0) + I(x,v1) +... + I(x,vN); v=normalized y coordinate For instance the 5th pixel of the first line would be the sum of all five pixels on the first line. And the last pixel would be the sum of all previous pixels including the last pixel

How vertex and fragment shaders communicate in OpenGL?

被刻印的时光 ゝ 提交于 2019-12-06 12:35:40
I really do not understand how fragment shader works. I know that vertex shader runs once per vertices fragment shader runs once per fragment Since fragment shader does not work per vertex but per fragment how can it send data to the fragment shader? The amount of vertices and amount of fragments are not equal. How can it decide which fragment belong to which vertex? To make sense of this, you'll need to consider the whole render pipeline. The outputs of the vertex shader (besides the special output gl_Position ) is passed along as "associated data" of the vertex to the next stages in the

Three.js - a vertex shader to color based on location of pixel on screen

こ雲淡風輕ζ 提交于 2019-12-06 09:14:13
问题 Using Three.js, I have written a vertex shader that colors each point in a plane according to which quadrant of the screen a pixel is rendered. // vertex shader uniform float width; uniform float height; varying float x; varying float y; void main() { vec4 v = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); x = v.x; y = v.y; gl_Position = v; } // fragment shader varying float x; varying float y; void main() { gl_FragColor = vec4(x, y, 0.0, 1.0); } Live example at jsFiddle: http:/

How fragment shader determines the number of fragments from vertex shader output?

你说的曾经没有我的故事 提交于 2019-12-06 06:07:22
问题 I'm familiar with vertex and fragment shaders but still confused about how a fragment shader determines the amount of fragments from the output of vertex shader. If I have 3 vertices and I draw a triangle primitive in GLSL, then vertex shader will run three times for every vertex and then fragment shader will run many times (depending upon the number of fragments, once for each fragment). I want to know how fragment shader determines the fragments? Does it use gl_Position? If I don't set gl

Generic picking solution for 3D scenes with vertex-shader-based geometry deformation applied

老子叫甜甜 提交于 2019-12-05 16:34:34
I'm trying to implement a navigation technique for 3D scenes (in OpenSceneGraph with OpenGL). Among other things the user should be able to click on an scene object on the screen to move towards it. The navigation technique should be integrated into another project which uses a vertex shader to apply a global deformation to the scene geometry. And here is the problem: Since the geometry is deformed using a vertex shader, it is not straight forward to un-project the mouse cursor position to the world coordinates of the spot the user actually selected. But I need those coordinates to perform the

OpenGL - Fixed pipeline shader defaults (Mimic fixed pipeline with shaders)

不羁的心 提交于 2019-12-05 14:34:35
Can anyone provide me the shader that are similar to the Fixed function Pipeline? I need the Fragment shader default the most, because I found a similar vertex shader online. But if you have a pair that should be fine! I want to use fixed pipeline, but have the flexability of shaders, so I need similar shaders so I'll be able to mimic the functionality of the fixed pipeline. Thank you very much! I'm new here so if you need more information tell me:D This is what I would like to replicate: (texture unit 0) functionality of glTranslatef functionality of glColor4f functionality of glTexCoord2f

Vertex shader with array inputs

倾然丶 夕夏残阳落幕 提交于 2019-12-05 13:40:06
Given a vertex shader that looks something like #version 400 compatibility const int max_valence = 6; in int valence; in vec3 patch_data[1 + 2 * max_valence]; ... What is the the proper way to map the data to the correct vertex attribs? I'm trying to use a VBO, but I can't figure out how to pass that large of a value in. glVertexAttribPointer takes at most a vector of size 4. What's the correct way to get the vertex attributes into the shader? Arrays of vertex attributes are legal in OpenGL. However, each member of the array takes up a separate attribute index. They are allocated contiguously,

for-loop in shader code working with hardcoded number but not with uniform variable

[亡魂溺海] 提交于 2019-12-05 13:17:38
I asked for help about an OpenGL ES 2.0 Problem in this question . What seems to be the answer is very odd to me. Therefore I decided to ask this question in hope of being able to understand what is going on. Here is the piece of faulty vertex-shader code: // a bunch of uniforms and stuff... uniform int u_lights_active; void main() { // some code... for ( int i = 0; i < u_lights_active; ++i ) { // do some stuff using u_lights_active } // some other code... } I know this looks odd but this is really all code that is needed to explain the problem / faulty behavior. My question is: Why is the

OpenGLES 2.0: gl_VertexID equivalent?

放肆的年华 提交于 2019-12-05 08:16:18
I'm trying to create a grid of points by calculating vertex positions dynamically, based on their index in the array of vertices sent to the shader. Is there an equivalent of the gl_VertexID variable that I can call from within my shader? Or another way of accessing their position in the array without having to send more data to the GPU? Thank, Josh. Here's my vertex shader: attribute vec4 vertexPosition; uniform mat4 modelViewProjectionMatrix; vec4 temp; uniform float width; void main() { temp = vertexPosition; // Calculate x and y values based on index: temp.y = floor(gl_VertexID/width);

How can I feed compute shader results into vertex shader w/o using a vertex buffer?

霸气de小男生 提交于 2019-12-05 02:43:28
问题 Before I go into details I want outline the problem: I use RWStructuredBuffers to store the output of my compute shaders (CS). Since vertex and pixel shaders can’t read from RWStructuredBuffers, I map a StructuredBuffer onto the same slot (u0/t0) and (u4/t4): cbuffer cbWorld : register (b1) { float4x4 worldViewProj; int dummy; } struct VS_IN { float4 pos : POSITION; float4 col : COLOR; }; struct PS_IN { float4 pos : SV_POSITION; float4 col : COLOR; }; RWStructuredBuffer<float4>