Einführung in die Computergrafik und Bildverarbeitung

Wintersemester 2021/22

22. Dezember 2021 - GLSL Shaders in PyOpenGL

  • GLSL in Python verwenden
  • Fragestunde zur Studienleistung 2

Tutorial

Download simple_shaders.py from GRIPS and try to get it running

Then complete the following tasks:

  • change the code so that the fragment shader reacts to mouse clicks
  • animate the square's position
  • drag the square around using the mouse
  • make the square rotate in 3D space (you need matrix multiplication in your shader (see here)
  • apply simple shading in the fragment shader (see link above)
  • advanced: implement a blur fragment shader (you need to render to a buffer first - see multipass example here

Fragment Shaders

  • werden einmal pro Pixel im Bild aufgerufen, geben Farbwert zurück
  • Eingabeparameter: Bildposition (vec2 fragCoord)
  • Ausgabewert: Pixelfarbe (vec4 fragColor, RGBA)
  • Zeichnen in 2D: Kreis
  • Blur-Filter (nicht Gaussscher Weichzeichner, nicht effizient): https://www.shadertoy.com/view/Xltfzj

Vertex Shaders

  • werden einmal pro Vertex aufgerufen
  • Eingabeparameter: Vertex-Koordinaten (vec3)
  • Ausgabewert: Vertex-Koordinaten, indem globale Variable glPosition gesetzt wird.
  • nicht direkt von ShaderToy unterstützt

Beispiele Shading

Ausblick 11. Januar 2022 (online)

  • Wrap-Up 3D
  • Intro Computer Vision / OpenCV