Sunday, November 30, 2008

Ah er


He he

Jude in love



Ice cream with mum


Too bad she dig in too fast. All that's left is this sugar snowman. That i licked. Ha ha

Thursday, November 27, 2008

Relaxing at work

Which is something I rarely do. But today we were all shouting and laughing. Because it is a relaxing day.

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

Oh wow! SIGGRAPH Asia in Singapore! 10th to 13th December!


Find the details here: http://www.siggraph.org/asia2008/attendees/index.php

Saturday, November 22, 2008

BD

Well with the rate I torture myself, I guess I might be one of those closet BDSM kinda person.

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?

You broke the rules.
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

void FunctionRunWhenProgramStarts()
{
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

One of my favourite sci-fi movie as a kid. My brother and I would watch it every week, I think. It was good. It was vivid even though I cannot remember much now; except for the lights, the bike and the race.

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

Oh eh.
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

Saw a picture of my brother, on his girl friend's facebook.
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

That's all I could do. When the announcement was made. That I am leaving. I don't know what to say.

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

1. OpenGL matrix distribution (memorised translate, rotate, scale). Also need to memorise perspective.

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?

What will your team say when they find out you're leaving?

Eerrr.... thank god? She's a real kryptonite?

Saturday, November 15, 2008

Sick Sick Sick!

Been sick for the past 2 days. Oh No! 2 days wasted. Gone. And I need to start studying for CG exams. And the darned FFD project for geometry.

If I don't finish CG today, I am not allowed to sleep. Ok. That's it!

Friday, November 14, 2008

The good girl

Who's responsible for herself.
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

Sick. Took my meds. Fell asleep. ND called.

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

This will be my first Christmas & New Year with the new system.

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

As I was explaining the procedure, he interrupts and said, "Oh ah and then this part?"

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

Somehow I found the graphics algorithm a better read than the game engine portion:

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!

Too many crap happening.

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

I was going "uuwaaaah" and told myself I want to play with this during sem break:

http://projecteuler.net/index.php?section=about

I really do.

Sunday, November 9, 2008

All about R-tree

While reading up on Rectangle Tree (R-tree), I came upon this site:
http://www.rtreeportal.org/

Saturday, November 8, 2008

My punishment

I was not studious at all in school. Or during my first degree.
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)

nrnamesalary
1John100
5Sarah300
7Tom100

SQLResultRelational algebra
select salary
from E


salary
100
300
PROJECTsalary(E)
select nr, salary
from E
nrsalary
1100
5300
7100
PROJECTnr, salary(E)

Note that there are no duplicate rows in the result.

Selection

The same table E (for EMPLOYEE) as above.

SQLResultRelational algebra
select *
from E
where salary <>
nrnamesalary
1John100
7Tom100
SELECTsalary <>(E)
select *
from E
where salary <>= 7
nrnamesalary
7Tom100
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

SQLResultRelational algebra
select name, salary
from E
where salary <>
namesalary
John100
Tom100
PROJECTname, salary (SELECTsalary <>(E))

or, step by step, using an intermediate result

Temp <- SELECTsalary <>(E)
Result <- PROJECTname, salary(Temp)

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:

Operation My HTML Symbol
Projection PROJECT Greek letter pi
Selection SELECT Greek letter sigma
Renaming RENAME Greek letter rho
Union UNION Union symbol
Intersection INTERSECTION Intersection symbol
Assignment <- Assignment symbol

Operation My HTML Symbol
Cartesian product X Symbol for Cartesian product
Join JOIN Join symbol
Left outer join LEFT OUTER JOIN Symbol for left outer join
Right outer join RIGHT OUTER JOIN Symbol for right outer join
Full outer join FULL OUTER JOIN Symbol for full outer join
Semijoin SEMIJOIN Semijoin symbol

Example: The relational algebra expression which I would here write as

PROJECTNamn ( SELECTMedlemsnummer <> ( Medlem ) )

should actually be written

Ett relationsalgebrauttryck

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)

