这是一个美国的Shader集合着色器相关的作业代写

Introduction:

If you’ve seen one of the Lego movies, you now how great they are! It would be fun to emulate
something about one of them. We could write a geometry shader to quantize geometry in
Cartesian coordinates to make a “Lego Look”, but anyone can do that! Let’s do ours in spherical
coordinates. I call these SphereGo Bricks. 🙂

The word “quantize” means to take something that is continuous, and give it discrete (fixed)
locations instead. So, in the normal lego sense, we could create that look by forcing all x-y-z
coordinates to assume certain values only, thus turning them into blocks.

Requirements:

1. Your input should be something with triangles, e.g., the teapot, the torus, an OBJ file, etc.

2. Have a uLevel slider that controls the number of levels of triangle subdivision.

3. Have a uQuantize variable that controls the quantization equation (see below).

4. Have have some way to turn a boolean variable, uRadiusOnly on and off. This variable allows
you to quantize just in radius. Turning this off will perform quantization in radius, theta, and
phi.

5. Do some sort of lighting. The quick-and-dirty-diffuse is fine. Per-fragment would be even
better.

Hints

Your GLIB file could look something like this:

OpenGL GLIB
Perspective 70
LookAt 0 0 3 0 0 0 0 1 0

Vertex sphlego.vert
Geometry sphlego.geom
Fragment sphlego.frag
Program SphLego \
uRadiusOnly <true> \
uLevel <0 3 3> \
uQuantize <1. 50. 50.> \
uColor { 1.00 0.65 0.40 }

Obj tigerstsL.obj

Pass a vNormal from the vertex shader to the geometry shader.

out vec3 vNormal;
. . .
in vec3 vNormal[3];

The geometry shader layouts will look like this:

layout( triangles ) in;
layout( triangle_strip, max_vertices=204 ) out;

The geometry shader must set gl_Position and all out variables before each call to EmitVertex().

If you are doing a quick-and-dirty diffuse lighting, pass a gLightIntensity from the geometry
shader to the rasterizer to the fragment shader.

out float gLightIntensity;
. . .
in float gLightIntensity;

If you are using the better per-fragment lighting, pass a gNs, gEs, gLs from the geometry
shader to the rasterizer to the fragment shader.

out vec3 gNs, gEs, gLs;
. . .
in vec3 gNs, gEs, gLs;

Use uLevel to subdivide the triangle into smaller triangles. Use the s and t interpolation
scheme from our class notes:

vec3 v = V0 + s*V01 + t*V02;

where we created new (x,y,z)’s to form triangle strips. You can use the code from the Sphere
Subdivision geometry shader as a start.

Use the same equation to also create new (nx,ny,nz)’s: