OpenGL Shaders - Rotate a vertex using it's normal

Display name

Given the surfaceNormal (gl_NormalMatrix * gl_Normal) and a gl_Vertex how do I rotate the gl_Vertex such that it will adjust to that normal. I want to use this for billboards and general rotation.

2 Questions:

  1. How would you rotate the gl_Vertex using the surfaceNormal (In the .vert shader)?
  2. Should the rotation be done on the GPU (in the shader) or on the CPU? (Please adjust question #1 according to this question given 2 Vector3fs, one for the rotation (normal) the other for the vertex position if it should be done on the CPU)

Thanks!

Aracthor

In most of cases, the rotation should be done on the CPU, by the way of the model matrix (or directly world matrix).

Even if the CPU is slower than the GPU, keep in mind a vertex shader will have been executed for each vertex, whereas a model matrix linked to a mesh, so a lot of vertices, shall be calculated only once per frame if your mesh is dynamic, and only once of your entire program if your mesh won't move.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How not to overwrite vertex colors using shaders in OpenGL?

From Dev

Opengl triangle rotate with vertex modified

From Dev

How vertex and fragment shaders communicate in OpenGL?

From Dev

How to set the colour of a vertex in shaders with OpenGL

From Dev

Using emscripten with opengl shaders

From Dev

Display voxels using shaders in openGL

From Dev

iOS using OpenGL shaders in CIKernel

From Dev

Vertex and Fragment shaders for lighting effect in OpenGL ES20

From Dev

OpenGL-GLSL drawing 3D GL_LINES vertex shaders vs. vertex

From Dev

Adding a gradient to a bitmap font using shaders in OpenGL

From Dev

calculating vertex normal in opengl c++ ( gouraud shading)

From Dev

calculating vertex normal in opengl c++ ( gouraud shading)

From Dev

How the Vertex Shaders of OpenGL 4.X process huge number of vertices

From Dev

Trying to use shaders with Win32 OpenGL but the vertex shader doesn't draw anything

From Dev

Trying to use shaders with Win32 OpenGL but the vertex shader doesn't draw anything

From Dev

Calculating a camera's normal in OpenGL?

From Dev

OpenGL ES Shaders and 64-bit iPhone 5S

From Dev

How widely supported are Vertex Shaders?

From Dev

Android opengl es YUV to RGB conversion using shaders

From Dev

Android opengl es YUV to RGB conversion using shaders

From Dev

(Modern) OpenGL Different Colored Faces on a Cube - Using Shaders

From Dev

C# OpenGL - Trying to get the light to move with the camera using shaders

From Dev

OpenGL: Is there a benefit to using multiple global work groups for compute shaders

From Dev

webgl rotate a triangle in vertex shader without using transformation matrix

From Dev

OpenGL: Defining variables in shaders

From Dev

Shaders in WebGL vs openGL?

From Dev

OpenGL shaders not drawing a thing :/

From Dev

.HLSL file for OpenGL Shaders

From Dev

OpenGL VAO and shaders not rendering

Related Related

  1. 1

    How not to overwrite vertex colors using shaders in OpenGL?

  2. 2

    Opengl triangle rotate with vertex modified

  3. 3

    How vertex and fragment shaders communicate in OpenGL?

  4. 4

    How to set the colour of a vertex in shaders with OpenGL

  5. 5

    Using emscripten with opengl shaders

  6. 6

    Display voxels using shaders in openGL

  7. 7

    iOS using OpenGL shaders in CIKernel

  8. 8

    Vertex and Fragment shaders for lighting effect in OpenGL ES20

  9. 9

    OpenGL-GLSL drawing 3D GL_LINES vertex shaders vs. vertex

  10. 10

    Adding a gradient to a bitmap font using shaders in OpenGL

  11. 11

    calculating vertex normal in opengl c++ ( gouraud shading)

  12. 12

    calculating vertex normal in opengl c++ ( gouraud shading)

  13. 13

    How the Vertex Shaders of OpenGL 4.X process huge number of vertices

  14. 14

    Trying to use shaders with Win32 OpenGL but the vertex shader doesn't draw anything

  15. 15

    Trying to use shaders with Win32 OpenGL but the vertex shader doesn't draw anything

  16. 16

    Calculating a camera's normal in OpenGL?

  17. 17

    OpenGL ES Shaders and 64-bit iPhone 5S

  18. 18

    How widely supported are Vertex Shaders?

  19. 19

    Android opengl es YUV to RGB conversion using shaders

  20. 20

    Android opengl es YUV to RGB conversion using shaders

  21. 21

    (Modern) OpenGL Different Colored Faces on a Cube - Using Shaders

  22. 22

    C# OpenGL - Trying to get the light to move with the camera using shaders

  23. 23

    OpenGL: Is there a benefit to using multiple global work groups for compute shaders

  24. 24

    webgl rotate a triangle in vertex shader without using transformation matrix

  25. 25

    OpenGL: Defining variables in shaders

  26. 26

    Shaders in WebGL vs openGL?

  27. 27

    OpenGL shaders not drawing a thing :/

  28. 28

    .HLSL file for OpenGL Shaders

  29. 29

    OpenGL VAO and shaders not rendering

HotTag

Archive