From 73cd27d0c658b43b268cb782b3e3831d2b615cc6 Mon Sep 17 00:00:00 2001 From: Udit Chandra <83822686+udit-uc828@users.noreply.github.com> Date: Tue, 28 Sep 2021 00:38:09 +0530 Subject: [PATCH 01/11] Update with Cython Code --- RenderLib/RenderLib.py | 381 ++++++++++++++++++++++++----------------- 1 file changed, 221 insertions(+), 160 deletions(-) diff --git a/RenderLib/RenderLib.py b/RenderLib/RenderLib.py index e7ac031..aa6b8db 100644 --- a/RenderLib/RenderLib.py +++ b/RenderLib/RenderLib.py @@ -2,8 +2,9 @@ from math import sin,cos,tan,pi,radians #vectors -class Vec: - def __init__(self, i=0,j=0,k=0): +cdef class Vec: + cdef public double i,j,k + def __init__(self, double i=0, double j=0, double k=0): self.i = i self.j = j self.k = k @@ -14,9 +15,9 @@ def __repr__(self): def __neg__(self): return Vec(-self.i,-self.j,-self.k) - def __add__(self, v): + def __add__(self, Vec v): return Vec((self.i + v.i), (self.j + v.j), (self.k + v.k)) - def __sub__(self, v): + def __sub__(self, Vec v): return Vec((self.i - v.i), (self.j - v.j), (self.k - v.k)) def __mul__(self, scl): @@ -24,69 +25,83 @@ def __mul__(self, scl): return Vec((self.i *scl.i), (self.j *scl.j), (self.k *scl.k)) return Vec((self.i *scl), (self.j *scl), (self.k *scl)) - def __truediv__(self,scl): + def __truediv__(self, double scl): invscl = 1/scl return Vec((self.i*invscl), (self.j*invscl), (self.k*invscl)) - def __eq__(self, v): + def __eq__(self, Vec v): if (self.i == v.i) and (self.j==v.j) and (self.k==v.k): return True - else: - return False + return False - def mag(self): + cpdef double mag(self): return (self.dot(self))**.5 - def magsq(self): + cpdef double magsq(self): return self.dot(self) - def normalize(self): + + cpdef Vec normalize(self): return self/(self.mag()) - def dot(self, v): + + cpdef double dot(self, Vec v): return ((self.i * v.i)+(self.j*v.j)+(self.k*v.k)) - def cross(self, v): + cpdef Vec cross(self, Vec v): return Vec((self.j*v.k - self.k*v.j), (self.k*v.i - self.i*v.k), (self.i*v.j - self.j*v.i)) #___Color___ -class Color: - def __init__(self, r=0,g=0,b=0): +cdef class Color: + cdef public double r,g,b + + def __init__(self,double r=0, double g=0, double b=0): self.r = r self.g = g self.b = b def __repr__(self): return f"{self.r} {self.g} {self.b}" - def __add__(self, c): + def __add__(self, Color c): return Color((self.r + c.r), (self.g + c.g), (self.b + c.b)) - def __iadd__(self, c): - return Color((self.r + c.r), (self.g + c.g), (self.b + c.b)) + def __iadd__(self, Color c): + return self+c def __mul__(self, scl): if type(scl) == Color: return Color((self.r *scl.r), (self.g *scl.g), (self.b *scl.b)) else: return Color((self.r *scl) , (self.g *scl), (self.b *scl)) - def __truediv__(self, scl): - return self*(1/scl) + def __truediv__(self, double scl): + return self/scl - def __eq__(self, c): + def __eq__(self, Color c): if ((self.r == c.r) and (self.g==c.g) and (self.b==c.b)): return True return False - def quantize(self,bpc=8,clip=False): - qv = 2**bpc -1 - gam = .45 + + cpdef list quantize(self,int bpc=8, int clip=0): + cdef int qv = 2**bpc -1 + cdef double gam = .45 + cdef double rh,gh,bh + rh,gh,bh = self.r, self.g, self.b + if clip: - if self.r>=1 or self.g>=1 or self.b>=1: + if rh>=1 or gh>=1 or bh>=1: return [0,0,255] - - r,g,b= ((min(int((self.r**gam)*qv),qv)), - (min(int((self.g**gam)*qv),qv)), - (min(int((self.b**gam)*qv),qv)) ) - return [r,g,b] + + rh = (rh**gam)*qv + gh = (gh**gam)*qv + bh = (bh**gam)*qv + + return [min(rh,qv), + min(gh,qv), + min(bh,qv) ] + #__Material__ -class Material: - def __init__(self,color=Color(),rough=0,spec=0): +cdef class Material: + cdef public Color color + cdef public double rough,spec + + def __init__(self,Color color=Color(), double rough=0, double spec=0): self.color = color self.rough = rough self.spec = spec @@ -94,40 +109,44 @@ def __init__(self,color=Color(),rough=0,spec=0): #__Geometry__ -class Triangle: - def __init__(self,a,b,c): +cdef class Triangle: + cdef public Vec a,b,c,BA,CA + cdef public Material mat + + def __init__(self, Vec a, Vec b, Vec c): self.a, self.b, self.c = a,b,c - self.color = Color(1,1,1) - self.mat = Material() + self.BA,self.CA = (b-a),(c-a) + self.mat = Material(color=Color()) - def normal(self): - return ((self.b-self.a).cross(self.c-self.a)) - def center(self): - return Vec( - (self.a.i+self.b.i+self.c.i)*.33, - (self.a.j+self.b.j+self.c.j)*.33, - (self.a.k+self.b.k+self.c.k)*.33) + cpdef Vec normal(self): + return (self.BA.cross(self.CA)) + cpdef Vec center(self): + return (self.a+self.b+self.c)*.33 -class Mesh: - def __init__(self,fcs): - self.name = "" +cdef class Mesh: + cdef public list triangles,Rotation,Scale,PreTranslate,Translate + cdef public Material mat + + def __init__(self,list fcs): self.triangles = fcs self.mat = Material(Color(1,1,1)) self.Rotation = [0,0,0] - self.Scale = [1,1,1] + self.Scale = [1,1,1] + self.PreTranslate = [0,0,0] self.Translate = [0,0,5] @staticmethod def LoadMesh(path,norm=1): - verts = [] - tris = [] - ctr = 0 + cdef list verts,tris + verts,tris = [],[] + cdef int ctr = 0 + with open(path, "r") as file: Lines = file.readlines() file.close() - + for Line in Lines: if Line.startswith("v "): a,b,c = list(map(float,(Line[2::]).split())) @@ -166,37 +185,52 @@ def LoadMesh(path,norm=1): #__Camera_Scene_&_Lights__ -class Camera: +cdef class Camera: + cdef public double fov + cdef public int typ + cdef public Vec loc + def __init__(self, loc, fov): self.loc = loc self.fov = fov self.typ = 1 -class Scene: - def __init__(self,objs,lt,cam,w,h): +cdef class Scene: + cdef public list Objects,Lights,Size,VertColor,EdgeColor + cdef public Camera camera + cdef public int W,H,HDRClip,Lighting + cdef public double Scale,NearPoint,FarPoint + cdef public str DrwMode + + def __init__(self,list objs, list lt, Camera cam, int w, int h): self.Objects = objs self.Lights = lt self.camera = cam self.W, self.H = w,h - self.Size = (self.W,self.H) + self.Size = [self.W,self.H] self.Scale = 100 self.NearPoint = .1 self.FarPoint = 1e4 - self.Lighting = True + self.Lighting = 1 self.DrwMode = "RENDER" - self.VertColor = (0,120,255) - self.EdgeColor = (250,240,240) + self.VertColor = [0,120,255] + self.EdgeColor = [250,240,240] - self.HDRClip = False + self.HDRClip = 0 + +cdef class Light: + cdef public Vec loc,dirx + cdef public Color color + cdef public str typ + cdef public double power -class Light: - def __init__(self, loc, power, dirx=Vec(0,0,1), typ="DIRX"): + def __init__(self,Vec loc, double power,Vec dirx=Vec(0,0,1),str typ="DIRX"): self.loc = loc self.power = power self.typ = typ @@ -205,40 +239,43 @@ def __init__(self, loc, power, dirx=Vec(0,0,1), typ="DIRX"): #___FUNCTIONS___ -def PersMatrixGen(fov, AsR, zN, zF): +cdef list PersMatrixGen(fov, AsR, zN, zF): fov /= 2 - f = round(1/tan(radians(fov)),8) - q = round(zF/(zF-zN),8) - return (AsR*f,f,q,zN*q) + f = 1/tan(radians(fov)) + q = zF/(zF-zN) + return [AsR*f,f,q,zN*q] -def RotMatrixGen(AnTup): +cdef list RotMatrixGen(AnTup): a1,a2,a3 = map(radians,AnTup) - return (Vec((cos(a2)*cos(a3)),(cos(a2)*sin(a3)),(-sin(a2))), - Vec((sin(a1)*sin(a2)*cos(a3) - cos(a1)*sin(a3)),(sin(a1)*sin(a2)*sin(a3)+cos(a1)*cos(a3)),(sin(a1)*cos(a2))), - Vec((cos(a1)*sin(a2)*cos(a3) - sin(a1)*sin(a3)),(cos(a1)*sin(a2)*sin(a3)-sin(a1)*cos(a3)),(cos(a1)*cos(a2)))) + return [Vec((cos(a2)*cos(a3)),(cos(a2)*sin(a3)),(-sin(a2))), + Vec((sin(a1)*sin(a2)*cos(a3) - cos(a1)*sin(a3)),(sin(a1)*sin(a2)*sin(a3)+cos(a1)*cos(a3)),(sin(a1)*cos(a2))), + Vec((cos(a1)*sin(a2)*cos(a3) - sin(a1)*sin(a3)),(cos(a1)*sin(a2)*sin(a3)-sin(a1)*cos(a3)),(cos(a1)*cos(a2)))] -def Transform(O,Anim,NrmOp,cmra): - RotATup = O.Rotation - RotATup[0] += Anim[0] - RotATup[1] += Anim[1] - RotATup[2] += Anim[2] - - sx,sy,sz = O.Scale +cdef dict Transform(Mesh O, int NrmOp, Camera cmra): + + cdef Triangle T,FinalTris + cdef Vec a,b,c, r1,r2,r3,rVec + cdef double sx,sy,sz, rtx,rty,rtz + + sx,sy,sz = O.Scale + rtx,rty,rtz = O.PreTranslate tx,ty,tz = O.Translate - r1,r2,r3 = RotMatrixGen(RotATup) - LocTrisDic = {} - mt = O.mat + r1,r2,r3 = RotMatrixGen(O.Rotation) + cdef Vec PreTr = Vec(rtx,rty,rtz) + + cdef dict LocTrisDic = {} + cdef Material mt = O.mat for T in O.triangles: #_Transformation - a,b,c = T.a,T.b,T.c + a,b,c = T.a+PreTr, T.b+PreTr, T.c+PreTr FinalTris = Triangle( - (Vec(r1.dot(a)*sx+tx,r2.dot(a)*sy+ty,r3.dot(a)*sz+tz) ), - (Vec(r1.dot(b)*sx+tx,r2.dot(b)*sy+ty,r3.dot(b)*sz+tz) ), - (Vec(r1.dot(c)*sx+tx,r2.dot(c)*sy+ty,r3.dot(c)*sz+tz) )) - + Vec(r1.dot(a)*sx+tx,r2.dot(a)*sy+ty,r3.dot(a)*sz+tz), + Vec(r1.dot(b)*sx+tx,r2.dot(b)*sy+ty,r3.dot(b)*sz+tz), + Vec(r1.dot(c)*sx+tx,r2.dot(c)*sy+ty,r3.dot(c)*sz+tz)) + #_Apply_Colors FinalTris.mat = mt @@ -254,54 +291,70 @@ def Transform(O,Anim,NrmOp,cmra): -def Project(PM,tr,cx,cy,Scl,Typ): - p1,p2,p3 = tr.a, tr.b, tr.c +cdef list Project(list PM, Triangle tr, int cx, int cy, double Scl, int Typ): + cdef double p1x,p2x,p3x + cdef double p1y,p2y,p3y + cdef double p1z,p2z,p3z + cdef double z1,z2,z3 + cdef double Px1,Px2,Px3,Py1,Py2,Py3,Pz1,Pz2,Pz3 + + p1x,p1y,p1z = tr.a.i, tr.a.j, tr.a.k + p2x,p2y,p2z = tr.b.i, tr.b.j, tr.b.k + p3x,p3y,p3z = tr.c.i, tr.c.j, tr.c.k if Typ: - Px1,Py1,Pz1 = (PM[0]*p1.i, - PM[1]*p1.j, - PM[2]*p1.k - PM[3]) - Px2,Py2,Pz2 = (PM[0]*p2.i, - PM[1]*p2.j, - PM[2]*p2.k - PM[3]) - Px3,Py3,Pz3 = (PM[0]*p3.i, - PM[1]*p3.j, - PM[2]*p3.k - PM[3]) - - if p1.k: - z1 = 1/p1.k + Px1,Py1,Pz1 = (PM[0]*p1x, + PM[1]*p1y, + PM[2]*p1z - PM[3]) + Px2,Py2,Pz2 = (PM[0]*p2x, + PM[1]*p2y, + PM[2]*p2z - PM[3]) + Px3,Py3,Pz3 = (PM[0]*p3x, + PM[1]*p3y, + PM[2]*p3z - PM[3]) + + if p1z: + z1 = 1/p1z Px1,Py1,Pz1 = Px1*z1, Py1*z1, Pz1*z1 - if p2.k: - z2 = 1/p2.k + if p2z: + z2 = 1/p2z Px2,Py2,Pz2 = Px2*z2, Py2*z2, Pz2*z2 - if p3.k: - z3 = 1/p3.k + if p3z: + z3 = 1/p3z Px3,Py3,Pz3 = Px3*z3, Py3*z3, Pz3*z3 - - return ( - Vec( (Px1+1)*cx,(-Py1+1)*cy,Pz1 ), - Vec( (Px2+1)*cx,(-Py2+1)*cy,Pz1 ), - Vec( (Px3+1)*cx,(-Py3+1)*cy,Pz1 )) + + return [ + Vec( (Px1+1)*cx,(1-Py1)*cy,Pz1 ), + Vec( (Px2+1)*cx,(1-Py2)*cy,Pz2 ), + Vec( (Px3+1)*cx,(1-Py3)*cy,Pz3 )] else: - return ( - Vec(p1.i*Scl + cx, cy-p1.j*Scl), - Vec(p2.i*Scl + cx, cy-p2.j*Scl), - Vec(p3.i*Scl + cx, cy-p3.j*Scl)) + return [ + Vec(p1x*Scl + cx, cy-p1y*Scl), + Vec(p2x*Scl + cx, cy-p2y*Scl), + Vec(p3x*Scl + cx, cy-p3y*Scl)] -def Shade(T,L,C): - TNor = (T.normal()).normalize() - RetCol = None +cdef Color Shade(Triangle T, Light L, Camera C): + cdef Vec TNor,Lv,H + cdef Color RetCol,LCor + cdef double LAtten,DiffConst,SpecConst + LCor = L.color + LV = -L.dirx + cdef str Lty = L.typ - #dif + TNor = (T.normal()).normalize() + RetCol = Color(0,0,0) + LAtten = 1 - if L.typ == "DIRX": - DiffConst = ( (TNor).dot((-L.dirx).normalize()) ) + + #dif + if Lty == "DIRX": + DiffConst = ( (TNor).dot(LV.normalize()) ) - elif L.typ == "POINT": + else: LVec = L.loc - T.center() LAtten = 1/(4*pi*LVec.magsq()) DiffConst = (TNor).dot(LVec.normalize()) @@ -313,12 +366,11 @@ def Shade(T,L,C): #spec if T.mat.spec: - if L.typ == "DIRX": - lv = -L.dirx - H = ((C.loc-T.a)+lv).normalize() - elif L.typ =="POINT": - lv = L.loc-T.a - H = ((C.loc-T.a)+lv).normalize() + if Lty == "DIRX": + H = ((C.loc-T.a)+LV).normalize() + else: + Lv = L.loc-T.a + H = ((C.loc-T.a)+LV).normalize() SpecConst = (H.dot(TNor))**150 @@ -328,7 +380,7 @@ def Shade(T,L,C): -def Render(PG,UserScene,RotAn): +def Render(PG, Scene UserScene, list RotAn): PG.init() myfont = PG.font.SysFont("monospace", 15) @@ -337,47 +389,57 @@ def Render(PG,UserScene,RotAn): Surface = Display.set_mode(UserScene.Size) clock = PG.time.Clock() - Cam = UserScene.camera - Sze = UserScene.Size - OX,OY = Sze[0]/2, Sze[1]/2 - Scl = UserScene.Scale - Lts = UserScene.Lights - - VertSize = 2 - EdgeSize = 1 - NOpt = True + cdef Camera Cam = UserScene.camera + cdef list Sze = UserScene.Size + cdef int OX,OY + OX,OY = (Sze[0]/2), (Sze[1]/2) + cdef double Scl = UserScene.Scale + cdef list Lts = UserScene.Lights + + cdef int VertSize = 2 + cdef int EdgeSize = 1 + cdef int NOpt,DVt,DEd,DFc - DVt = DEd = DFc = False + NOpt = 1 + DVt = DEd = DFc = 0 DrwMode = UserScene.DrwMode if DrwMode == "RENDER": - DFc = True + DFc = 1 elif DrwMode == "ALL": - DVt = DEd = DFc = True + DVt = DEd = DFc = 1 elif DrwMode == "ALL-NV": - DEd = DFc = True + DEd = DFc = 1 elif DrwMode == "ALL-NE": - DVt = DFc = True + DVt = DFc = 1 elif DrwMode == "WIRE": - DEd = True - NOpt = False + DEd = 1 + NOpt = 0 elif DrwMode == "WIREVERT": - DEd = DVt = True - NOpt = False + DEd = DVt = 1 + NOpt = 0 elif DrwMode == "VERT": - DVt = True - NOpt = False + DVt = 1 + NOpt = 0 - VColor,EColor = (UserScene.VertColor, - UserScene.EdgeColor) + cdef list VColor,EColor + VColor,EColor = UserScene.VertColor, UserScene.EdgeColor + cdef list PersMatrix PersMatrix = PersMatrixGen(Cam.fov, - (UserScene.H/UserScene.W), - UserScene.NearPoint, - UserScene.FarPoint) - - - while True: + (UserScene.H/UserScene.W), + UserScene.NearPoint, + UserScene.FarPoint) + + cdef dict UnsortedTris + cdef list SortedTris + cdef Triangle TRIS + cdef Vec a,b,c + cdef Color SurfCol + cdef int R,G,B + cdef Mesh Object + + while 1: t1 = time() clock.tick(60) Surface.fill((0,0,0)) @@ -387,17 +449,17 @@ def Render(PG,UserScene,RotAn): tTrans1 = time() #__GEOMETRY_CALCULATION___ for Object in UserScene.Objects: - UnsortedTris.update(Transform(Object,RotAn,NOpt,Cam)) + Object.Rotation = list(map(sum, zip(Object.Rotation, RotAn))) + UnsortedTris.update(Transform(Object,NOpt,Cam)) tTrans2 = time() - #__FACE_SORTING___ SortedTris = sorted(UnsortedTris, key=UnsortedTris.get)[::-1] - - + tPrj = RastT = tLgt = 0 #___RENDERING__ + for TRIS in SortedTris: #_Projection_ tPrj1 = time() @@ -430,7 +492,7 @@ def Render(PG,UserScene,RotAn): t2 = time() - #__PROFILING__ + #__PERFORMANCE__ tt = (t2-t1) TransT = round((tTrans2-tTrans1)*100,3) tPrj = round(tPrj*100,3) @@ -447,7 +509,6 @@ def Render(PG,UserScene,RotAn): Surface.blit(timerLab, (20, Sze[1]-200)) Display.update() + # break - - From d69eda1bfb1664a21f75f08c98aeb3d2ada0957d Mon Sep 17 00:00:00 2001 From: Udit Chandra <83822686+udit-uc828@users.noreply.github.com> Date: Tue, 28 Sep 2021 00:38:42 +0530 Subject: [PATCH 02/11] Rename RenderLib.py to RenderLib.pyx --- RenderLib/{RenderLib.py => RenderLib.pyx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename RenderLib/{RenderLib.py => RenderLib.pyx} (100%) diff --git a/RenderLib/RenderLib.py b/RenderLib/RenderLib.pyx similarity index 100% rename from RenderLib/RenderLib.py rename to RenderLib/RenderLib.pyx From 392a942176ef9e34895c317c25aabdf1f0f15138 Mon Sep 17 00:00:00 2001 From: Udit Chandra <83822686+udit-uc828@users.noreply.github.com> Date: Tue, 28 Sep 2021 00:45:08 +0530 Subject: [PATCH 03/11] Import pyximport... --- main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.py b/main.py index 3dec10f..e009bf7 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,6 @@ +import pyximport +pyximport.install() + import pygame from SceneFile2 import RenderScene,Anim from RenderLib.RenderLib import Render From 58ba7deee85651ee3ff8d5add4b12fea5df952e8 Mon Sep 17 00:00:00 2001 From: Udit Chandra <83822686+udit-uc828@users.noreply.github.com> Date: Tue, 28 Sep 2021 00:49:12 +0530 Subject: [PATCH 04/11] Update Cython info --- README.md | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 50e0b08..81fedda 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,20 @@ # Python_Rasterizer ## Description -This is an implementation of a Software Rasterizer written in Python. +This is an implementation of a Software Rasterizer written in Cython. ## Dependencies * PyGame +* Cython * `Python 3.x` is recommended. ## Notice -This is a pure Python 3.x code, and will be very slow on CPython interpreter. - -For speed boost, kindly use PyPy version. - -I've also implemented it in Cython, check that branch `Cython_Ver`. Cython code is much more verbose compared Pure Python due to Types, but in return you get blazing fast speed of C (Native C will almost always be faster) +This is the Cython implementation you're looking for ## Building * Clone this Repository * Simply run `main.py` file +* You can either use pyximport or build the `renderlib.pyx` file using cython compiler * Changes in the scene can be made by editing `scenefile.py` or `scenefile2.py`, whichever is imported in `main.py` ## Features @@ -31,12 +29,3 @@ I've also implemented it in Cython, check that branch `Cython_Ver`. Cython code ## ChangeLog ###Sept 28,2021 * Initial Commit (see Features) - -## Editing Scenes -_Kindly Read `RenderLib.py` file and if you understand a little bit of it, Scenes are defined by using a `Scene` object which contains all the data of scene._ - -I know this is not enough to explain but I'll be writing doc-strings in each every class and functions.. And in future, I maybe create a wiki or documentation for using this project - -## Contributions -If you like this Project, and want to improve something in it, or just want to reimplement this from your perspective (any class/function/algorithm or whole project), feel free to do.. It will be very appreciated! -We're going to take over the VFX industry with this 🙂 From fd63f8b7346c0a54a96aef38ac41bbb6753619fb Mon Sep 17 00:00:00 2001 From: Udit Chandra <83822686+udit-uc828@users.noreply.github.com> Date: Tue, 28 Sep 2021 00:49:47 +0530 Subject: [PATCH 05/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81fedda..3e5cfd8 100644 --- a/README.md +++ b/README.md @@ -27,5 +27,5 @@ This is the Cython implementation you're looking for * OBJ import support (only triangluar geometry is supported for now) ## ChangeLog -###Sept 28,2021 +### Sept 28,2021 * Initial Commit (see Features) From e4c52839cd48547fe5c966ffb17abde720972d09 Mon Sep 17 00:00:00 2001 From: Udit Chandra <83822686+udit-uc828@users.noreply.github.com> Date: Tue, 28 Sep 2021 12:41:46 +0530 Subject: [PATCH 06/11] Update RenderLib.pyx --- RenderLib/RenderLib.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RenderLib/RenderLib.pyx b/RenderLib/RenderLib.pyx index aa6b8db..e456807 100644 --- a/RenderLib/RenderLib.pyx +++ b/RenderLib/RenderLib.pyx @@ -135,7 +135,7 @@ cdef class Mesh: self.Rotation = [0,0,0] self.Scale = [1,1,1] self.PreTranslate = [0,0,0] - self.Translate = [0,0,5] + self.Translate = [0,0,6] @staticmethod def LoadMesh(path,norm=1): @@ -507,7 +507,7 @@ def Render(PG, Scene UserScene, list RotAn): Surface.blit(fpsLab, (20, Sze[1]-220)) Surface.blit(timerLab, (20, Sze[1]-200)) - + Display.update() From c508bb7f0fa32a031a829614947f251e43547e8d Mon Sep 17 00:00:00 2001 From: Udit Chandra <83822686+udit-uc828@users.noreply.github.com> Date: Tue, 28 Sep 2021 12:43:51 +0530 Subject: [PATCH 07/11] Update SceneFile.py --- SceneFile.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/SceneFile.py b/SceneFile.py index 620c7b7..a082083 100644 --- a/SceneFile.py +++ b/SceneFile.py @@ -1,15 +1,13 @@ from RenderLib.RenderLib import * -w,h = 720,720 +w,h = 1600,720 Obj = Mesh.LoadMesh("OBJ/teapot.obj") -Obj.mat.color = Color(1,0,0) Obj.Rotation = [30,0,0] -Obj.Scale = [1/1.5]*3 +Obj.Scale = [1/1.3]*3 Obj.Translate = [0,0,6] - -Obj.mat = Material(color=Color(1,0,.08),spec=1) +Obj.mat = Material(color=Color(0,0.2,1),spec=1) camr = Camera(Vec(), 60) From 397788f6df0bbf2c45a2b518e3c86f542327568f Mon Sep 17 00:00:00 2001 From: Udit Chandra <83822686+udit-uc828@users.noreply.github.com> Date: Tue, 28 Sep 2021 12:44:51 +0530 Subject: [PATCH 08/11] Update SceneFile2.py --- SceneFile2.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/SceneFile2.py b/SceneFile2.py index 56fe283..4679c62 100644 --- a/SceneFile2.py +++ b/SceneFile2.py @@ -1,25 +1,28 @@ from RenderLib.RenderLib import * -w,h = 1280,720 +w,h = 1600,720 -Obj = Mesh.LoadMesh("OBJ/sphere2.obj") +Obj = Mesh.LoadMesh("OBJ/torus.obj") +Obj = Mesh.LoadMesh("OBJ/sphere.obj") -Obj.mat.color = Color(1,0,0) -Obj.Rotation = [0,0,0] +Obj.Rotation = [-10,0,0] +Obj.Translate = [0,.3,6] +Obj2.Translate = [0,.3,6] Obj.Scale = [.5]*3 -Obj.PreTranslate = [0,0,0] -Obj.Translate = [0,0,6] +Obj2.Scale = [.25]*3 -Obj.mat = Material(color=Color(1,0,.1),spec=1) +Obj.mat = Material(color=Color(0,.2,1),spec=1) +Obj2.mat = Material(color=Color(1,.2,0),spec=1) camr = Camera(Vec(), 50) dxlt = Light(Vec(),power=.8,dirx=Vec(0,-.51,1)) -pxlt = Light(Vec(0,2,0), 280,typ="POINT") +pxlt = Light(Vec(0,2,0), 600,typ="POINT") -RenderScene = Scene([Obj],[pxlt],camr,w,h) +RenderScene = Scene([Obj,Obj2],[pxlt],camr,w,h) + +Anim = [1,1,0] -Anim = [0,1,0] #RenderScene.HDRClip=True #RenderScene.DrwMode= "ALL" From 367d96c3cc5ab355c87211ef877e38f3e8b7aee7 Mon Sep 17 00:00:00 2001 From: Udit Chandra <83822686+udit-uc828@users.noreply.github.com> Date: Tue, 28 Sep 2021 12:52:16 +0530 Subject: [PATCH 09/11] Bug fix --- SceneFile2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SceneFile2.py b/SceneFile2.py index 4679c62..1407bd0 100644 --- a/SceneFile2.py +++ b/SceneFile2.py @@ -3,7 +3,7 @@ w,h = 1600,720 Obj = Mesh.LoadMesh("OBJ/torus.obj") -Obj = Mesh.LoadMesh("OBJ/sphere.obj") +Obj2 = Mesh.LoadMesh("OBJ/sphere.obj") Obj.Rotation = [-10,0,0] Obj.Translate = [0,.3,6] From 0a620cd44e91221b07b1926192f81c696d9dddf3 Mon Sep 17 00:00:00 2001 From: Udit Chandra <83822686+udit-uc828@users.noreply.github.com> Date: Tue, 28 Sep 2021 13:20:54 +0530 Subject: [PATCH 10/11] Update README.md --- README.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3e5cfd8..6b40ac4 100644 --- a/README.md +++ b/README.md @@ -17,15 +17,9 @@ This is the Cython implementation you're looking for * You can either use pyximport or build the `renderlib.pyx` file using cython compiler * Changes in the scene can be made by editing `scenefile.py` or `scenefile2.py`, whichever is imported in `main.py` -## Features -* Perspective and Orthographic Projection -* Rotation, Translation and Scale -* Real-time Preview using PyGame -* Diffuse and Specular Shading -* Directional and Point Lighting -* Real-time Profiling -* OBJ import support (only triangluar geometry is supported for now) +## Other Stuff! +>This is a branch of main repo- +https://github.com/udit-uc828/Python_Rasterizer +Please check main repo for features and other information -## ChangeLog -### Sept 28,2021 - * Initial Commit (see Features) +:) From 64997d747a5754bf575b55160cdfc58dce678193 Mon Sep 17 00:00:00 2001 From: Udit Chandra <83822686+udit-uc828@users.noreply.github.com> Date: Tue, 28 Sep 2021 13:23:01 +0530 Subject: [PATCH 11/11] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6b40ac4..f221292 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,10 @@ This is the Cython implementation you're looking for * Changes in the scene can be made by editing `scenefile.py` or `scenefile2.py`, whichever is imported in `main.py` ## Other Stuff! ->This is a branch of main repo- -https://github.com/udit-uc828/Python_Rasterizer +>This branch is made to speed up the code by using cython. Please check main repo for features and other information +https://github.com/udit-uc828/Python_Rasterizer + + :)