Wednesday, December 31, 2008
Why aren't we out partying?
When he asked,"Why aren't we out partying?"
I said,"I am wondering the same thing myself. We're like old people, eh? But doesn't matter. I want to sleep. I am sick."
He said,"Partying sucks anyway."
I looked at him,"Whatever, good night!"
So we ended up sick, both of us. Me fixing him TCM throat remedy. Him changing all the rugs. Me buying new duvet. Him clearing all the old furnitures. Me counting threads on the new bedsheets. Him rewiring the house's network. Me picking out new curtains.
We've gone from 25 to 65.
Sunday, December 21, 2008
Oral Fixation
What's that?
I bite. Now they're all infected and bleeding. When the new sem begins again, they will bleed even more.
You should do like that guy in Boston Legal. Bite on a wooden cigarette. For him, it's an ego trip.
I don't get it. I don't need an ego boost.
Ya... but it's still an oral fixation.
Gosh... You're such a perv.
Wednesday, December 17, 2008
All excited and no one to tell to
I sit in the office bursting with joy. Sadly, there's no one to tell to. And suddenly I say, "I wish he is here, I would really like to tell him."
My only friend in the office. And he's not here. Just for a moment, I wish he is here, so I can tell him about Siggraph. About scattering. About the technical papers presented. About everything.
Today, I want my only office buddy back. Because he's the only one whom I can talk to. And unfortunately, he still is.
Tuesday, December 16, 2008
Monday, December 15, 2008
I am watching you
At least spoof your network or something. This is too easy for me. Come on!
I am still watching you....
Thursday, December 11, 2008
Breathing the same air as Don Greenberg
But oh so tiring. Everyone was rushing and running around to attend their selected conferences, papers presentation, speech. I was being the usual polite girl as I was and wanted to wait till the applause quiet down before standing up to leave but I see others just walked out during applause.
You see, it's like those concerts... SXSW etc. Where at a given time a few dozen events, speeches, presentations, showreel, theatre are happening. So you really have to plan your time well. I only attend mostly the courses but I plot my itineraries at least one day ahead. Oh I better sleep now. Discrete geometry starts at 8:30am tomorrow.
Monday, December 8, 2008
Money is the root of all evil
Me: Yes.
He: Do you know how much you owe me?
Me: Err... 9k?
He: 11k. Do you have a financial plan?
Me: ... I am getting a few thousand soon. I can pay you 3k? As long as you feed me. Because I really don't have much.
He: I don't mean that. Just what about the ongoing? Do you have a plan?
Me: ...
He: Gosh. Now you're like the US govt. Even after you pay me the lump sum with your bonuses, can you afford the ongoing rent?
Me: ...
He: Can you not be such an airhead?
Me: But I am such an airhead.
He: You have to start planning your finances.
Me: I took a pay cut when I joined this company. That was the rent. They promised to give it back in 3 months but they didn't. I'll bet you didn't know that.
He: ...
Me: Let's see how it all goes. I can pay you back that sum with my bonus. Definitely! And then I will see how I can deal with the monthly part.
He: You better. Don't let it pile up.
I am officially broke and up to my neck in debts.
Friday, December 5, 2008
You can be really nasty in academics and no one will stop you
I have some of the nastiest professors and they just get away with it. Knowledge is really something, isn't it?
1. Prof Mint
"Hello class? Wah lau eh! Interactive lah? Only me talking, very boring wei."
*puts up all the stupid emails he received on powerpoint and presents it in lecture* "You asked me what is the best research topic to choose? Hey, you're the one doing it, not me."
"Anyone here? All sleeping? Haiz...."
2. Prof Elvis
"Well, if you want to know more, I can prove the whole equation here" *walks to the projector* "On second thoughts, it really ain't that interesting, I think I will skip this" *walks back to his notebook*
3. Prof Gerald
"You traverse through all the objects in your near child node, and recurse, recurse, recurse till you find a hit. Else, go to far child node and recurse, recurse, recurse" *flip his waist length hair*
3. Prof H
Professor H is by far the most mild of the lot. However, when I asked him about my assignment, he gave me the look like I was the kind of kid who used to bully him in school. Maybe I am. Mua ha ha.
Prof Sore Throat
"Hello?"
"Yello"
"Are you having a sore throat?" *I have the worst thought in the world. I was thinking that he might be waiting for a phone call from his office affair and wanted to to surprise her with a kewl voice*
"Why? Do I sound like I am having a sore throat?"
"Errr. Yes" *A no will suffice*
"What's a MAE prof doing chairing a computer graphics conference?"
"I get asked that a lot. It really is very strange, isn't it? I've been an active member since... since before you were even born!"
"I am really excited to attend this conference. I checked the speakers and some of them are the godfathers of computer graphics."
"There are a lot of computer graphics godfather here. Like this and that. Oh and you really have to attend this conference. And the fast forward. It is the pitch of their technical papers. And very funny."
"Somehow I think in academic, you get away with speaking your mind."
"Haha. Somewhat. This is still Singapore after all. But really, why would you say anything otherwise?"
"You should go for the reception. Let me check if students are invited for the reception. Hehe. I have people I can call that will tell me these things *gleeful*. Ok. Please attend the reception. I hope you get to mingle and meet people there."
I think... he is trying to say, network. Of course, Prof! I will!!!! You guys are too cool!
Our happy book
Em and I will try to self-publish a little happy book. It's gonna be mostly crap but our own happy crap.
She draws some of the cutest little things. Me? I am just a muse. Eerr... well I will provide the words. Somewhat. I thought I will defer and have all the time in the world to do it from next month onwards. But I guess not. We shall start now!
Wednesday, December 3, 2008
See what the monkeys got me
We were in Marks & Spencers when C asked me what's the best chocolate here.
I showed him the huge fruit cake and said, "I really want to eat this but it cost $69! You see the tag? And such a big cake. Oh it has cognac too. See?"
"Ok. I am getting this."
*totally flattered that he trusts my taste in food* "You're getting for your mum? Says here it will last till march."
"No. the guys are getting this for you."
"You're kidding me right? It's $69! For a cake! You know that is too expensive! Add another $8 and you can buy an ipod shuffle!!"
"No. You want this. So we're getting this for you."
"Noooooooooo this is mad. You're kidding right?" *I've been really nasty to them and they're so good to me?*
"Nope. I am going to pay now."
I didn't believe him till he paid and handed me the cake.
"Does this mean I can't call you monkey or say D is fat?"
I am so touched.... The indian boys want to feed me. Uhuk
Windows-how to write batch file
http://www.robvanderwoude.com/bht.html
I'll just use cygwin.
Oh wait. I found exactly what I need: http://www.cknow.com/tutorcom/dos08_dealwithfiles.htm
And some misc batch scripts by some misc person: http://www.geocities.com/~budallen/batfiles.html
Monday, December 1, 2008
1st Singapore Tattoo Show 2009
9th to 11th January 2009 at Singapore Expo.
I am so excited. Chris Garver from Miami Ink fame. Hmm... But of course, I am a little biased and absolutely in love with Kat von D. But woohoo!! I can't wait!
December and January is going to be so exciting for me.
Find the details here:
Singapore Expo Calendar
http://www.tattoo.com.sg/
Sunday, November 30, 2008
Thursday, November 27, 2008
Relaxing at work
We were all talking and telling stupid jokes and slam book? That is one good joke. Anyways we started exchanging stories about first crush and all. That's wierd. I don't tell colleagues my childhood stories. But I did this time. And we log into facebook and orkut for the whole show and tell.
"We can't see the picture of the guy you like. Why didn't you add him?"
"Why should I? He was my first crush. I was thirteen. Long time ago."
"Oooh. But we can't see his face."
"Doesn't matter."
Then we started talking about other stuff. I told them about SIGGRAPH Asia. One guy said, "Don't be so stingy. Just pay the $450 and go for it already."
"Pay money and sit in classes torturing myself with C++ and graphics programming?"
"You want to go."
He is right. I do.
Yes I will! I can't wait.
Tuesday, November 25, 2008
SIGGRAPH Asia 2008
Find the details here: http://www.siggraph.org/asia2008/attendees/index.php
Saturday, November 22, 2008
BD
So exams' over, I've submitted the project hours ago and I should be so relieved and sleep to make up for the past semester. But I can't. I mean yes, I am relieved and I woke up this morning shouting "Yay!" with my hands in the air (the other "Yay" is cause I will be seeing punjabi boy in January). But I can't sleep. I can't fall asleep. I just am not tired enough.
Maybe I am just hungry. I forgot to eat today. I just had some chips and coffee. That's lunch and dinner.
I can't sleep. I can't sleep. What do I do?? I fell into this site today. I forgot how. But I just did. So I started reading. And I thought, hmmm... Cool. Then I get a headache reading them. But I need to sleep and I will take any kind of torture just to be able to sleep. Or I could work on my Phong equation codes again. I don't want to. Too soon to start slaving away on the CG codes.
So here I am alternating between reading some call girls' blog and buying makeup online.
Friday, November 21, 2008
For the greater good?
That's what she was trying to imply.
Ok... Am I in trouble?
"I've been involved for the whole of this episode. We have rules for a reason. What we're doing now is not according to company protocols. But we realised you're an asset. I've heard good things about you. So we're doing this because it is beneficial to the company."
Oh... really? I've always thought I'm such a nuisance here.
"The managers and directors have all agreed on this. We've all come together and this is the decision we've made. For the company's benefit, we've all agreed to your transfer. Your new role starts on Jan 1st. I've heard good things about you. Except..."
Hold my breath.
"You talk to fast."
Huh?
In my own twisted world, I imagined the whole episode goes like the nuns' singing about Maria in Sound Of Music.
Thursday, November 20, 2008
glMatrixMode Cheat Sheet
{
glMatrixMode(GL_PROJECTION); // signal that I want to work with the projection stack
glLoadIdentity(); // make sure that the projection stack doesn't already have anything on it
gluPerspective(whatever I want); // set up a normal perspective projection
glMatrixMode(GL_MODELVIEW); // the rest of my app will only change MODELVIEW
glLoadIdentity(); // make sure that the modelview stack doesn't already have anything on it
}
void FunctionToDrawAFrame()
{
// modelview is still the active stack, because I never that setting
glPushMatrix(); // push current matrix up one, because I'm about to do a bunch of stuff that shouldn't remain active after the end of this function
/* position camera - whatever code you want, this is just an example */
glTranslatef(cameraX, cameraY, cameraZ);
glRotatef(cameraAngle, 0, 1, 0);
/* draw all objects */
for(all objects)
{
glPushMatrix(); //we don't want each object to move the camera...
glTranslatef(objectX, objectY, obectZ);
glRotatef(objectAngle, 0, 1, 0);
DrawObject(); // whatever method you use to draw your object
glPopMatrix(); //restore unaffected camera for next object
}
glPopMatrix(); // restore view prior to movement by this camera
}
From: http://www.allegro.cc/forums/thread/595000
Tron
Relentless Quark had to remind me the game they play in the movie. It's Light Cycle.
Anyways, for the uninitiated, here you go:
http://en.wikipedia.org/wiki/Light_Cycle
Wednesday, November 19, 2008
GL Mouse Picking and Selection
I think I might might have a solution to the mouse picking problem.
Could it be:
1. viewport problem?
2. matrix transformation problem?
3. z-buffer depth search problem - check in function processHits();
Read this: http://www.opengl.org/resources/faq/technical/transformations.htm
Wow! Very nice!!!!
3D Computer Graphics Tutorial:
http://www.jimbrooks.org/web/opengl/tutorials/
EDIT:
Was looking at the visitor stats and realised a lot of people come to this post when searching for OpenGL mouse picking. I've solved it.
Point is, if you want to pick in 3D; there's no straight forward way to doing that entirely in mouse.
What you can do is, specify another keyboard key + one mouse action for z-coordinate. Why? cause glut mouse function only specifies x,y coordinates. That's the easiest way to doing it.
That bugger
My heart did a leap. I've not seen him for the past 6 months.
How do you look like now?
Are you thinner? Are you older? How have you been?
Are you world weary now? Life can be cruel sometimes. Hang on. I am coming home soon.
I miss you. Can't wait to see you.
Tuesday, November 18, 2008
Stare at the table
No reaction from the crowd. I dare not breathe. In case breathing might offend. I hang my head and let my hair fall around my face. Hoping my face will be occluded.
Nobody say anything.
Nothing! Nothing! I held my breath till my face turned purple.
"Thank you for being with us for the past one year."
Is that the cue for me to speak? I still dare not. I smiled and nodded.
Continue staring at the table.
Monday, November 17, 2008
Get around
Read this on the sin and cos for 3D programming: http://pixwiki.bafsoft.com/mags/5/articles/circle/sincos.htm
Homogenous coordinates:
http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MOHR_TRIGGS/node7.html
This for better explanation on the 4x4 matrix as used in OpenGL.
http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm
2. 3D viewing and perspectives. Eye, World, Object view.
3. OpenGL commands...
4. Finish all the past year papers.
Sunday, November 16, 2008
Thank god?
Eerrr.... thank god? She's a real kryptonite?
Saturday, November 15, 2008
Sick Sick Sick!
If I don't finish CG today, I am not allowed to sleep. Ok. That's it!
Friday, November 14, 2008
The good girl
Her family.
Who listens to her parents... somewhat.
Does everything well.
Does everything they want her to, except... get married.
To a chinese boy.
Homogeneous. Just like her maths equations.
She will never defy them. And break their hearts.
So she chooses never to
But she will never tell them.
She just apologise and kept herself busy.
Here is where she will fail them.
All because,
she is hard to impress.
Strange dreams
Dreamt that I jumped into his car and he was driving around backwards.
Dreamt that bro was found guilty. Without bail. Confused.
Dreamt that my shoulder and ass hurts from dragging my bag around. Which could be true. Since it did hurt my shoulder very badly.
Dreamt about graphics pipeline. Dreamt about exams.
Dreamt about work. Dreamt about the dreaded meeting to announce my departure.
Wednesday, November 12, 2008
My first Christmas & New Year
Used to dread this time of the year. Spent most of the time in switch. Tortured, stressful, sleepless nights.
How about this year?
You are wasting my time look
I replied,"I have not finished talking yet. I will come to that part once I am done explaining this to you."
"Oh hehe. So I have to pay you? Ah with Malaqa money?"
*Look at him from the corner of my chinky eyes* "Can we continue?"
3D Game and Graphic Engine DB
http://www.devmaster.net/articles/graphics_alg/
Find it here. Check them out during sem break:
http://www.devmaster.net/engines/
Monday, November 10, 2008
Please, Just make up your mind!
Just make up your mind. Yes? No? Ok. Let's go!
And then there's the biggest longgok... lol. Love Jude's way of saying it.
School. Family. Work. All drama at the same time.
Jude told me it's alright to defer. As she puts it:
You don't want to fail and repeat school. And fail at work? Absolutely not. Cause we are the best!
I will buy her whatever she wants to eat after this. And she really can eat even though she is so small.
Embarassed closet maths nerd
http://projecteuler.net/index.php?section=about
I really do.
Sunday, November 9, 2008
All about R-tree
http://www.rtreeportal.org/
Saturday, November 8, 2008
My punishment
So I guess, I am really really making up for all of it now. Ugh!
Mean thought. I hope the rest of the class did badly too.
Why do I torture myself like that? I cannot explain.
Someone asked,"Why did you decided to do this?"
To which I replied, "To open my chakra."
Relational Algebra
Lecture Notes: Relational Algebra
What? Why?
- Similar to normal algebra (as in 2+3*x-y), except we use relations as values instead of numbers, and the operations and operators are different.
- Not used as a query language in actual DBMSs. (SQL instead.)
- The inner, lower-level operations of a relational DBMS are, or are similar to, relational algebra operations. We need to know about relational algebra to understand query execution and optimization in a relational DBMS.
- Some advanced SQL queries requires explicit relational algebra operations, most commonly outer join.
- Relations are seen as sets of tuples, which means that no duplicates are allowed. SQL behaves differently in some cases. Remember the SQL keyword distinct.
- SQL is declarative, which means that you tell the DBMS what you want, but not how it is to be calculated. A C++ or Java program is procedural, which means that you have to state, step by step, exactly how the result should be calculated. Relational algebra is (more) procedural than SQL. (Actually, relational algebra is mathematical expressions.)
Set operations
Relations in relational algebra are seen as sets of tuples, so we can use basic set operations.Review of concepts and operations from set theory
- set
- element
- no duplicate elements (but: multiset = bag)
- no order among the elements (but: ordered set)
- subset
- proper subset (with fewer elements)
- superset
- union
- intersection
- set difference
- cartesian product
Projection
Example: The table E (for EMPLOYEE)
nr | name | salary |
---|---|---|
1 | John | 100 |
5 | Sarah | 300 |
7 | Tom | 100 |
SQL | Result | Relational algebra | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
select salary |
| PROJECTsalary(E) | ||||||||
select nr, salary |
| PROJECTnr, salary(E) |
Note that there are no duplicate rows in the result.
Selection
The same table E (for EMPLOYEE) as above.
SQL | Result | Relational algebra | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
select * |
| SELECTsalary <>(E) | |||||||||
select * |
| SELECTsalary <>= 7(E) |
Note that the select operation in relational algebra has nothing to do with the SQL keyword select. Selection in relational algebra returns those tuples in a relation that fulfil a condition, while the SQL keyword select means "here comes an SQL statement".
Relational algebra expressions
SQL | Result | Relational algebra | ||||||
---|---|---|---|---|---|---|---|---|
select name, salary |
| PROJECTname, salary (SELECTsalary <>(E))
Temp <- SELECTsalary <>(E) |
Notation
The operations have their own symbols. The symbols are hard to write in HTML that works with all browsers, so I'm writing PROJECT etc here. The real symbols:
Example: The relational algebra expression which I would here write as
PROJECTNamn ( SELECTMedlemsnummer <> ( Medlem ) )
should actually be written
Cartesian product
The cartesian product of two tables combines each row in one table with each row in the other table.Example: The table E (for EMPLOYEE)
enr | ename | dept |
---|---|---|
1 | Bill | A |
2 | Sarah | C |
3 | John | A |
Example: The table D (for DEPARTMENT)
dnr | dname |
---|---|
A | Marketing |
B | Sales |
C | Legal |
SQL | Result | Relational algebra | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
select * |
| E X D |
- Seldom useful in practice.
- Usually an error.
- Can give a huge result.
Join (sometimes called "inner join")
The cartesian product example above combined each employee with each department. If we only keep those lines where the dept attribute for the employee is equal to the dnr (the department number) of the department, we get a nice list of the employees, and the department that each employee works for:
SQL | Result | Relational algebra | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
select * |
| SELECTdept = dnr (E X D)
E JOINdept = dnr D |
- A very common and useful operation.
- Equivalent to a cartesian product followed by a select.
- Inside a relational DBMS, it is usually much more efficient to calculate a join directly, instead of calculating a cartesian product and then throwing away most of the lines.
- Note that the same SQL query can be translated to several different relational algebra expressions, which all give the same result.
- If we assume that these relational algebra expressions are executed, inside a relational DBMS which uses relational algebra operations as its lower-level internal operations, different relational algebra expressions can take very different time (and memory) to execute.
Natural join
A normal inner join, but using the join condition that columns with the same names should be equal. Duplicate columns are removed.Renaming tables and columns
Example: The table E (for EMPLOYEE)
nr | name | dept |
---|---|---|
1 | Bill | A |
2 | Sarah | C |
3 | John | A |
Example: The table D (for DEPARTMENT)
nr | name |
---|---|
A | Marketing |
B | Sales |
C | Legal |
We want to join these tables, but:
- Several columns in the result will have the same name (nr and name).
- How do we express the join condition, when there are two columns called nr?
Solutions:
- Rename the attributes, using the rename operator.
- Keep the names, and prefix them with the table name, as is done in SQL. (This is somewhat unorthodox.)
SQL | Result | Relational algebra | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
select * |
| (RENAME(enr, ename, dept)(E)) JOINdept = dnr (RENAME(dnr, dname)(D)) | ||||||||||||||||||||
select * |
| E JOINdept = D.nr D |
You can use another variant of the renaming operator to change the name of a table, for example to change the name of E to R. This is necessary when joining a table with itself (see below).
RENAMER(E)A third variant lets you rename both the table and the columns:
RENAMER(enr, ename, dept)(E)
Aggregate functions
Example: The table E (for EMPLOYEE)
nr | name | salary | dept |
---|---|---|---|
1 | John | 100 | A |
5 | Sarah | 300 | C |
7 | Tom | 100 | A |
12 | Anne | null | C |
SQL | Result | Relational algebra | ||
---|---|---|---|---|
select sum(salary) |
| Fsum(salary)(E) |
Note:
- Duplicates are not eliminated.
- Null values are ignored.
SQL | Result | Relational algebra | ||
---|---|---|---|---|
select count(salary) | Result:
| Fcount(salary)(E) | ||
select count(distinct salary) | Result:
| Fcount(salary)(PROJECTsalary(E)) |
You can calculate aggregates "grouped by" something:
SQL | Result | Relational algebra | ||||||
---|---|---|---|---|---|---|---|---|
select sum(salary) |
| deptFsum(salary)(E) |
Several aggregates simultaneously:
SQL | Result | Relational algebra | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
select sum(salary), count(*) |
| deptFsum(salary), count(*)(E) |
Standard aggregate functions: sum, count, avg, min, max
Hierarchies
Example: The table E (for EMPLOYEE)
nr | name | mgr |
---|---|---|
1 | Gretchen | null |
2 | Bob | 1 |
5 | Anne | 2 |
6 | John | 2 |
3 | Hulda | 1 |
4 | Hjalmar | 1 |
7 | Usama | 4 |
Going up in the hierarchy one level: What's the name of John's boss?
SQL | Result | Relational algebra | ||
---|---|---|---|---|
select b.name |
| PROJECTbname ([SELECTpname = "John"(RENAMEP(pnr, pname, pmgr)(E))] JOINpmgr = bnr [RENAMEB(bnr, bname, bmgr)(E)])
PROJECTb.name ([SELECTname = "John"(RENAMEP(E))] JOINp.mgr = b.nr [RENAMEB(E)])
P <- RENAMEP(pnr, pname, pmgr)(E) |
Notes about renaming:
- We are joining E with itself, both in the SQL query and in the relational algebra expression: it's like joining two tables with the same name and the same attribute names.
- Therefore, some renaming is required.
- RENAMEP(E) JOIN... RENAMEB(E) is a start, but then we still have the same attribute names.
Going up in the hierarchy two levels: What's the name of John's boss' boss?
SQL | Result | Relational algebra | ||
---|---|---|---|---|
select ob.name |
| PROJECTob.name (([SELECTname = "John"(RENAMEP(E))] JOINp.mgr = b.nr [RENAMEB(E)]) JOINb.mgr = ob.nr [RENAMEOB(E)])
P <- RENAMEP(pnr, pname, pmgr)(E) |
Recursive closure
Both one and two levels up: What's the name of John's boss, and of John's boss' boss?
SQL | Result | Relational algebra | |||
---|---|---|---|---|---|
(select b.name ...) |
| (...) UNION (...) |
Recursively: What's the name of all John's bosses? (One, two, three, four or more levels.)
- Not possible in (conventional) relational algebra, but a special operation called transitive closure has been proposed.
- Not possible in (standard) SQL (SQL2), but in SQL3, and using SQL + a host language with loops or recursion.
Outer join
Example: The table E (for EMPLOYEE)
enr | ename | dept |
---|---|---|
1 | Bill | A |
2 | Sarah | C |
3 | John | A |
Example: The table D (for DEPARTMENT)
dnr | dname |
---|---|
A | Marketing |
B | Sales |
C | Legal |
List each employee together with the department he or she works at:
SQL | Result | Relational algebra | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
select *
select * |
| E JOINedept = dnr D |
No employee works at department B, Sales, so it is not present in the result. This is probably not a problem in this case. But what if we want to know the number of employees at each department?
SQL | Result | Relational algebra | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
select dnr, dname, count(*)
select dnr, dname, count(*) |
| dnr, dnameFcount(*)(E JOINedept = dnr D) |
No employee works at department B, Sales, so it is not present in the result. It disappeared already in the join, so the aggregate function never sees it. But what if we want it in the result, with the right number of employees (zero)?
Use a right outer join, which keeps all the rows from the right table. If a row can't be connected to any of the rows from the left table according to the join condition, null values are used:
SQL | Result | Relational algebra | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
select * |
| E RIGHT OUTER JOINedept = dnr D | |||||||||||||||||||||||||
select dnr, dname, count(*) |
| dnr, dnameFcount(*)(E RIGHT OUTER JOINedept = dnr D) | |||||||||||||||||||||||||
select dnr, dname, count(enr) |
| dnr, dnameFcount(enr)(E RIGHT OUTER JOINedept = dnr D) |
Join types:
- JOIN = "normal" join = inner join
- LEFT OUTER JOIN = left outer join
- RIGHT OUTER JOIN = right outer join
- FULL OUTER JOIN = full outer join
Outer union
Outer union can be used to calculate the union of two relations that are partially union compatible. Not very common.Example: The table R
A | B |
---|---|
1 | 2 |
3 | 4 |
Example: The table S
B | C |
---|---|
4 | 5 |
6 | 7 |
The result of an outer union between R and S:
A | B | C |
---|---|---|
1 | 2 | null |
3 | 4 | 5 |
null | 6 | 7 |
Division
Who works on (at least) all the projects that Bob works on?Semijoin
A join where the result only contains the columns from one of the joined tables. Useful in distributed databases, so we don't have to send as much data over the network.Update
To update a named relation, just give the variable a new value. To add all the rows in relation N to the relation R:R <- R UNION N
Taken from:
Friday, November 7, 2008
Prof G said
Yahooo! Yay! I was going to do that anyways, but I got no one to confirm that my codes' right. Cooool. I can't wait! So excited.
Oh on another note, I might have more responsibilities on the job come January, so I am not sure if I should defer or continue with Jan semester. But that can wait. First thing first. Exams and geometry project!
Wednesday, November 5, 2008
Let's go somewhere far away.
I will go somewhere very far away. Build my own little house. Then I will kidnap you. And we will live in that little house. You will never have to care what happens to him.
A silly thought. But a silly thought that makes me happy.
Tuesday, November 4, 2008
Understand Phong and Spaces
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
VGOPHONG.TXT - Phong lighting and specular highlights. Theory,
practice and explaination of the phong lighting
and shading model.
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
by TimJ/Vertigo
"I am he, as you are he, as you are me, and we are all together"
email: tim@legend.co.uk
irc: #coders #vertcode
revision history:
16/02/97 v1.0 - Initial version
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
INTRODUCTION
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
First off, I hope this doc is of use to some people, and maybe other
people will find it interesting.
Recently, I've been thinking a lot about phong shading and lighting.
There was something that was bugging me. I couldn't quite put my finger
on it. It was something I knew to be true, but I had to explain it to
myself. It all started when I was chatting to Vector about true phong
shading. We'd both recently looked at Voltaire/OTM's doc on fast phong
shading (again).
We were (among other things) chatting about lighting functions in our
3D engine. It was about specular highlights and the way normal (fast)
phong lighting doesn't yield specular highlights on a flat plane
(all normals pointing one way). This got me thinking. I thought, well
of course it doesn't, because the light calculated at each point will be
the same (because all normals are the same). This annoyed me because I
knew it wasn't true -- but I couldn't remember why. It's all to do with
the light vector and the view vector (and keeping them constant).
Volatire's phong method also doesn't yield specular highlights in the
center of polygons. Oh, and his method emulates the equation given
exactly -- it's not a tradeoff. But then again, it's also just the
same as using gouraud. I'll explain later.
Then I remembered the actual theory behind the lighting equations. It
stuck me that people tend to get mixed up in code and forget about the
theory behind it.
What I'll do is go through the theory, how it's implemented.
Based on that I'll then address what this doc is actually about --
highlights in the center of polygons and on flat planes.
If you think this doc is a bit slow, forgive me, but you can never please
everybody :)
[Oh, important point.. this is generally about the phong equation. You
can do it per pixel or per vertex, either way it's the phong equation.
Just because you gouraud shade doesn't mean you can't have phong style
specular highlights.]
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
LIGHT RAY REFLECTION
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
I was going to explain the theory behind light ray relfection and the
spread of the ray across a surface depending on the angle of incidence.
But but then I realized I'd have to go into they physics behind spectral
reflectivity too, so I won't :)
If there's enough demand for it, email me and I'll put it in.
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
PHONG'S SPECULAR HIGHLIGHTS
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
We need to understand how the phong lighting equation is made up. Let's
define a few useful values:
^N
|
Lˇˇˇ | R V
\ˇˇ | / __/
\ˇ | / __/
\ | / __/
\ | /__/
\|//
-------------.--------------
P
^
point under consideration
It's important you know what these values actually are:
N = surface normal
L = unit vector between point and light
V = unit vector between point and view
R = light reflection unit vector (mirror of L about N)
First, the diffuse relfection is given by the Lamertian Relfection
equation:
diffuse = Kd * (N dot L)
Where Kd is the diffuse relfection constant. (N dot L) is the same as
the cosine of the angle between N and L, so as the angle decrease, the
resulting diffuse value is higher.
Phong gave spectral reflectivity as:
diffuse + Ks * (R dot V)^n
Which is:
Kd * (N dot L) + Ks * (R dot V)^n
Where Kd is the diffuse component and Ks is the specular compoenet. This
is the generally accepted phong lighting equation. Ks is generaly taken to
be a specularity constant (although Phong defined it as W(i).. see later).
As the angle between the view (V) and the reflected light (R) decreases,
you will get more specularity.
The clever thing about Phong's equation was that it gave a neat way to
calculate the specular intensity 'bump' around the light reflection
vector (R). The larger the exponential power (n) the smaller and more
intense the specular intensity bump. Hence specular highlights.
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
IMPLEMENTATION OF PHONG'S EQUATION
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
Most people simplify this equation somewhat, for speed. We begin with :
Kd * (N dot L) + Ks * (R dot V)^n
The obvious thing we'd like to remove is (R dot V). Since we don't
want to calculate the light relfection vector (mirror of light incidence
around the surface normal) -- because it's expensive. Blinn introduced a
way to do this using an imaginary vector H. It's then reduced to (N dot H).
H is defined as halfway between L and V (after L and V are normalized).
H is therefore (L + V) / 2. You will see that the angle R dot V is double
N dot H -- but this doesn't matter as you can alter the specular
exponential value (n) to compenstate. This gives us the equation :
Kd * (N dot L) + Ks * (N dot ( L + V / 2))^n
Up until now we've ignored the ambient factor, this is because it's
damn obvious and has little consequence on the math.. we'll put it in
now
Ka + Kd * (N dot L) + Ks * (N dot ( L + V / 2))^n
Which is easily implemented. You only need three vectors: the surface
normal, the light vector and the view vector. It's obviously advised
to do this equation in object-space.
Another way to remove R dot V, is by replacing it with N dot L :
Ka + Kd * (N dot L) + Ks * (N dot L)^n
This assumes you will always get the maximum specularly reflected light,
no matter where the view is. Here's why :
If we assume V is always the same as R, then the angle between N and V is
the same as N and L --
^N
| A = angle between N and L
Lˇˇˇ | R (also V) B = angle between N and V
\ˇˇA | B /
\ˇ /|\ /
\/ | \/
\ | /
\|/
-------------.--------------
Angle A and B are the same (of course, since R is the mirror vector of L).
So, N dot V becomes the same as L dot N.
This makes life easier and faster. The results completely ignore the
position of the view; so it's like having a reflective surface that always
reflects the maximum amount of specular light towards the view.
(normally, as the angle between the view and the reflected light
increases, you get less specularly reflected light).
It's just a trade off.
Ka + Kd * (N dot L) + Ks * (N dot L)^n
or
Ka + Kd * cos(theta) + Ks * cos(theta)^n
where cos(theta) is N dot L. Most likely, the above equation is the
one most people use. Also, since more implementation assume V is constant
across the scene (normalized.. at infinity) then using N dot L can be
acceptable. But it does have some dire consequences.
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
REAL TIME PHONG SHADING
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
This is what was causing the confusion. Voltaires text on phong shading
(OTMPHONG.TXT) used the equation
color = specular + (cos x) * diffuse + (cos x)^n * specular
for calculating phong lighting. This is the same as the last equation we
just disussed. He then went on to explain the specular intensity 'bump'
through the (cos x)^n term of the equation.
(note: phong shading is done by recalculating the lighting equation at
each pixel -- this is done by interpolating the vertex normals across
the polygon and re-evaluating).
Since there is just one angle term in the equation (N dot L), he realized
he could dispense with normals and just interpolate the angle.
Remember :
Ka + Kd * cos(theta) + Ks * cos(theta)^n
You only need to interpolate theta, then you can do a lookup table for
the correct colour created like so:
for( theta=0 ; theta <>
{
table[i] = Ka + Kd * cos(theta) + Ks * pow( cos(theta) , specExp ) ;
}
The problem with all this is that the original equation was inaccurate,
so the results will be inaccurate. However, Voltaire does point this
out, and state that highlights can't be inside polygons.
But, as Zog pointed out to me, you can get exactly the same effect with
gouraud, by setting up the palette in a similar way. This method is
basically the same as gouraud, you're just interpolating an angle instead
of an intensity.. as Zog put it, "it's fucking gouraud revisited" :)
I just thought I'd clear this up, as people tend not to believe it's
real, and think it's some kind of trick (if you use the same equation
in a true shader, you'll get the same results).
It's also important for the next section (the equation at least).
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
PHONG'S SPECULAR HIGHLIGHTS (REVISITED)
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
As pointed out, phong shading requires the interpolating of vertex
normals across the polygon, and recalculation of the equation.
Right, here's where more confustion comes in. To simplify things,
people tend to treat V as a constant over the entire scene.
N
L | / V (view)
(light) \ | /
\ | /
\ | /
\|/
-------------.--------------
P
V is not constant though.. it is dependant on the point under
consideration (P). So making V constant, is like sticking the view at
infinity (this is done by normalizing the view vector).
This means that the falloff of the specular light at sharp angles
between the surface and view is not taken into account (it's linear).
So the highlight will be too big and intense at sharp angles (the
falloff will be linear in respect to the view position). Also, the
highlight won't move correctly with the view.
You can probably see that the same thing can be done for L..
ie. directional lighting. Putting L at infinity affects specular fall
off with respect to the light and the view. But I'm sure everyone knows
the implications of directional lighting (it's just like having a light
really really far away).
As explained earlier, dispensing with V altogether can give you a nice
speed up using N dot L instead of R dot V.
Let's look at the consequences of dispensing with V. This is like
assuming you have a perfect reflector.. like a mirror. The surface will
always reflect the maximum amount of specular light towards the view --
the highlight will seem to 'stick' to the light relfection vector and not
change shape or size, no matter where you put the view.
But, given this, you just have to interpolate N for the polygon
(remember, we need (N dot L) and (N dot H) where is H = L+V/2)
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
SPECULAR REFLECTION
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
Now we get to the crux of the problem. All that time ago back at the
start, I mentioned a plane with all the normals pointing one way.
The thing to remember is this, the lighting is *not* just dependant on
the surface normal. It's a function of the light vector and the view
vector. The important value is V, as V affects how specular light is
reflected.
If V is properly calculated, for a flat surface, the angle between the
view and the normal (which is constant) will alter.
N
V ^
\ \ |
\ \ |
\ \ |
\ \ |
\ \ |
\ \ |
-------.-----------.---
p1 p2
The angle at p1 is obviously sharper than the angle at p2. Even though
N is the same at both points. It all becomes obvious now. Unless you
calculate V correctly, the reflected specular light over a flat surface
will be the even at any point on it.
At this point you might be thinking : "what if V is put at infinity and
L is calculated properly? -- won't that do the same job?"
In a word, no, because V is the important vector. We have to remember the
original equation where the specular light was a function of R and V.
N would be constant, V would be constant, so specular light would just be
a function of V -- ie, not very accurate at all.
So, we're left with the following equation:
Ka + Kd * (N dot L) + Ks * (N dot ( L + V / 2))^n
So, basically, in a nutshell, you've got to recalculate V for the new
point under consideration. If you do that, you'll get specular highlights
on flat planes.
If you have directional lights (L at infinity) then the highlight will be
incorrectly positioned and spread -- since the angle between any given
point and the light will be more or less the same (to an infintecial
degree). On a flat surface you'd be depending on the angle the view makes
with the surface. Although, this isn't too much to worry about --
I think directional lighting is a choice, not a compromise.
[ Oh yeah, in the first section I said Phong defined Ks as W(i). Well,
this meant that Ks was a function of the angle of incidence between
the light and the surface. So specularly reflected light was dependant
on the incoming angle as well as the outgoing angle. Phong never
actually defined W(i) though -- so it's usually ignored. It does give
you another parameter for your surface to play with though. ]
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
REAL TIME PHONG SHADING (REVISIED)
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
Ok, so now we know that V and L are important factors of the equation.
Voltaire's phong shading method is completely correct for the equation
he used (but as mentioned, it's basically the same as gouraud).
What he did was place L at infinity and make the surface a perfect
reflector (that always reflected the maximum specular light) towards
the view (where ever it was). I explained all this earlier anyway :)
That meant there was only one angle to interpolate, but it also meant
that on flat surfaces it was impossible to get correct highlights.
(polygons are flat :)
However, Voltaire's method is more accurate than normal gouraud for the
same lighting equation (due to the non-linear lookup table).
However, you can do the same with gouraud.. it just another way of
implenenting it (and quite redundant).
His method won't extend to other equations though.
What's annoying is when people just say his method doesn't work and is
a load of crap, without explaining why.
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
CLOSING WORDS
"picture yourself in boat on river with tangerine trees and marmalade skies"
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
Well, I guess I've managed to confuse almost eveyone. What I've tried
to do is explain the factors of the phong lighting equation -- what parts
do what, and why it works.
I've probably made loads of typo's and got different bit's mixed up --
but hell, I don't care :) With any luck, I might not get flamed.
If I have mixed something up, forgive me -- it get's hard to track what
you have/have not said etc.. and it's not easy without some good
diagrams :)
There are a couple of sections I've left out.. I started the one on
light ray reflection, but left it out. I also has a section on optimizing
the equation :
Ka + Kd * (N dot L) + Ks * (N dot ( L + V / 2))^n
But I didn't get it finished (it's based on the routines I use in my
3D engine). There are no square roots, tables, divides or pow()'s used.
Yet it still produces the same results (to a reasonable degree of
accuracy -- any errors are covered up by (a). the number of intensities we
can actually display and (b). the precision of the fpu).
If there's enough demand then I'll put it in.
At the end of all this, an interesting thing to note is that all these
equations have no physical basic what so ever -- they're just equations
that fit real work observations. Light is actually better represented as
radiation -- but let's not get into that now :)
Greets:
Oh god, I don't know.. um.. people I know.. hmmm
(no particular order)
Vector
Vastator
Phred
Gooroo
Midnight
aM
Eckart
codex
PGM (where ever he may be)
BigCheese
Pel
Wog (Zog, whatever)
Crom
God
All at Abstract Entertainment
[plus anyone I've missed]
Flames/comments go to: tim@legend.co.uk
Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’
"Living is easy with eyes closed. Misunderstanding all you see.
It's getting hard to be someone, but it all works out. It doesn't matter
much to me."
Monday, November 3, 2008
The beginning
I don't want to see uniforms again. It was funny before. Now the joke is stale."
No tears. My heart just bleeds. You hurt me bad. I cannot even begin to understand this pain.
Sunday, November 2, 2008
FANTASTIC Explaination and Picture on Eye, World & Object Space
http://www.cs.cmu.edu/~djames/15-462/Fall03/notes/CassEveritt-MathematicsOfPerPixelLighting.pdf
However, in OpenGL, there's only 2 spaces:
1. ModelView: Object
2. Projection: Eye (or camera)
OpenGL has no explicit world space.
From OpenGL.org:
Think of the projection matrix as describing the attributes of your camera, such as field of view, focal length, fish eye lens, etc. Think of the ModelView matrix as where you stand with the camera and the direction you point it.
For the specular lights, we will need the inverse matrix to compute the camera view. However OpenGL matrix is column major. So beware!
Here is one good read on Matrix, OpenGL style.
MacTech: Macintosh Technology has a simple reading for texture gen and texture mapping.
My lighting algorithm was right as far as mathematics is concerned but I did not care about the Eye and View Space that I got them all topsy turvy. From OpenGL Forum:
+--------------+ +--------------+
| Object Space | -> Modeling Transform -> | World Space |
+--------------+ +--------------+
+--------------+ +--------------+
| World Space | -> Viewing Transform -> | Eye Space |
+--------------+ +--------------+
+--------------+ +--------------+
| Object Space | -> Modelview Transform -> | Eye Space |
+--------------+ +--------------+
The modelview matrix gets you from object space to eye space (use the inverse to get back). It doesn't know about world
space.
The only way you can use modelview to get back to world space is if your object space and world space are the same (i.e. your modeling transform is the identity matrix -- i.e. a no-op). in other words, if the position vertex data for all objects in your scene are specified in a common coordinate system.
You're probably goin to find it simpler to pre-transform your light to eye space in your app and pass that into your shader, so you don't have to think about world space in your shader.
Saturday, November 1, 2008
Semester Break
For Self:
1. Wax!
2. Threading. I can see a layer of mustache!
3. Yoga
4. Facial
5. Finish those BS sessions in Orchard.
6. Check camera & equip. Store properly.
7. Clear old lecture notes from bag. Store properly.
For Room:
1. Clean study. Setup dual monitor for mac & Dell. Buffer & speakers.
2. Rearrange furniture. Throw that ugly brown thing out. New room decor! ^_^
3. Clear clothes closet. Throw or give away clothes. Send dresses for dry clean.
4. Buy shoe compartment (Ikea). Throw or give away shoes. Send shoes for mending.
5. Vanity table. Clear old makeup. Put everything properly in their storage boxes. Some new storage compartments from bkk and tky. Need more storage? Ikea or Daiso.
Haiz... Unpack from trips.
Bring unwanted storage boxes home to mum.
Check out:
1. Tesco for home stuff & clothes(?)
2. Raid Harris bookstore for graphic books.
3. Is the Ikea near mum's opened yet?
For sg home:
1. Buy and fix the toilet seat. Dark blue.
For Friends:
1. Copy all pics from my camera for Apie.
2. Pack and label the stuff I've got for Apie & Iqbal.
3. Work with Thomad on his "Project Runway"? -- Let's discuss. Can we finish sewing classes in Dec only? Confirm that.
Need Thomad to: mend my necklace. teach me how to use the tiny sewing machine.
4. Pictures for Celine and Li Ting.
Question:
Where's my Ikea membership card? Find it.
Lights & Rays by Phong
Oooh... Dr Phong. I will study your algo and make the darn lights lit!
Basic Light Model
surfaceColor = emissive + ambient + diffuse + specular
All about lights:
- diffuse = object_diffuse * light_diffuse / (distance_to_object * angle)
- ambient = object_ambient * light_ambient
- emissive = object_emissive
- specular = object_specular * light_specular : with size of reflection determined by object_specular_power and distance_to_object and the position of the reflection based on angle.
- final_color = (diffuse + ambient + emissive) * object_texture + specular : with the sum of diffuse, ambient and emissive capped at (1.0, 1.0, 1.0)
BASICS DETAILS OF LIGHTING:
http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter05.html