Skip to content

Commit

Permalink
添加assignment4
Browse files Browse the repository at this point in the history
  • Loading branch information
MuseumMage committed Jun 20, 2024
1 parent 3aff084 commit a63c813
Show file tree
Hide file tree
Showing 159 changed files with 542,065 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Assignment4/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2021 Lingqi Yan <[email protected]>, All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 changes: 22 additions & 0 deletions Assignment4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# GAMES202 homework0

## Usage

### For Visual Studio Code
Install plugin `Live Sever` and run with `index.html` directly

### For Node.js users
To install:
```
npm install http-server -g
```
To run(from `index.html` directory):
```
http-server . -p 8000
```

## In-web operation
- Hold right mouse to rotate the camera
- Scroll mouse wheel to zoom in/out
- Hold left mouse to move the camera
- Hold left mouse only to drag the GUI
99 changes: 99 additions & 0 deletions Assignment4/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
You're correct. [From the spec](https://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.25.pdf) section 2.10.4

> When an attribute variable is declared as a `mat2`, its matrix columns are taken from the `(x, y)` components of generic attributes `i` and `i + 1`. When an attribute variable is declared as a `mat3`, its matrix columns are taken from the `(x, y, z)` components of generic attributes `i` through `i + 2`. When an attribute variable is declared as a `mat4`, its matrix columns are taken from the `(x, y, z, w)` components of generic attributes `i` through `i + 3`.
stride and offsets in WebGL are in bytes so I suspect you wanted

gl.vertexAttribPointer(loc , 4, gl.FLOAT, false, 64, 0);
gl.vertexAttribPointer(loc+1, 4, gl.FLOAT, false, 64, 16);
gl.vertexAttribPointer(loc+2, 4, gl.FLOAT, false, 64, 32);
gl.vertexAttribPointer(loc+3, 4, gl.FLOAT, false, 64, 48);

Let's check

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

var vs = `
attribute mat4 matrix;
attribute vec4 color;

varying vec4 v_color;

void main() {
gl_PointSize = 10.0;
gl_Position = matrix * vec4(0, 0, 0, 1);
v_color = color;
}
`;
var fs = `
precision mediump float;

varying vec4 v_color;

void main() {
gl_FragColor = v_color;
}
`;

var m4 = twgl.m4;
var gl = document.querySelector("canvas").getContext("webgl");
var program = twgl.createProgramFromSources(gl, [vs, fs]);

var matrixLoc = gl.getAttribLocation(program, "matrix");
var colorLoc = gl.getAttribLocation(program, "color");

function r(min, max) {
if (max === undefined) {
max = min;
min = 0;
}
return Math.random() * (max - min) + min;
}

var numPoints = 100;
var matrices = [];
var colors = [];
for (var ii = 0; ii < numPoints; ++ii) {
matrices.push.apply(matrices, m4.translation([r(-1,1), r(-1,1), 0]));
colors.push(r(1), r(1), r(1), 1);
}

function makeBuffer(gl, array) {
const buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(array), gl.STATIC_DRAW);
return buf;
}

var buffers = {
matrices: makeBuffer(gl, matrices),
colors: makeBuffer(gl, colors),
};

gl.useProgram(program);

gl.bindBuffer(gl.ARRAY_BUFFER, buffers.matrices);
for (var ii = 0; ii < 4; ++ii) {
gl.enableVertexAttribArray(matrixLoc + ii);
gl.vertexAttribPointer(matrixLoc + ii, 4, gl.FLOAT, 0, 64, ii * 16);
}

gl.bindBuffer(gl.ARRAY_BUFFER, buffers.colors);
gl.enableVertexAttribArray(colorLoc);
gl.vertexAttribPointer(colorLoc, 4, gl.FLOAT, 0, 0, 0);

gl.drawArrays(gl.POINTS, 0, numPoints);

<!-- language: lang-css -->

canvas { border: 1px solid black; }

<!-- language: lang-html -->

<script src="https://twgljs.org/dist/4.x/twgl-full.js" crossorigin></script>
<canvas></canvas>

<!-- end snippet -->

Binary file added Assignment4/assets/GGX_Eavg_LUT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assignment4/assets/ball/GGX_E_LUT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assignment4/assets/ball/GGX_E_MC_LUT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assignment4/assets/ball/GGX_Eavg_LUT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions Assignment4/assets/ball/TestObj.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Blender MTL File: 'TestObj.blend'
# Material Count: 2

newmtl InnerMat
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.796 0.62 0.482
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2

newmtl OuterMat
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.796 0.62 0.482
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
Loading

0 comments on commit a63c813

Please sign in to comment.