How to do it...

To create a shader program that applies the Sobel edge detection filter, perform the following steps:

  1. The vertex shader just converts the position and normal to camera coordinates and passes them along to the fragment shader.
  1. The fragment shader applies the reflection model in the first pass, and applies the edge detection filter in the second pass:
in vec3 Position; 
in vec3 Normal; uniform int Pass; // Pass number // The texture containing the results of the first pass layout( binding=0 ) uniform sampler2D RenderTex; uniform float EdgeThreshold; // The squared threshold // Light/material uniforms... layout( location = 0 ) out vec4 FragColor; const vec3 lum = vec3(0.2126, 0.7152, 0.0722); vec3 blinnPhong( vec3 pos, vec3 ...

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.