enrenamedept
1BillA
2SarahC
3JohnA

Example: The table D (for DEPARTMENT)

dnrdname
AMarketing
BSales
CLegal

SQLResultRelational algebra
select *
from E, D
enrenamedeptdnrdname
1BillAAMarketing
1BillABSales
1BillACLegal
2SarahCAMarketing
2SarahCBSales
2SarahCCLegal
3JohnAAMarketing
3JohnABSales
3JohnACLegal
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:

SQLResultRelational algebra
select *
from E, D
where dept = dnr
enrenamedeptdnrdname
1BillAAMarketing
2SarahCCLegal
3JohnAAMarketing
SELECTdept = dnr (E X D)

or, using the equivalent join operation

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)

nrnamedept
1BillA
2SarahC
3JohnA

Example: The table D (for DEPARTMENT)

nrname
AMarketing
BSales
CLegal

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.)
SQLResultRelational algebra
select *
from E as E(enr, ename, dept),
D as D(dnr, dname)
where dept = dnr
enrenamedeptdnrdname
1BillAAMarketing
2SarahCCLegal
3JohnAAMarketing
(RENAME(enr, ename, dept)(E)) JOINdept = dnr (RENAME(dnr, dname)(D))
select *
from E, D
where dept = D.nr
nrnamedeptnrname
1BillAAMarketing
2SarahCCLegal
3JohnAAMarketing
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)

nrnamesalarydept
1John100A
5Sarah300C
7Tom100A
12AnnenullC

SQLResultRelational algebra
select sum(salary)
from E
sum
500
Fsum(salary)(E)

Note:

  • Duplicates are not eliminated.
  • Null values are ignored.
SQLResultRelational algebra
select count(salary)
from E
Result:
count
3
Fcount(salary)(E)
select count(distinct salary)
from E
Result:
count
2
Fcount(salary)(PROJECTsalary(E))

You can calculate aggregates "grouped by" something:

SQLResultRelational algebra
select sum(salary)
from E
group by dept
deptsum
A200
C300
deptFsum(salary)(E)

Several aggregates simultaneously:

SQLResultRelational algebra
select sum(salary), count(*)
from E
group by dept
deptsumcount
A2002
C3001
deptFsum(salary), count(*)(E)

Standard aggregate functions: sum, count, avg, min, max

Hierarchies

Example: The table E (for EMPLOYEE)

nrnamemgr
1Gretchennull
2Bob1
5Anne2
6John2
3Hulda1
4Hjalmar1
7Usama4

Going up in the hierarchy one level: What's the name of John's boss?

SQLResultRelational algebra
select b.name
from E p, E b
where p.mgr = b.nr
and p.name = "John"
name
Bob
PROJECTbname ([SELECTpname = "John"(RENAMEP(pnr, pname, pmgr)(E))] JOINpmgr = bnr [RENAMEB(bnr, bname, bmgr)(E)])

or, in a less wide-spread notation

PROJECTb.name ([SELECTname = "John"(RENAMEP(E))] JOINp.mgr = b.nr [RENAMEB(E)])

or, step by step

P <- RENAMEP(pnr, pname, pmgr)(E)
B <- RENAMEB(bnr, bname, bmgr)(E)
J <- SELECTname = "John"(P)
C <- J JOINpmgr = bnr B
R <- PROJECTbname(C)

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?

SQLResultRelational algebra
select ob.name
from E p, E b, E ob
where b.mgr = ob.nr
where p.mgr = b.nr
and p.name = "John"
name
Gretchen
PROJECTob.name (([SELECTname = "John"(RENAMEP(E))] JOINp.mgr = b.nr [RENAMEB(E)]) JOINb.mgr = ob.nr [RENAMEOB(E)])

or, step by step

P <- RENAMEP(pnr, pname, pmgr)(E)
B <- RENAMEB(bnr, bname, bmgr)(E)
OB <- RENAMEOB(obnr, obname, obmgr)(E)
J <- SELECTname = "John"(P)
C1 <- J JOINpmgr = bnr B
C2 <- C1 JOINbmgr = bbnr OB
R <- PROJECTobname(C2)

