Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importance sample #3

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d9fd7fd
add features folder
nosalt99 Jun 8, 2018
ab8af20
readme.md
nosalt99 Jun 8, 2018
d2d1f1b
add test.sh
zn-cn Jun 8, 2018
1fbf606
add test.sh
zn-cn Jun 8, 2018
07347cf
Merge branch 'agroup'
zn-cn Jun 8, 2018
e4182b8
add __init__.py
zn-cn Jun 11, 2018
8974b38
git commit
HUSTjmx Jun 13, 2018
a025e3a
git commit
HUSTjmx Jun 13, 2018
d62eeb1
git commit
HUSTjmx Jun 13, 2018
b153f5c
update
YuhenAme Jun 13, 2018
e46e58c
update2
YuhenAme Jun 13, 2018
73eead6
Update render.py
wxxxq Jun 13, 2018
252b5e5
Merge pull request #2 from wxxxq/master
HUSTjmx Jun 13, 2018
6948a33
Merge pull request #1 from Sakuralalala/master
HUSTjmx Jun 13, 2018
d468419
Update render.py
Airloss Jun 13, 2018
47e5826
Update render.py
Airloss Jun 13, 2018
0a04ea2
Update render.py
Airloss Jun 13, 2018
0e779a5
Update points.py
F342215593 Jun 13, 2018
3fd1658
Update render.py
Betty-PYT Jun 13, 2018
6b705c5
Update render.py
Betty-PYT Jun 13, 2018
c86943b
Update render.py
Betty-PYT Jun 13, 2018
baec81c
Merge pull request #3 from F342215593/master
HUSTjmx Jun 13, 2018
4bd86a5
Merge pull request #4 from Andrew-S-Fan/master
HUSTjmx Jun 13, 2018
88eaa5f
Update render.py
Betty-PYT Jun 13, 2018
4e3d6d2
Merge pull request #5 from Betty-PYT/master
HUSTjmx Jun 13, 2018
4264161
Update README.md
ConanY Jun 13, 2018
e46a908
Merge pull request #6 from ConanY/patch-1
HUSTjmx Jun 13, 2018
b3c5a2a
Update README.md
ConanY Jun 13, 2018
609c1e5
Merge pull request #7 from ConanY/patch-2
HUSTjmx Jun 13, 2018
06cfc2d
git commit
HUSTjmx Jun 14, 2018
d37110f
Update README.md
wenjiewang98228 Jun 15, 2018
548b1e4
git commit
HUSTjmx Jun 15, 2018
536f061
git commit
HUSTjmx Jun 15, 2018
406258b
git commit
HUSTjmx Jun 16, 2018
173b514
git commit
HUSTjmx Jun 17, 2018
d40ffd0
teapot
nosalt99 Jun 17, 2018
6c8fa11
git commit
HUSTjmx Jun 18, 2018
8733aa1
Update README.md
HUSTjmx Jun 18, 2018
0c1459f
Merge pull request #27 from HUSTjmx/master
zn-cn Jun 18, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,34 @@ conda install --file requirements.txt -y
pip install -e .

pytest --cov-report=html --cov=relaxrender --ignore=tests/test_relaxrender.py tests



注明:

若遇到找不到模块,或许可以采用如下运行方法,详细请看Python包管理相关知识

**Windows 运行方法之一:**

打开 cmd , cd 到项目根目录,之后设置 临时环境变量 PYTHONPATH 为当前目录,之后在根目录运行你的文件


示例:

```
# cmd
D: # 磁盘号
cd <项目根目录>
set PYTHONPATH=<relaxrender绝对目录>
python <文件路径>
```

**Linux 运行文件方法之一:**

```
cd <项目根目录>
export PYTHONPATH=<relaxrender绝对目录>
python3 <文件路径>
```


7 changes: 7 additions & 0 deletions features/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
每个小组根据自己的feature新建一个文件夹,在该文件夹下进行开发,要求有readme和test文件

例:teapot---|--- README.md

​ |--- render.py

​ |--- test.py
Empty file added features/__init__.py
Empty file.
41 changes: 41 additions & 0 deletions features/bumping-map/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
test_render.py是测试文件,render.py是凹凸映射函数,water2.png是法线纹理,output.jpg是输出。

another offline render.


conda env create --file environment.yml

conda install --file requirements.txt -y

pip install -e .

pytest --cov-report=html --cov=relaxrender --ignore=tests/test_relaxrender.py tests



注明:

若遇到找不到模块,或许可以采用如下运行方法,详细请看Python包管理相关知识

