現(xiàn)代OpenGL學(xué)習(xí)-08

原文地址

Directional Lights

Directional lights are lights that shine in a single, uniform direction. That is, all rays of light are parallel to each other. Pure directional lights do not exist (except maybe lasers?) but they are often used in computer graphics to imitate strong light sources that are very far away, such as the Sun. The Sun radiates light in all directions, like a point light. Over an enormous distance, however, the tiny fraction of light rays that make it to earth appear to be almost parallel.

Unlike point lights, directional lights do not need a position coordinate. A directional light only needs a single 3D vector that represents the direction of all the rays of light. However, the GLSL lighting code in our shader expects every light to have a position. Luckily, we can represent the direction of a directional light with a homogeneous coordinate by setting W=0.

Spotlights


float lightToSurfaceAngle = degrees(acos(dot(-surfaceToLight, normalize(light.coneDirection))));

if(lightToSurfaceAngle > light.coneAngle){

attenuation = 0.0;

}

Notice how the colors from all the lights are added together in our fragment shader. The RGBA values are supposed to be within the 0.0 to 1.0 range, so what happens if there are lots of lights, and the sum ends up being greater than 1.0? The colors would get clamped, and look weird. Also, if the lights are too dim, the whole scene could look basically black, with no detail. High-dynamic-range (HDR) rendering can help to fix these problems.



The human eye adjusts depending on the brightness of what it's looking at. If you are in a dark room for long enough, your pupils dilate to allow more light to reach your retina, which makes the room seem brighter. If you walk outside into bright sunlight, the opposite happens, so that you don't go blind from the intense light. HDR rendering sort of imitates how your eye works, in order to keep the details visible in very dark and very bright scenes. RGB values are allowed to go above 1.0 during lighting calculations, then the values are later rescaled so that they fit nicely within the 0.0–1.0 range.

子面散射


Light doesn't just reflect off of surfaces, it can travel through them too. When light penetrates a surface, it changes the color of that surface. Rendering this color change is called subsurface scattering.

Even though skin looks fairly opaque, subsurface scattering is generally used for realistic rendering of human skin. Without it, skin tends to look like painted plastic.

發(fā)光表面


In our implementation, only lights can illuminate a surface. Some surfaces, however, provide their own illumination, which makes it look like they are glowing. Think of a firefly, glow-in-the-dark stickers, or those weird glowing mushrooms.

Emissive lights are pretty easy to implement in OpenGL. Send an extra color uniform to the shaders, along with the materials texture and shininess, and add that color to the final color. Alternatively, you can send an extra texture instead of a single color.

Normal Mapping 法線紋理


3D meshes have limits to the number of vertices they can contain, due to performance. Making a surface rough or bumpy with geometry can take a lot of vertices, so normal maps are often used instead. Normal maps can be used to make an angular-looking 3D model look less angular, and more realistic.

A normal map is a texture that affects the surface normal. It is like the surface texture that we have implemented, except it contains XYZ vectors instead of RGB colors. The surface normal is an important part of the lighting calculations, and it affects the brightness of each pixel.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市快耿,隨后出現(xiàn)的幾起案子囊陡,更是在濱河造成了極大的恐慌,老刑警劉巖润努,帶你破解...
    沈念sama閱讀 211,376評(píng)論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異示括,居然都是意外死亡铺浇,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,126評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門垛膝,熙熙樓的掌柜王于貴愁眉苦臉地迎上來鳍侣,“玉大人丁稀,你說我怎么就攤上這事∫芯郏” “怎么了线衫?”我有些...
    開封第一講書人閱讀 156,966評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵,是天一觀的道長惑折。 經(jīng)常有香客問我授账,道長,這世上最難降的妖魔是什么惨驶? 我笑而不...
    開封第一講書人閱讀 56,432評(píng)論 1 283
  • 正文 為了忘掉前任白热,我火速辦了婚禮,結(jié)果婚禮上粗卜,老公的妹妹穿的比我還像新娘屋确。我一直安慰自己,他們只是感情好续扔,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,519評(píng)論 6 385
  • 文/花漫 我一把揭開白布攻臀。 她就那樣靜靜地躺著,像睡著了一般纱昧。 火紅的嫁衣襯著肌膚如雪刨啸。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,792評(píng)論 1 290
  • 那天砌些,我揣著相機(jī)與錄音呜投,去河邊找鬼。 笑死存璃,一個(gè)胖子當(dāng)著我的面吹牛仑荐,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播纵东,決...
    沈念sama閱讀 38,933評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼粘招,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了偎球?” 一聲冷哼從身側(cè)響起洒扎,我...
    開封第一講書人閱讀 37,701評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎衰絮,沒想到半個(gè)月后袍冷,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,143評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡猫牡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,488評(píng)論 2 327
  • 正文 我和宋清朗相戀三年胡诗,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,626評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡煌恢,死狀恐怖骇陈,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情瑰抵,我是刑警寧澤你雌,帶...
    沈念sama閱讀 34,292評(píng)論 4 329
  • 正文 年R本政府宣布,位于F島的核電站二汛,受9級(jí)特大地震影響婿崭,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜习贫,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,896評(píng)論 3 313
  • 文/蒙蒙 一逛球、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧苫昌,春花似錦颤绕、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,742評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至袜硫,卻和暖如春氯葬,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背婉陷。 一陣腳步聲響...
    開封第一講書人閱讀 31,977評(píng)論 1 265
  • 我被黑心中介騙來泰國打工帚称, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人秽澳。 一個(gè)月前我還...
    沈念sama閱讀 46,324評(píng)論 2 360
  • 正文 我出身青樓闯睹,卻偏偏與公主長得像,于是被迫代替她去往敵國和親担神。 傳聞我的和親對(duì)象是個(gè)殘疾皇子楼吃,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,494評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,435評(píng)論 0 23
  • 【蘿鼓萱天】20170810 學(xué)習(xí)力踐行記錄 day87 1孩锡,今天萱兒走在路上也是各種能說,現(xiàn)在簡直成了小話癆亥贸。晚...
    眸眸_50ae閱讀 156評(píng)論 0 0
  • 上午去看了我媽一圈躬窜。一個(gè)月沒有過去了。帶了倆孩炕置。買的餃子荣挨。敖的米湯溜族,吃罷飯歇了會(huì),回家了垦沉。 時(shí)不時(shí)看手機(jī),刷新一下...
    南受朝北閱讀 224評(píng)論 0 0
  • 昨天周六仍劈,帶著老媽和兩個(gè)小朋友一起驅(qū)車前往鎮(zhèn)江游玩厕倍。路上說到金山寺,老媽說她好多年沒有去過金山了贩疙,她還記得幾十年前...
    吳佟閱讀 471評(píng)論 0 2