Recursive closure

Both one and two levels up: What's the name of John's boss, and of John's boss' boss?

SQLResultRelational algebra
(select b.name ...)
union
(select ob.name ...)
name
Bob
Gretchen
(...) 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)

enrenamedept
1BillA
2SarahC
3JohnA

Example: The table D (for DEPARTMENT)

dnrdname
AMarketing
BSales
CLegal

List each employee together with the department he or she works at:

SQLResultRelational algebra
select *
from E, D
where edept = dnr

or, using an explicit join
select *
from (E join D on edept = dnr)
enrenamedeptdnrdname
1BillAAMarketing
2SarahCCLegal
3JohnAAMarketing
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?

SQLResultRelational algebra
select dnr, dname, count(*)
from E, D
where edept = dnr
group by dnr, dname

or, using an explicit join
select dnr, dname, count(*)
from (E join D on edept = dnr)
group by dnr, dname
dnrdnamecount
AMarketing2
CLegal1
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:

SQLResultRelational algebra
select *
from (E right outer join D on edept = dnr)
enrenamedeptdnrdname
1BillAAMarketing
2SarahCCLegal
3JohnAAMarketing
nullnullnullBSales
E RIGHT OUTER JOINedept = dnr D
select dnr, dname, count(*)
from (E right outer join D on edept = dnr)
group by dnr, dname
dnrdnamecount
AMarketing2
BSales1
CLegal1
dnr, dnameFcount(*)(E RIGHT OUTER JOINedept = dnr D)
select dnr, dname, count(enr)
from (E right outer join D on edept = dnr)
group by dnr, dname
dnrdnamecount
AMarketing2
BSales0
CLegal1
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

AB
12
34

Example: The table S

BC
45
67

The result of an outer union between R and S:

ABC
12null
345
null67

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:

http://www.databasteknik.se/webbkursen/relalg-lecture/index.html

Friday, November 7, 2008

Prof G said

"If you guys want to work on your light codes after the exams, I will be available during semester holiday. We can go through your codes."

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 told mum.

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

And you will not get them mixed up. Unfortunately my light algorithm is still wrong and my lights aren't coming out right. Submission is in half an hour and I've officially given up. But I want to get it and read up with this:




Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’Æ’

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 am a useless street rat again. I'm out of my wits. I am tired of thinking. I am worried. I am worried I can't stand back up again. The fall of me starts now. We won't have much chance to talk after tonight. Just pray for me?

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

So ironic. Here we are, preaching "a picture worth a thousand words" and no one can explain it better than the drawings on this!

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.

New travel mouse



New Logitech Cord Wrap mouse. The old paw print one died a horrible death of disconnected "tail".

Kewl! My first mobile blog!

Saturday, November 1, 2008

Semester Break

What I have to do...

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

At first, I was quite angry at this Phong fella and all this lighting and shading algorithm. But then I started reading about him in wikipedia...

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)
From: neurobs.com

BASICS DETAILS OF LIGHTING:
http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter05.html

More Texture Mapping

Very good read and easy to understand. Beyond the basics:

http://www.informit.com/articles/article.aspx?p=770639&seqNum=4

Perspective Correct Texture Mapping. Back to basics of U V from X Y
http://easyweb.easynet.co.uk/~mrmeanie/tmap/tmap.htm

Some simple TRIGO maths:

http://www.ies.co.jp/math/java/trig/

! year

Fulfilled 12 months in this company.
Woah. Feels like forever.

How was I like 1 year ago? I cannot remember.
But I know I was not depressed. I know I was all sunshine and rainbow. And very excited.
But... but the people here... They're constantly stern and looked constipated all the time.

Thomad said last week, "You have not smiled in a long time, have you? You are all frowns." I guess... I am not sure. I don't remember who I used to be. I just know who I am now.
I am tired and getting nowhere.
I guess that is what this place do to you.