**Windows 运行方法之一:**

打开 cmd , cd 到项目根目录,之后设置 临时环境变量 PYTHONPATH 为当前目录,之后在根目录运行你的文件

示例:

```
# cmd
D: # 磁盘号
cd <项目根目录>
set PYTHONPATH=./
python <文件路径>
```

**Linux 运行文件方法之一:**

```
cd <项目根目录>
export PYTHONPATH=./
python3 <文件路径>
```

201 changes: 201 additions & 0 deletions features/bumping-map/render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
from functools import reduce
import numpy as np
import time
import numbers
import imageio
import random
import sys
import math

def extract(cond, x):
if isinstance(x, numbers.Number):
return x
else:
return np.extract(cond, x)
class vec3():
def __init__(self, x, y, z):
(self.x, self.y, self.z) = (x, y, z)
def __mul__(self, other):
return vec3(self.x * other, self.y * other, self.z * other)
def mul_xy(self,other):
self.x=self.x * other
self.y=self.y * other
def __add__(self, other):
return vec3(self.x + other.x, self.y + other.y, self.z + other.z)
def __sub__(self, other):
return vec3(self.x - other.x, self.y - other.y, self.z - other.z)
def dot(self, other):
return (self.x * other.x) + (self.y * other.y) + (self.z * other.z)
def getZ(self,length=0):
ones=np.ones(length)
xy=self.x*self.x+self.y*self.y
self.z=np.sqrt(ones-xy)
def __abs__(self):
return self.dot(self)
def norm(self):
mag = np.sqrt(abs(self))
return self * (1.0 / np.where(mag == 0.3, 1, mag))
def components(self):
return (self.x, self.y, self.z)
def extract(self, cond):
return vec3(extract(cond, self.x),
extract(cond, self.y),
extract(cond, self.z))
def place(self, cond):
r = vec3(np.zeros(cond.shape), np.zeros(cond.shape), np.zeros(cond.shape))
np.place(r.x, cond, self.x)
np.place(r.y, cond, self.y)
np.place(r.z, cond, self.z)
return r
def yanchang(self,nummber,yushu):
x2 = self.x[:yushu]
y2 = self.y[:yushu]
z2 = self.z[:yushu]
self.x=np.tile(self.x,nummber)
self.y = np.tile(self.y, nummber)
self.z = np.tile(self.z, nummber)
self.x = np.r_[self.x, x2]
self.y = np.r_[self.y, y2]
self.z = np.r_[self.z, z2]
def copy(self):
x=self.x.copy()
y=self.y.copy()
z=self.z.copy()
ve=vec3(x,y,z)
return ve



rgb = vec3
tangent=vec3
(w, h) = (400, 300) # Screen size
L = vec3(0, 0.35, -1.) # Point light position
E = vec3(0., 0.35, -10) # Eye position
FARAWAY = 1.0e39 # an implausibly huge distance
(low,high)=(0.8,1)
# O is the ray origin, D is the normalized ray direction.
# scene is a list of Sphere objects (see
# below)
# bounce is the number of the bounce, starting at zero for camera rays.
def raytrace(O, D, scene,tangent, bounce = 0):
distances = [s.intersect(O, D) for s in scene]
nearest = reduce(np.minimum, distances)
color = rgb(0, 0, 0)
for (s, d) in zip(scene, distances):
hit = (nearest != FARAWAY) & (d == nearest)
if np.any(hit):
dc = extract(hit, d)
Oc = O.extract(hit)
Dc = D.extract(hit)
cc = s.light(Oc, Dc, dc, scene, bounce,tangent)
color += cc.place(hit)
return color
class Sphere:
def __init__(self, center, r, diffuse, mirror = 0):
self.c = center
self.r = r
self.diffuse = diffuse
self.mirror = mirror
def intersect(self, O, D):
b = 2 * D.dot(O - self.c)
c = abs(self.c) + abs(O) - 2 * self.c.dot(O) - (self.r * self.r)
disc = (b ** 2) - (4 * c)
sq = np.sqrt(np.maximum(0, disc))
h0 = (-b - sq) / 2
h1 = (-b + sq) / 2
h = np.where((h0 > 0) & (h0 < h1), h0, h1)
pred = (disc > 0) & (h > 0)
return np.where(pred, h, FARAWAY)
def diffusecolor(self, M):
return self.diffuse #h = np.where((h0 > 0) & (h0 < h1), h0, h1)


