Tag Info

Hot answers tagged

6

How are you passing your normals to the vertex shader? It looks like those are the normals for each of the six faces of a cube, but the vertex shader operates on vertices, not faces. Unless you're doing something unusual, you need to specify a normal for each vertex. In addition, if you want a cube to look right, you will need 24 vertices rather than 8, so ...


4

Absolutely, But not as simple as taking a return value of a normal function. First I assume your question isn't about sharing variables between two shader stages (vertex, fragment..etc) but actually between two shader (programs). Shaders are part of the rendering pipeline, every input/output should pass through the rendering pipeline and its memory is ...


2

What you essentially want is the depth in camera coordinates, but relative to model, not camera. the easiest way to achieve that is to calculate the position of the origin of a model coordinate system in camera coordinates. ... vec4 cs_position = glModelViewMatrix * gl_Vertex; vec4 origin_position = glModelViewMatrix * vec4(0,0,0,1); distToOrigin = ...


2

You can explicitly get those numbers from id = glGetAttribLocation(program, name); after linking; the name is the string that appears in the vertex shader for the attribute. For example if you passed "vertexPosition" for name then you would get 0. If the layout information is not in the shader then openGL will create a default layout (usually in order as ...


2

In DirectX this is called the input signature. In older version of DX (DX9) you could skip to plug a stream-source, and then all unplugged things in the shader would default to zero value. (zero value filled from void by the pipeline). I would suppose OpenGL also does this kind of things. Note the newer versions of the graphics libraries (DX10+) do not ...


1

Your shader, vertex structure, and glVertexAttribPointer calls do not agree. This tends to cause unusual behavior because you're mapping unexpected values to the GPU pipeline. Your vertex structure says you have a 3-vector for position, a 2-vector for for texture coordinates, and a 3-vector for the normal (a total of eight floats per vertex). Your ...


1

There are two issues in the C# version, compared to the C++ version. When fixed, the project runs as expected. The C++ version is using glutInitContextProfile(GLUT_CORE_PROFILE); while the C# version is not. You can fix that by changing the Game constructor to: public Game() : base(800, 600, GraphicsMode.Default, "Example", ...


1

calculate a bounding volume of the object (sphere, convex hull, box - depends on your speed/accuracy needs), this needs to be done only once - at initalization while rendering, for each object: transform camera (origin, direction) to object space project bounding volume on camera direction axis and subtract camera origin projection to retrieve min/max ...


1

I agree with what v.oddou said. An extra point, changing the number of inputs of the shader can be thought of as changing an interface of a function, they are not strictly the same but the concept applies. So expect by default a recompile for your shaders to add more input streams, you also need to modify your code to pass those streams. You can use #define ...



Only top voted, non community-wiki answers of a minimum length are eligible