CS计算机代考程序代写 This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License
ΔΦ
H
Computer Graphics
disco.pptx
Computer Graphics
disco.glib
#version 330 compatibility
##OpenGL GLIB
Perspective 90 LookAt001 000 010
out vec3 vECpos;
out vec4 vColor;
out float vLightIntensity;
Vertex disco.vert
Fragment disco.frag
Program Disco Program Disco \
const vec3 LIGHTPOS = vec3( 2., 0., 0. );
Color 1. 0.5 0. Teapot
vECpos = ( gl_ModelViewMatrix * gl_Vertex ).xyz;
Computer Graphics
Computer Graphics
Disco Ball Lighting!
12 LIGHTPOS
uNumFacets <5 15 50> \ uPower <1000. 5000. 50000.>
void main( ) {
Mike Bailey mjb@cs.oregonstate.edu
Δθ
BP
12
34
mjb – December 20, 2020
mjb – December 20, 2020
mjb – December 20, 2020
mjb – December 20, 2020
BALLPOS
34
disco.vert
angle
vec3 tnorm = normalize( vec3( gl_NormalMatrix * gl_Normal ) ); vLightIntensity = dot( normalize(LIGHTPOS – vECpos), tnorm ); vLightIntensity = abs( vLightIntensity );
vColor = gl_Color;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
BL
ECpos (fragment position)
12/22/2020
1

disco.frag, I
56 disco.frag, II
#version 330 compatibility
in vec3 vECpos;
in vec4 vColor;
in float vLightIntensity;
vec3 BL = normalize( LIGHTPOS – BALLPOS );
// vector from the ball center // to the light
uniform int uNumFacets;
uniform float uPower;
uniform float Timer; // built-in to glman
vec3 H = normalize( BL + bp );
// vector halfway between BL and bp – if a facet aligns with this angle, // the point we care about will get a lot of light
const float PI = 3.14159265;
const vec3 BALLPOS = vec3( 0., 2., 0. ); const vec3 LIGHTPOS = vec3( 2., 0., 0. ); const vec3 LIGHTCOLOR = vec3( 1., 1., 1. );
// turn the H vector into spherical coordinates int itheta = int( floor( ( theta + dtheta/2. ) / dtheta ) );
void
main( void ) {
float theta0 = dtheta * float(itheta); float phi0 = dphi * float(iphi);
Computer Graphics
Computer Graphics
int numTheta = uNumFacets;
int numPhi = uNumFacets;
float dtheta = 2. * PI / float(numTheta); float dphi = PI / float(numPhi);
// # in longitude direction // # in latitude direction
vec3 N0;
N0.y = sin(phi0);
xz = cos(phi0); N0.x = xz*cos(theta0); N0.z = xz*sin(theta0);
// spherical coord angles between the facets
float d = max( dot( N0, H ), 0. ); const float DMIN = 0.990;
if( d < DMIN ) // like the cone angle on a spotlight // acos(0.990) is about 8 degrees vec3 BP = normalize( vECpos – BALLPOS ); // vector from ball center to the // point we care about // ball rotation angle float angle = radians(Timer*360.); float c = cos( angle ); float s = sin( angle ); vec3 bp; d = 0.; d = pow( d, uPower ); // specular brightness bp.x = c*BP.x + s*BP.z; bp.y = BP.y; bp.z = -s*BP.x + c*BP.z; gl_FragColor = vec4( vColor.rgb*vLightIntensity + d * LIGHTCOLOR, 1. ) ; // diffuse + specular // but, rotate the vector, not the ball } 56 7 Computer Graphics mjb – December 20, 2020 mjb – December 20, 2020 mjb – December 20, 2020 7 float xz float phi float theta = atan( H.z, H.x ); = length( H.xz ); = atan( H.y, xz ); int iphi = int( floor( ( phi + dphi/2. ) / dphi ) ); // figure out what the closest facet to H is // N0 is the discrete facet normal vector 12/22/2020 2