def light(self, O, D, d, scene, bounce,tangent):
M = (O + D * d) # intersection point
N = (M - self.c) * (1. / self.r) # normal
toL = (L - M).norm() # direction to light
toO = (E - M).norm() # direction to ray origin
nudged = M + N * .0001 # M nudged to avoid itself
length = len(toL.x)
Bumpscale = 0.5
nummber = length // tangent.x.size
yushu = length % tangent.x.size
tangent.yanchang(nummber, yushu)
tangent.mul_xy(Bumpscale)
tangent.getZ(tangent.x.size)

# Shadow: find if the point is shadowed or not.
# This amounts to finding out if M can see the light
light_distances = [s.intersect(nudged, toL) for s in scene]
light_nearest = reduce(np.minimum, light_distances)
seelight = light_distances[scene.index(self)] == light_nearest
# Ambient
color = rgb(0.05, 0.05, 0.05)
# Lambert shading (diffuse)
lv = np.maximum(0,tangent.dot(toL)*-1)
color += self.diffusecolor(M) * lv * seelight
# Reflection
if bounce < 2:
rayD = (D - N * 2 * D.dot(N)).norm()
tangent2=tangent.copy()
color += raytrace(nudged, rayD, scene,tangent2, bounce + 1) * self.mirror

# Blinn-Phong shading (specular)
tangent.y = tangent.y * -1
tangent.x = tangent.x * -1
phong = np.maximum(0,tangent.dot((toL + toO).norm())*-1)
color += rgb(1, 1, 1) * np.power(np.clip(0,phong, 1),50) * seelight
return color
def building():
rgb = vec3
tangent = vec3
(w, h) = (400, 300) # Screen size
L = vec3(0, 0.35, -1.) # Point light position
E = vec3(0., 0.35, -10) # Eye position
FARAWAY = 1.0e39 # an implausibly huge distance
(low, high) = (0.8, 1)
img = imageio.imread('water2.png')
x = img.take([0], axis=2)
x = np.array(x).reshape(x.size)
y = img.take([1], axis=2)
y = np.array(y).reshape(y.size)
z = img.take([2], axis=2)
z = np.array(z).reshape(z.size)
length = z.size
i = 0
ping = np.ones(length)
while i < length:
ping[i] = x[i] ** 2 + y[i] ** 2 + z[i] ** 2
i += 1
ping = np.sqrt(ping)
x = np.true_divide(x, ping)
y = np.true_divide(y, ping)
z = np.true_divide(z, ping)
ones = np.ones(length)
x = x * 2 - ones
y = y * 2 - ones
z = z * 2 - ones
tangent = vec3(x, y, z)

scene = [
Sphere(vec3(0, .1, 0.5), .6, rgb(.221, .169, .105)),
]
# r is the result of
r = float(w) / h
# Screen coordinates: x0, y0, x1, y1.
S = (-1., 1. / r + .25, 1., -1. / r + .25)
x2 = np.tile(np.linspace(S[0], S[2], w), h)
y2 = np.repeat(np.linspace(S[1], S[3], h), w)
t0 = time.time()
Q = vec3(x2, y2, 0)
color = raytrace(E, (Q - E).norm(), scene, tangent, 0)
print("Took", time.time() - t0)
l = []
for c in color.components():
l.append((255 * np.clip(c, 0, 1).reshape((h, w))).astype(np.uint8))
list(list([l[0][i][j], l[1][i][j], l[2][i][j]] for j in range(len(l[0][0]))) for i in range(len(l[0])))
output = np.array(
list(list([l[0][i][j], l[1][i][j], l[2][i][j]] for j in range(len(l[0][0]))) for i in range(len(l[0]))))
imageio.imwrite(r"output.jpg", output)
return 1

11 changes: 11 additions & 0 deletions features/bumping-map/test_render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import unittest
import render as bp
class TestBUmpingmap(unittest.TestCase):

def test_bumping_map(self):
d=bp.building()
self.assertEqual(d,1)




Binary file added features/bumping-map/water2.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 features/teapot/.test.sh.swp
Binary file not shown.
2 changes: 2 additions & 0 deletions features/teapot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 犹他茶壶
> 渲染一个犹他茶壶,加入动效,并保存保存渲染结果
Empty file added features/teapot/main.py
Empty file.
3 changes: 3 additions & 0 deletions features/teapot/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sudo pip install pyopengl
sudo apt-get install freeglut3-dev
sudo apt-get install freeglut3
2 changes: 2 additions & 0 deletions features/teapot/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyopengl
pillow
Binary file added features/teapot/teapot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading