锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品国内视频,一区二区精品,亚洲午夜av在线http://www.shnenglu.com/winmain/archive/2010/03/07/109136.htmlCode KnightCode KnightSun, 07 Mar 2010 11:50:00 GMThttp://www.shnenglu.com/winmain/archive/2010/03/07/109136.htmlhttp://www.shnenglu.com/winmain/comments/109136.htmlhttp://www.shnenglu.com/winmain/archive/2010/03/07/109136.html#Feedback0http://www.shnenglu.com/winmain/comments/commentRss/109136.htmlhttp://www.shnenglu.com/winmain/services/trackbacks/109136.htmlCryEngine緋誨垪寮曟搸鐜╁浠茍涓嶉檶鐢燂紝浠庢渶鍒濈殑鍗曟満娓告垙銆婂宀涙儕欖傘嬨併婂宀涘嵄鏈恒嬪埌鐩墠鐏儹鐨勭綉娓搞婃案鎭掍箣濉斻嬬瓑涓緋誨垪澶т綔閮芥槸鐢辮緋誨垪1鍒?浠e紩鎿庢墦閫狅紝鐩墠錛孋rytek宸茬粡鍙戝竷浜嗚緋誨垪鐨勭涓変唬寮曟搸“CryEngine 3”銆?/p>

銆銆濡備笅鏄渶鏂板叕甯冪殑涓孌?#8220;CryEngine 3”寮曟搸鍒朵綔FPS娓告垙鍦板浘瑙嗛錛屼粠鍒朵綔鍒版紨紺轟粎闀?鍒嗛挓錛岀湅浜嗚浜虹灎鐩粨鑸岋紝鍞忓槝涓嶅凡銆?/p>

Code Knight 2010-03-07 19:50 鍙戣〃璇勮
]]>
Introduction To Octreeshttp://www.shnenglu.com/winmain/archive/2010/02/23/108306.htmlCode KnightCode KnightTue, 23 Feb 2010 13:18:00 GMThttp://www.shnenglu.com/winmain/archive/2010/02/23/108306.htmlhttp://www.shnenglu.com/winmain/comments/108306.htmlhttp://www.shnenglu.com/winmain/archive/2010/02/23/108306.html#Feedback0http://www.shnenglu.com/winmain/comments/commentRss/108306.htmlhttp://www.shnenglu.com/winmain/services/trackbacks/108306.html
Introduction


Hidden surface removal is among the biggest problems when writing a 3D engine.

I struggled with it since the very beginning of writing 3D engines and still have no satisfactory solution to it. The ideal visibility detection scheme would allow unlimited data, extremely dynamic worlds and would have zero overdraw. The first 3d engine which implements these three demands still has to be written.

The Z buffer for example allows dynamical worlds and even crossing faces, but it suffers from immense overdraw. The BSP-tree on the other hand, if well implemented, has no overdraw at all but needs that much pre-processing that dynamical worlds are a definite nono.

It wasn't until recently i first heard of the octree, and I must admit i was struck by it's simplicity. I never actually implemented this structure and therefore I will present no pseudo code at all. This explanation is merely an attempt to make it more clear to people who have never heard of it. Besides, if you really understand the structure, then implementation is a piece of cake.


The Octree Structure


Our virtual world or level is actually nothing more then a soup of polygons. Some of you people might have thrown in a couple of curves and voxels but most of it will be polygons. Here it is:



Fig 1. Our little level.


In the picture I just built a simple level containing no more than 250 polys. Now imagine a cube surrounding the world like in the next image:



Fig. 2. Our little level surrounded by a cube.


Now it isn't hard to see that this cube can be divided into eight smaller cubes, hence the name octree. Take a look at this picture:



Fig 3. Our little level with the surrounding cube subdivided.


Call the larger cube the parent and the smaller cubes the children. On their turn subdivide each children into eight smaller cubes, and you will notice we are creating a tree where each node has eight children.

There is still one little problem left. When should we stop dividing cubes into smaller ones? There are two possible solutions. The first one is to stop when a cube has some size smaller then a fixed number. The second one is more common. You might have noticed that every child has less polygons then it's parent. The trick is to stop subdividing when the number of polygons in a cube is smaller then some fixed number.


Creating The Octree


Trees are recursion, recursion is trees. It is as simple as that. If you have a correct definition of you cubeNode it is very easy to create an octree recursively. First of all you check all polygons against the boundarys of the cube. This is very simple cause these boundaries are all axis aligned. This means that the cube has six plane equations, which are:

  • 1. X = Q.X
  • 2. Y = Q.Y
  • 3. Z = Q.Z

  • 4. X = Q.X + cubeSize
  • 5. Y = Q.Y + cubeSize
  • 6. Z = Q.Z + cubeSize

    Where Q is the position of one corner of the cube. This are very easy equations and the all parent polygons can very easily be checked against them.

    It could occur that a polygon crosses a cube boundary. Again two possible solution are at hand. First of all we could clip the polygon against the cube, which is simple, because of the axis aligned boundarys. On the other hand we could put the polygon in all cubes it is in. This means that some cubes can contain the same polygons. In order to prevent us from drawing one poly more than one time we should have a flag on each polygon which will be set if the poly is drawn for the first time.

    The implementation of an octree is very straight forward. I haven't done it myself yet, but I will soon. It is all matter of recursion. In order to construct a tree, the first thing you should think of is recursion. Whether we are talking about binary trees, quad trees or octrees, it doesnt matter, just build the darn thing recursively. So have a class definition of one cubeNode and put the creation of the tree in it's constructor. In this constructor you will call the constructor itself for smaller cubes.


  • The Purpose Of The Octree


    An octree is actually nothing more then a data structure. It can be used for very different things. It is not only handy for visibility detection but also for collision detection, realtime shadows and many more things. The most important thing to understand about octrees is that if a parent is not important then it's children aren't either. Let's makes this a little bit more clear with an example.

    We will do this in 2d, which therefore resembles a quadtree, but with some imagination it can very easily be extended to 3d. Here we test the cubes (squares) against the viewing frustrum. Take a look at the next picture:



    Fig 4. An octree from the top and a viewing frustrum.


    In this picture a colored square that has one color was dumped without checking it錕絪 children. As you can see some squares had to be checked all the way to the final node, but some large squares could be dumped at once. The colored squares are the ones that are outside the viewing frustrum and the greyscale ones are the one inside the viewing frustrum. As you can see this is actually a worst case scenario because the viewing frustrum crosses the middle of the surrounding square and therefore all the four children have to be checked.

    You could also apply the octree to many other things. Collision detection for example. Just check in which cube your bounding sphere or box is and you will only have to check against those faces. There are many more examples.


    Conclusion


    There is already a lot written about octrees. I tried to give my view on them in the hope somebody might read this. As you can see octrees are way easier to implement than BSP-trees (although some disagree) while offering a better structure. The main point about an octrees is that when a parent is discarded so are it's children. Actually that is all there is to it.

    Code clean, play Goldeneye and go vegetarian.

    Jaap Suter a.k.a .........

    璇戞枃錛?br>1銆佸紩璦錛?span class=English>Introduction錛?br>銆銆闅愰潰縐婚櫎鏄啓3D寮曟搸鏃跺欐渶澶х殑闂涔嬩竴銆?br>銆銆Hidden surface removal is among the biggest problems when writing a 3D engine.

    銆銆鍦ㄦ垜鍐?D寮曟搸鐨勫紑濮嬮樁孌靛氨寮濮嬪拰瀹冩枟浜夊茍涓斾竴鐩存病鏈夋弧鎰忕殑瑙e喅鏂規硶銆傜悊鎯崇殑鍙媯嫻嬫柟妗堝簲褰撳仛鍒板厑璁革紙浣跨敤錛夋棤闄愮殑鏁版嵁銆佸ぇ鍔ㄦ佺殑涓栫晫鍜岄浂閲嶇敾銆傜涓嫻佺殑3D寮曟搸涓鐩村湪榪芥眰瀹炵幇榪?涓姹傘?br>銆銆I struggled with it since the very beginning of writing 3D engines and still have no satisfactory solution to it. The ideal visibility detection scheme would allow unlimited data, extremely dynamic worlds and would have zero overdraw. The first 3d engine which implements these three demands still has to be written.

    銆銆Z buffer鍏佽鍔ㄦ佷笘鐣屼互鍙婂嵆浣挎槸浜ゅ弶鐨勯潰錛屼絾鏄緱蹇嶅彈澶ч噺鐨勯噸鐢匯傚彟涓鏂歸潰錛孊SP鏍戝鏋滆兘澶熻寰堝ソ鐨勫疄鐜幫紝鍙互閬垮厤閲嶇敾錛屼絾鏄畠闇瑕佸ぇ閲忕殑棰勫鐞嗚綆楄屼笖涓嶉傚悎鍔ㄦ佷笘鐣屻?br>銆銆The Z buffer for example allows dynamical worlds and even crossing faces, but it suffers from immense overdraw. The BSP-tree on the other hand, if well implemented, has no overdraw at all but needs that much pre-processing that dynamical worlds are a definite nono.

    銆銆鐩村埌鏈榪戞垜絎竴嬈″惉璇翠簡鍏弶鏍戯紙Octree錛夛紝鎴戝繀欏繪壙璁ゆ垜琚畠鐨勭畝鏄撴?#8220;鐙犵嫚鍦版墦浜嗕竴涓嬪効”銆傛垜浠庢潵娌℃湁鐪熸鍦板幓瀹炵幇榪欎釜緇撴瀯錛屽洜姝ゆ垜涓嶄細鍘誨疄鐜頒竴浜涗唬鐮併傝繖涓В閲婂彧鏄兂璁╀粠娌℃湁鍚榪囧叓鍙夋爲鐨勪漢鎰熷埌鏇存竻鏅版槗鎳傘傚鏋滀綘鐪熺殑浜嗚В浜嗚繖涓粨鏋勶紙Octree錛夛紝瀹炵幇瀹冨彧鏄竴涓皬鎰忔濄?br>銆銆It wasn't until recently i first heard of the octree, and I must admit i was struck by it's simplicity. I never actually implemented this structure and therefore I will present no pseudo code at all. This explanation is merely an attempt to make it more clear to people who have never heard of it. Besides, if you really understand the structure, then implementation is a piece of cake.

    2銆佸叓鍙夋爲鐨勭粨鏋?/strong>錛?span class=English>The Octree Structure錛?br>銆銆鎴戜滑鐨勫疄闄?#8216;涓栫晫’鎴栬呰鏄叧鍗″彧涓嶈繃鏄竴浜涘杈瑰艦銆備綘浠垨璁稿湪鍏朵腑鍔犲叆浜嗕竴浜涙洸闈紙Curves錛夊拰Voxels錛堝湴褰㈠疄鐜版柟娉曠殑涓縐嶏級錛屼絾鏄ぇ澶氭暟涔熼兘鏄杈瑰艦銆?br>銆銆Our virtual world or level is actually nothing more then a soup of polygons. Some of you people might have thrown in a couple of curves and voxels but most of it will be polygons. Here it is:

    鍥?

    銆銆鍥?錛氭垜浠璁$殑灝忓瀷鍏沖崱銆?br>銆銆Fig 1. Our little level.

    銆銆鍦ㄨ繖寮犲浘鐗囦腑鎴戝緩绔嬩簡涓涓笉瓚呰繃250涓杈瑰艦鐨?#8216;鍏沖崱’銆傜幇鍦ㄦ兂璞℃湁涓涓寘鍥翠簡榪欎釜涓栫晫鐨勭珛鏂逛綋錛屽儚涓嬩竴寮犲浘鐗囬偅鏍楓?br>銆銆In the picture I just built a simple level containing no more than 250 polys. Now imagine a cube surrounding the world like in the next image:

    鍥?

    銆銆鍥?錛氭垜浠璁$殑鍏沖崱琚竴涓珛鏂逛綋鎵鍖呭洿鐫銆?br>銆銆Fig. 2. Our little level surrounded by a cube.

    銆銆鐜板湪涓嶉毦鐪嬪嚭榪欎釜绔嬫柟浣撳彲浠ヨ鍏瓑鍒嗕負鍏釜灝忎簺鐨勭珛鏂逛綋錛屾墍浠ユ墠鍙叓鍙夋爲銆傜湅鐪嬭繖寮犲浘錛?br>銆銆Now it isn't hard to see that this cube can be divided into eight smaller cubes, hence the name octree. Take a look at this picture:

    鍥?

    銆銆鍥?錛氬鍥寸粫鐫鍏沖崱鐨勭珛鏂逛綋榪涜緇嗗垎銆?br>銆銆Fig 3. Our little level with the surrounding cube subdivided.

    銆銆澶х偣鍎跨殑榪欎釜绔嬫柟浣撹鍙仛‘鐖朵翰’灝忎簺鐨勭珛鏂逛綋鍙仛‘瀛╁瓙’銆傚鐞嗘瘡涓?#8216;瀛╁瓙’鐨勬椂鍊欙紝鍐嶄負鏇村皬鐨勫叓涓珛鏂逛綋錛屼綘浼氬彂鐜版垜浠湪鍒涘緩涓涓瘡涓妭鐐規湁鍏釜瀛愯妭鐐癸紙瀛╁瓙錛夌殑鏍戙?br>銆銆Call the larger cube the parent and the smaller cubes the children. On their turn subdivide each children into eight smaller cubes, and you will notice we are creating a tree where each node has eight children.

    銆銆榪樻湁涓涓皬闂銆備粈涔堟椂鍊欐垜浠緇撴潫緇嗗垎鐨勮繃紼嬪憿錛熸湁涓や釜鍙鐨勮В鍐蟲柟娉曘傜涓涓槸褰撲竴涓珛鏂逛綋鐨勫昂瀵稿凡緇忔瘮涓涓瀹氱殑鍥哄畾鍊煎皬鐨勬椂鍊欍傜浜屼釜鏇存櫘閫氥備綘鍙互娉ㄦ剰鍒版瘡涓?#8216;瀛╁瓙’閮芥瘮浠栫殑‘鐖朵翰’鏈夋洿灝戠殑澶氳竟褰€傝繖灝辨槸璇達細褰撲竴涓珛鏂逛綋鍖呭惈鐨勫杈瑰艦鏁伴噺姣斾竴涓瀹氱殑鍥哄畾鍊煎皯鐨勬椂鍊欏仠姝㈢粏鍒嗐?br>銆銆There is still one little problem left. When should we stop dividing cubes into smaller ones? There are two possible solutions. The first one is to stop when a cube has some size smaller then a fixed number. The second one is more common. You might have noticed that every child has less polygons then it's parent. The trick is to stop subdividing when the number of polygons in a cube is smaller then some fixed number.

    3銆佸垱寤哄叓鍙夋爲錛?span class=English>Creating The Octree錛?br>銆銆鏍戞槸閫掑綊鐨勶紝閫掑綊鐨勬槸鏍戙傚氨閭d箞綆鍗曘傚鏋滀綘姝g‘鐨勫畾涔変簡浣犵殑绔嬫柟浣撹妭鐐癸紝閭d箞閫掑綊鍦板垱寤轟竴涓叓鍙夋爲鏄緢瀹規槗鐨勩傞鍏堬紝媯鏌ユ墍鏈夌殑澶氳竟褰紙澶氳竟褰笂浣嶇疆鏈澶栭潰鐨勭偣浣滀負錛夌珛鏂逛綋鐨勮竟鐣屻傝繖寰堢畝鍗曞洜涓烘墍鏈夎竟鐣岄兘鏄拰鍧愭爣杞村鍏剁殑銆傝繖鎰忓懗鐫绔嬫柟浣撴湁鍏釜騫抽潰鏂圭▼錛屽垎鍒槸錛?br>銆銆Trees are recursion, recursion is trees. It is as simple as that. If you have a correct definition of you cubeNode it is very easy to create an octree recursively. First of all you check all polygons against the boundarys of the cube. This is very simple cause these boundaries are all axis aligned. This means that the cube has six plane equations, which are:
    • 1. X = Q.X
    • 2. Y = Q.Y
    • 3. Z = Q.Z

    • 4. X = Q.X + cubeSize
    • 5. Y = Q.Y + cubeSize
    • 6. Z = Q.Z + cubeSize
    銆銆鍦ㄨ繖閲孮鏄珛鏂逛綋涓涓《瑙掔殑浣嶇疆銆傝繖鏄釜寰堢畝鍗曠殑鏂圭▼錛岃屼笖鎵鏈夌殑鐖朵翰澶氳竟褰㈠彲浠ュ鏄撳湴鐢ㄨ繖浜涙柟紼嬫潵媯嫻嬨?br>銆銆WhereQ is the position of one corner of the cube. This are very easy equations and the all parent polygons can very easily be checked against them.

    銆銆涓涓杈瑰艦絀胯繃浜嗕竴涓珛鏂逛綋杈圭晫榪欐牱鐨勪簨鎯呮槸浼氬彂鐢熺殑銆傚啀涓嬈★紝鏈変袱涓В鍐蟲柟妗堝彲鐢ㄣ傞鍏堟垜浠彲浠ユ部鐫绔嬫柟浣撳壀鍒囪繖涓杈瑰艦錛岃繖涔熸槸寰堢畝鍗曠殑錛屽洜涓猴紙绔嬫柟浣撶殑錛夎竟鐣屾槸涓庡潗鏍囪醬瀵歸綈鐨勩傝繕鏈夛紝鎴戜滑鍙互鎶婁竴涓杈瑰艦鏀懼湪鎵鏈夊畠鎵鍦ㄧ殑绔嬫柟浣撻噷闈€傝繖灝辨剰鍛崇潃涓浜涚珛鏂逛綋鍙兘鍖呭惈鐫鍚屼竴涓杈瑰艦銆備負浜嗛槻姝㈤噸鐢諱竴涓杈瑰艦錛屾垜浠簲褰撳湪姣忎竴涓杈瑰艦涓婂仛涓涓爣璁幫紝褰撳杈瑰艦絎竴嬈¤鐢葷殑鏃跺欙紝璁劇疆榪欎釜鏍囪錛堝綋鐒剁敾涔嬪墠涔熻媯鏌ヨ繖涓爣璁板暒錛屼笉榪囪偗瀹氬獎鍝嶆晥鐜囥?br>銆銆It could occur that a polygon crosses a cube boundary. Again two possible solution are at hand. First of all we could clip the polygon against the cube, which is simple, because of the axis aligned boundarys. On the other hand we could put the polygon in all cubes it is in. This means that some cubes can contain the same polygons. In order to prevent us from drawing one poly more than one time we should have a flag on each polygon which will be set if the poly is drawn for the first time.

    銆銆瀹炵幇涓涓叓鍙夋爲鏄緢綆鍗曟槑浜嗙殑浜嬫儏錛屾垜榪樻病鏈夎嚜宸卞仛榪囷紝浣嗘槸鎴戜笉涔呬細鍋氱殑銆傚彧涓嶈繃鏄掑綊鑰屽凡銆備負浜嗘瀯閫犱竴涓爲錛岀涓浠朵綘璇ユ兂鐨勪簨鎯呭氨鏄掑綊銆備笉綆℃垜浠璁虹殑鏄簩鍙夈佸洓鍙夎繕鏄叓鍙夋爲錛岄兘娌℃湁鍖哄埆錛岄兘鏄掑綊鐨勬柟娉曘傛墍浠ュ畾涔変竴涓珛鏂逛綋鑺傜偣鐨勭被錛屽湪鏋勯犲嚱鏁伴噷闈㈠啓涓婂垱寤烘爲鐨勪唬鐮併傚湪榪欎釜鏋勯犲嚱鏁伴噷闈紝浣犱細璋冪敤鍒版洿灝忕珛鏂逛綋鐨勬瀯閫犲嚱鏁般?br>銆銆The implementation of an octree is very straight forward. I haven't done it myself yet, but I will soon. It is all matter of recursion. In order to construct a tree, the first thing you should think of is recursion. Whether we are talking about binary trees, quad trees or octrees, it doesnt matter, just build the darn thing recursively. So have a class definition of one cubeNode and put the creation of the tree in it's constructor. In this constructor you will call the constructor itself for smaller cubes.

    4銆佸叓鍙夋爲鐨勭敤閫?/strong>錛?span class=English>The Purpose Of The Octree錛?br>銆銆涓涓叓鍙夋爲瀹為檯涓婂氨鏄竴涓暟鎹粨鏋勩傚畠鍙互鐢ㄥ仛涓嶅悓鐨勪簨鎯呫備笉浠呬粎瀵逛簬‘鍙媯嫻?#8217;鏉ヨ寰堟柟渚匡紝榪樻湁瀹炴椂闃村獎浠ュ強鍏跺畠鏂歸潰銆傜悊瑙e叓鍙夋爲榪囩▼涓渶閲嶈鐨勪簨鎯呮槸錛氬鏋滀竴涓?#8216;鐖朵翰’鑺傜偣鏄?#8216;娌$敤’鐨勶紝閭d箞浠栫殑‘瀛╁瓙’鑺傜偣涔熷悓鏍楓傝鎴戜滑涓句釜渚嬪瓙璁╁畠鏇存竻妤氥?br>銆銆An octree is actually nothing more then a data structure. It can be used for very different things. It is not only handy for visibility detection but also for collision detection, realtime shadows and many more things. The most important thing to understand about octrees is that if a parent is not important then it's children aren't either. Let's makes this a little bit more clear with an example.

    銆銆鎴戜滑鐢?D鏉ヨ〃紺哄畠錛岃繖鏍峰氨寰堝儚涓涓洓鍙夋爲錛屼絾鏄兂璞′竴涓嬪畠涔熷彲浠ュ緢瀹規槗鐨勬墿灞曞埌3D涓娿傚湪榪欓噷鎴戜滑娌跨潃瑙嗛敟錛?span class=English>viewing frustrum錛夋嫻嬬珛鏂逛綋錛堟鏂瑰艦錛夈?br>銆銆We will do this in 2d, which therefore resembles a quadtree, but with some imagination it can very easily be extended to 3d. Here we test the cubes (squares) against the viewing frustrum. Take a look at the next picture:

    鍥?

    銆銆鍥?錛氶《閮ㄨ閿ュ唴鐨勫叓鍙夋爲銆?br>銆銆Fig 4. An octree from the top and a viewing frustrum.

    銆銆鍦ㄨ繖涓浘鐗囦腑錛屽僵鑹茬殑姝f柟褰㈡槸娌℃湁錛堟病蹇呰錛夋嫻嬪畠鐨?#8216;瀛╁瓙’鐨勩傚氨鍍忎綘鐪嬪埌鐨勯偅鏍蜂竴浜涙鏂瑰艦錛堢伆鑹茬殑涓浜涳級琚嫻嬬洿鍒版渶緇堣妭鐐癸紝浣嗘槸涓浜涘ぇ鐨勬鏂瑰艦鍙娑備簡涓縐嶉鑹層傞偅浜涘僵鑹茬殑姝f柟褰㈠氨鏄秴鍑轟簡瑙嗛敟鑼冨洿鐨勶紝鐏拌壊鐨勬槸鍦ㄨ閿ヨ寖鍥村唴鐨勩傚氨鍍忎綘鐪嬪埌鐨勯偅鏍鳳紝榪欑‘瀹炴槸鏈緋熺硶鐨勪竴縐嶆儏鍐碉紝鍥犱負瑙嗛敟絀胯繃浜嗗寘鍥存鏂瑰艦鐨勪腑澶紝鎵浠ユ墍鏈夌殑鍥涗釜‘瀛╁瓙’閮藉緱琚嫻嬨?br>銆銆In this picture a colored square that has one color was dumped without checking it鎶?children. As you can see some squares had to be checked all the way to the final node, but some large squares could be dumped at once. The colored squares are the ones that are outside the viewing frustrum and the greyscale ones are the one inside the viewing frustrum. As you can see this is actually a worst case scenario because the viewing frustrum crosses the middle of the surrounding square and therefore all the four children have to be checked.

    銆銆浣犲彲浠ュ簲鐢ㄥ叓鍙夋爲鍒板緢澶氬埆鐨勫湴鏂廣備緥濡傜鎾炴嫻嬨傚彧媯鏌ヤ綘鐨勭鎾炵悆鎴栬呯鎾炵洅瀛愭墍鍦ㄧ殑绔嬫柟浣擄紝鑰屼笖鍙渶瑕佹嫻嬮偅浜涢潰銆傝繕鏈夋洿澶氱殑渚嬪瓙銆?br>銆銆You could also apply the octree to many other things. Collision detection for example. Just check in which cube your bounding sphere or box is and you will only have to check against those faces. There are many more examples.

    5銆佺粨璁?/strong>錛?span class=English>Conclusion錛?br>銆銆鍏充簬鍏弶鏍戝凡緇忓啓浜嗗緢澶氫簡銆傛垜璁炬硶琛ㄨ堪鑷繁瀵瑰畠鐨勭湅娉曪紝騫朵笖甯屾湜鏈変漢浼氳鍒板畠銆傚氨鍍忎綘鐪嬪埌鐨勯偅鏍鳳紝褰撴彁渚涘ソ鐨勭粨鏋勭殑鏃跺欙紝鍏弶鏍戞瘮BSP鏍戞洿瀹規槗瀹炵幇錛堟湁浜烘寔寮傝錛夈備富瑕佺殑涓鐐規槸錛氬綋涓涓?#8216;鐖朵翰’鑺傜偣琚涪寮冪殑鏃跺欙紝浠栫殑‘瀛╁瓙’鑺傜偣涔熷悓鏍瘋涓㈠純銆傚疄闄呬笂榪欏氨鏄叏閮ㄣ?br>銆銆There is already a lot written about octrees. I tried to give my view on them in the hope somebody might read this. As you can see octrees are way easier to implement than BSP-trees (although some disagree) while offering a better structure. The main point about an octrees is that when a parent is discarded so are it's children. Actually that is all there is to it.
    銆銆Code clean, play Goldeneye and go vegetarian. Jaap Suter a.k.a .........



    ]]>
    鍥懼艦瀛﹀涔犵瑪璁?(cel-shading鍒嗘瀽) http://www.shnenglu.com/winmain/archive/2010/02/23/108304.htmlCode KnightCode KnightTue, 23 Feb 2010 13:14:00 GMThttp://www.shnenglu.com/winmain/archive/2010/02/23/108304.htmlhttp://www.shnenglu.com/winmain/comments/108304.htmlhttp://www.shnenglu.com/winmain/archive/2010/02/23/108304.html#Feedback0http://www.shnenglu.com/winmain/comments/commentRss/108304.htmlhttp://www.shnenglu.com/winmain/services/trackbacks/108304.html鍙傜湅word鏂囨。
    // -------------------------------

    // Cel Shading Section

    // -------------------------------

    vertex_program Ogre/CelShadingVP cg

    {

        source Example_CelShading.cg

        entry_point main_vp

        profiles vs_1_1 arbvp1

     

        default_params

        {

            param_named_auto lightPosition light_position_object_space 0        param_named_auto eyePosition camera_position_object_space

            param_named_auto worldViewProj worldviewproj_matrix

            param_named shininess float 10

        }

    }

     

    fragment_program Ogre/CelShadingFP cg

    {

        source Example_CelShading.cg

        entry_point main_fp

        profiles ps_1_1 arbfp1 fp20

    }

     

     

    material Examples/CelShading

    {

        technique

        {

            pass

            {

                vertex_program_ref Ogre/CelShadingVP

                {

                    // map shininess from custom renderable param 1

                    param_named_auto shininess custom 1

    // 緇堜簬鐭ラ亾param_named_auto絎笁涓弬鏁扮殑浣滅敤浜嗭紝鐢ㄤ簬緇欑▼搴忎腑璧嬪肩殑绱㈠紩

    sub->setCustomParameter(CUSTOM_SHININESS, Vector4(10.0f, 0.0f, 0.0f, 0.0f)); CUSTOM_SHININESS == 1

                }

                fragment_program_ref Ogre/CelShadingFP

                {

                    // map diffuse from custom renderable param 2

                    param_named_auto diffuse custom 2

                    // map specular from custom renderable param 2

                    param_named_auto specular custom 3

                }

                texture_unit

                {

                    texture cel_shading_diffuse.png 1d

                    tex_address_mode clamp

                    filtering none

                }

                texture_unit

                {

                    texture cel_shading_specular.png 1d

                    tex_address_mode clamp

                    filtering none

                }

                texture_unit

                {

                    texture cel_shading_edge.png 1d

                    tex_address_mode clamp

                    filtering none

                }

            }

        }

       

    }

     

     

    ////////////////////////////////////////////////////////////////////////////////////涓嬮潰鏄?span>cg鏂囦歡

    ////////////////////////////////////////////////////////////////////////////////

     

    /* Cel shading vertex program for single-pass rendering

       In this program, we want to calculate the diffuse and specular

       ramp components, and the edge factor (for doing simple outlining)

       For the outlining to look good, we need a pretty well curved model.

    */

    void main_vp(float4 position    : POSITION,

                 float3 normal      : NORMAL,[U1] 

                 // outputs

                 out float4 oPosition    : POSITION,

                 out float diffuse     : TEXCOORD0,

                 out float specular    : TEXCOORD1,

                 out float edge        : TEXCOORD2,[U2] 

                 // parameters

                 uniform float3 lightPosition, // object space錛氫笘鐣屽潗鏍囩郴

                 uniform float3 eyePosition,   // object space

                 uniform float4 shininess,

                 uniform float4x4 worldViewProj)

    {

        // calculate output position

        oPosition = mul(worldViewProj, position);

     

        // calculate light vector

        float3 N = normalize(normal);

        float3 L = normalize(lightPosition - position.xyz);

       

        // Calculate diffuse component

        diffuse = max(dot(N, L) , 0);

     

        // Calculate specular component

        float3 E = normalize(eyePosition - position.xyz);

        float3 H = normalize(L + E);

        specular = pow(max(dot(N, H), 0), shininess[U3] );

        // Mask off specular if diffuse is 0

        if (diffuse == 0) specular = 0;

     

        // Edge detection, dot eye and normal vectors

        edge = max(dot(N, E), 0); // 娉曠嚎涓庤綰垮鉤琛岀殑鐐硅涓烘槸鏍囪繙錛岀粰浜堥粦鑹叉矡杈?/span>

    }

     

    void main_fp(float diffuseIn    : TEXCOORD0,

                 float specularIn   : TEXCOORD1,

                 float edge         : TEXCOORD2,

    [U4]            

                 out float4 colour : COLOR,

                 

                 uniform float4 diffuse,

                 uniform float4 specular,

                 

                 uniform sampler1D diffuseRamp,

                 uniform sampler1D specularRamp,

                 uniform sampler1D edgeRamp[U5] )

    {

        // Step functions from textures

        diffuseIn = tex1D(diffuseRamp, diffuseIn).x;

        specularIn = tex1D(specularRamp, specularIn).x;

        edge = tex1D(edgeRamp, edge).x;

     

        colour = edge * ((diffuse * diffuseIn) +

                        (specular * specularIn));

    }


     [U1]榪欓噷鏄?/span>GPU浼犺繘鏉ョ殑錛?/span>POSITION錛氶《鐐瑰潗鏍囷紝NORMAL娉曠嚎錛屽幓鐪嬬湅hlsl鐨勮鎰忓畾涔?/span>

     [U2]out閮芥槸杈撳嚭鍙傛暟錛屾敼鍙樹粬浠殑鍊艱緭鍑轟箣鍚庤ps鑾峰彇

     [U3]鍗?/span>m涓嬫爣gls錛屼負鏉愭枡鐨勫厜娉藉害

     [U4]寰楀埌鐨勬槸vs涓?/span>out鍑烘潵鐨勫?/span>

     [U5]浠?/span>texture_unit涓緱鍒幫紝欏哄簭鏍規嵁瀹氫箟鐨勯『搴?/span>texture_unit

                         {

                                texture cel_shading_diffuse.png 1d

                                tex_address_mode clamp

                                filtering none

                         }

                         texture_unit

                         {

                                texture cel_shading_specular.png 1d

                                tex_address_mode clamp

                                filtering none

                         }

                         texture_unit

                         {

                                texture cel_shading_edge.png 1d

                                tex_address_mode clamp

                                filtering none

                         }



    ]]>
    [鍘焆鍥懼艦瀛﹀涔犵瑪璁?(鍏夌収鐫鑹叉ā鍨?http://www.shnenglu.com/winmain/archive/2010/02/23/108303.htmlCode KnightCode KnightTue, 23 Feb 2010 13:13:00 GMThttp://www.shnenglu.com/winmain/archive/2010/02/23/108303.htmlhttp://www.shnenglu.com/winmain/comments/108303.htmlhttp://www.shnenglu.com/winmain/archive/2010/02/23/108303.html#Feedback0http://www.shnenglu.com/winmain/comments/commentRss/108303.htmlhttp://www.shnenglu.com/winmain/services/trackbacks/108303.html涓錛屽洓縐嶅厜鐓х潃鑹叉ā鍨?/span>

    1錛屽浐瀹氱潃鑹?span>(constant shading)

        鍥哄畾鐫鑹叉牴鏈笉鑰冭檻鍏夌収妯″瀷錛屽彧鏄牴鎹杈瑰艦棰滆壊鐨勭儲寮曟垨RGB鍊肩粯鍒跺畠銆?/span>

    PS:鍩烘湰宸茬粡琚父鎴忔窐姹幫紝澶畝鍗曠殑鐫鑹叉ā鍨?/span>

    2錛屾亽瀹氱潃鑹詫紙flat shding錛?/span>

        瀵逛簬姣忎釜澶氳竟褰㈠彧闇瑕佹牴鎹竴涓《鐐規墽琛屽厜鐓ц綆楋紝鐒跺悗鏍規嵁璁$畻緇撴灉瀵規暣涓杈瑰艦榪涜鐫鑹詫紝榪欏氨鏄亽瀹氱潃鑹詫紝涔熺О涓洪潰鐗囩潃鑹?span>(faceted shading)錛屽浜庣敱騫抽潰緇勬垚鐨勫杈瑰艦榪欑鏂規硶鏄彲琛岀殑錛堢珛鏂逛綋錛夛紝浣嗗浜庣敱鏇查潰緇勬垚鐨勫杈瑰艦榪欑鐫鑹叉柟寮忎細鍑虹幇闈炰綘鎯寵鐨勭粨鏋?span>.

    3錛?span>Gougraud鐫鑹?/span>

    銆銆瀵逛簬欏剁偣涔嬮棿鐨勫儚绱犲奸噰鐢ㄤ袱涓《鐐逛箣闂寸殑鎻掑艱綆楁潵紜畾錛岄《鐐逛箣闂寸殑棰滆壊榪囨浮鑷劧錛屾覆鏌撴晥鏋滀篃姣旇緝騫蟲粦,娌℃湁鎭掑畾鐫鑹查偅鏍風獊鍏銆?/span>

    4錛?span>Phong鐫鑹?/span>

    銆銆涓?span>Gougraud鐫鑹茬被浼鹼紝涓嶈繃浼樼偣鍦ㄤ簬榪樺姣忎釜鍍忕礌榪涜浜嗘硶綰跨殑鎻掑鹼紝瀵逛簬闀滈潰鍙嶅皠鏁堟灉姣旇緝濂姐?/span>



    ]]>
    銆愯漿璐淬戜簡瑙e嚬鍑告槧灝凚ump Map鎶鏈殑鍐呭箷 http://www.shnenglu.com/winmain/archive/2010/02/23/108301.htmlCode KnightCode KnightTue, 23 Feb 2010 13:09:00 GMThttp://www.shnenglu.com/winmain/archive/2010/02/23/108301.htmlhttp://www.shnenglu.com/winmain/comments/108301.htmlhttp://www.shnenglu.com/winmain/archive/2010/02/23/108301.html#Feedback0http://www.shnenglu.com/winmain/comments/commentRss/108301.htmlhttp://www.shnenglu.com/winmain/services/trackbacks/108301.html
    涓轟簡灝婇噸鍘熶綔鑰咃紝鍚屾椂涔熸槸涓轟簡璇昏呰兘澶熷鐓у師鏂囷紝鍦ㄦ璐村嚭鍘熸枃鍦板潃錛?br>http://freespace.virgin.net/hugo.elias/graphics/x_polybm.htm
    鍑瑰嚫鏄犲皠Bump Mapping

    銆銆鍑瑰嚫鏄犲皠鍜岀汗鐞嗘槧灝勯潪甯哥浉浼箋傜劧鑰岋紝綰圭悊鏄犲皠鏄妸棰滆壊鍔犲埌澶氳竟褰笂錛岃屽嚬鍑告槧灝勬槸鎶婄矖緋欎俊鎭姞鍒板杈瑰艦涓娿傝繖鍦ㄥ杈瑰艦鐨勮瑙変笂浼氫駭鐢熷緢鍚稿紩浜虹殑鏁堟灉銆傛垜浠彧闇瑕佹坊鍔犱竴鐐逛俊鎭埌鏈潵闇瑕佷嬌鐢ㄥぇ閲忓杈瑰艦鐨勭墿浣撲笂銆傞渶瑕佹敞鎰忕殑鏄繖涓墿浣撴槸騫崇殑錛屼絾鏄畠鐪嬭搗鏉ュ嵈鏄矖緋欎笉騫崇殑銆傝鎴戜滑鏉ョ湅鐪嬪乏杈圭殑閭d釜绔嬫柟浣撱傚鏋滀綘寰堣繎鍦拌瀵熷畠鏃訛紝浣犱細鍙戠幇瀹冧笂闈㈢殑寰堝緇嗚妭銆傚畠鐪嬭搗鏉ュソ鍍忔槸鐢辨垚鍗冧笂涓囦釜澶氳竟褰㈡瀯鎴愮殑錛屽叾瀹炲畠鍙槸鐢?涓煩褰㈡瀯鎴愩備綘鎴栬浼氶棶錛?#8220;榪欏拰綰圭悊鏄犲皠鏈変粈涔堜笉鍚岋紵”瀹冧滑鐨勪笉鍚屼箣澶勫湪浜庘斺斿嚬鍑告槧灝勬槸涓縐嶈礋璐e厜鏂瑰悜鐨勭汗鐞嗘槧灝勩?br>
    錛?錛夊嚬鍑告槧灝勮儗鍚庣殑鍘熺悊

    銆銆璁╂垜浠潵鐪嬬湅涓涓矖緋欑殑琛ㄩ潰銆?br>銆銆銆銆

    銆銆浠庤繙澶勭湅錛屼綘鍒ゆ柇榪欎釜鐗╀綋鏄矖緋欑殑鐨勫敮涓璇佹嵁鏄湪瀹冭〃闈笂涓嬬殑浜害鏈夋敼鍙樸備綘鐨勫ぇ鑴戣兘澶熻幏寰楄繖浜涗寒鏆椾笉涓鐨勫浘妗堜俊鎭紝鐒跺悗鍒ゆ柇鍑哄畠浠槸琛ㄩ潰涓湁鍑瑰嚫鐨勯儴浣嶃?/p>

    銆銆閭d箞浣犱篃璁鎬細闂細鎴戞槸鎬庝箞鐭ラ亾鍝簺鐐硅浜紝鍝簺鐐硅鏆楀憿錛熻繖涓嶉毦銆傜粷澶у鏁頒漢鐢熸椿鍦ㄨ繖鏍蜂竴縐嶇幆澧冧笅鈥斺旇繖涓幆澧冪殑澶у鏁板厜婧愭潵鑷笂鏂癸紙璇戣呮敞錛氭瘮濡傜櫧澶╀富瑕佺殑鍏夋潵鑷お闃籌紝澶滄櫄涓昏鐨勫厜鏉ヨ嚜澶╄姳鏉夸笂鐨勬棩鍏夌伅錛夈傛墍浠ュ悜涓婂劇殑鍦版柟灝變細鏇翠寒錛岃屽悜涓嬪劇殑鍦版柟灝變細鏇存殫銆傛墍浠ヨ繖縐嶇幇璞′嬌浣犵殑鐪肩潧鐪嬪埌涓涓墿浣撲笂浜殫鍖哄煙鏃訛紝鍙互鍒ゆ柇鍑哄畠鐨勫嚬鍑告儏鍐點傜浉瀵逛寒鐨勫潡琚垽鏂槸闈㈠悜涓婄殑錛岀浉瀵規殫鐨勫潡琚垽鏂槸闈㈠悜涓嬬殑銆傛墍浠ユ垜鍙渶瑕佺粰鐗╀綋涓婄殑綰挎潯綆鍗曞緱涓婅壊銆?br>
    銆銆濡傛灉浣犳兂瑕佹洿澶氱殑璇佹嵁錛岃繖閲岃繕鏈変竴騫呭嚑涔庣浉鍚岀殑鍥撅紝涓嶅悓浜庡墠鐨勬槸瀹冩棆杞簡180搴︺傛墍浠ュ畠鏄墠涓騫呭浘鍊掕漿鐨勫浘鍍忋傞偅浜涘厛鍓嶇湅璧鋒潵鏄嚬榪涘幓鐨勫尯鍩燂紝鐜板湪鐪嬭搗鏉ユ槸鍑稿嚭鏉ョ殑浜嗐?br>銆銆銆銆

    銆銆榪欎釜鏃跺欎綘鐨勫ぇ鑴戝茍娌℃湁琚畬鍏ㄦ楠楋紝浣犺剳涓瓨鐣欑殑瑙嗚鍗拌薄浣夸綘浠嶇劧鏈夎兘鍔涘垽鏂嚭榪欐槸鍓嶄竴騫呭浘錛屽彧鏄畠鐨勫厜婧愬彉浜嗭紝鏄粠灝忓線涓婄収鐨勪綘鐨勫ぇ鑴戝彲鑳藉己榪у湴鍒ゆ柇鍑哄畠鏄涓騫呭浘銆備簨瀹炰笂錛屼綘鍙濮嬬粓鐩潃瀹冿紝騫朵笖鍔姏鍦版兂鍍忕潃鍏夋槸浠庡彸涓嬫柟鍚戠収灝勭殑錛屼綘灝變細鐞嗚В瀹冩槸鍑圭殑錛堣瘧鑰呮敞錛氬洜涓烘棩甯哥敓媧葷殑涔犳儻錛屼綘浼氬緢瀹規槗鎶婅繖浜涘浘褰㈠垽鏂垚鍑稿嚭鐨勫浘褰紝浣嗘槸鍥犱負鏈変簡涓婁竴騫呭鐓у浘鐨勫嵃璞★紝浣犲彲鑳芥墠浼氱壒鍒敞鎰忓埌榪欎簺鍥懼潡鍏跺疄榪樻槸鍑瑰叆鐨勶紝鍙槸鍒ゆ柇鏂規硶涓嶇鍚堟垜浠棩甯哥敓媧諱範鎯紝鍥犱負榪欐椂澶у鏁板厜涓嶆槸浠庝笂鏂圭収灝勶紝鑰屾槸浠庝笅寰涓婄収灝勶級銆?br>
    錛?錛変粈涔堟槸鍑瑰嚫鍥撅紙Bump Map錛?/strong>

    銆銆鍑瑰嚫鍥懼拰綰圭悊鍥懼緢鐩鎬技銆備絾鏄笉鍚岀殑鏄紝鍑瑰嚫鍥懼寘鍚殑涓嶆槸棰滆壊淇℃伅錛岃屾槸鍑瑰嚫淇℃伅銆傛渶閫氬父鐨勬柟娉曟槸閫氳繃瀛樺偍楂樺害鍊煎疄鐜般傛垜浠鐢ㄥ埌涓涓伆鑹茬殑綰圭悊鍥撅紝鐏拌壊鐨勪寒搴︿綋鐜板嚭姣忎釜鐐瑰垎鍒嚫鍑哄灝戯紙瑙佸彸鍥撅級銆傝繖灝辨槸涓涓潪甯告柟渚跨殑淇濆瓨鍑瑰嚫鍥劇殑鏂規硶錛岃屼笖榪欑鍥懼緢瀹規槗鍒朵綔銆傝繖鍓浘鍏蜂綋鍙堟槸鎬庢牱琚覆鏌撳櫒浣跨敤鐨勫憿錛熶綘鎺ョ潃寰涓嬬湅灝變細鏄庣櫧浜嗐?br>
    銆銆褰撶劧錛屼綘騫朵笉涓瀹氳鎶婅嚜宸卞眬闄愪簬榪欎簺綆鍗曠殑鍥懼艦錛屼綘鍙互鎵╁睍錛岀敤瀹冩潵鍋氭湪鏉愶紝鍋氱煶澶達紝鍋氳劚浜嗘紗鐨勫闈紝鍋氫換浣曚綘鎯沖仛鐨勭墿浣撱?br>銆銆銆銆

    錛?錛夐偅涔堝畠鏄庝箞宸ヤ綔鐨?/strong>

    銆銆鍑瑰嚫鏄犲皠鏄ˉ鑹叉覆鏌撴妧鏈紙Phong Shading Technique錛夌殑涓欏規墿灞曪紝鍙槸鍦ㄨˉ鑹叉覆鏌撻噷錛屽杈瑰艦琛ㄩ潰涓婄殑娉曠嚎灝嗚鏀瑰彉錛岃繖涓悜閲忕敤鏉ヨ綆楄鐐圭殑浜害銆傚綋浣犲姞鍏ヤ簡鍑瑰嚫鏄犲皠錛屾硶綰垮悜閲忎細鐣ュ井鍦版敼鍙橈紝鎬庝箞鏀瑰彉鍒欏熀浜庡嚬鍑稿浘銆傛敼鍙樻硶綰垮悜閲忓氨浼氭敼鍙樺杈瑰艦鐨勭偣鐨勯鑹插箋傚氨榪欎箞綆鍗曘?br>
    銆銆鐜板湪錛屾湁鍑犵鏂規硶鏉ヨ揪鍒拌繖涓洰鐨勶紙璇戣呮敞錛氳繖涓洰鐨勬寚鏀瑰彉娉曠嚎鍚戦噺錛夈傛垜騫舵病鏈夊疄闄呯紪鍐欒ˉ鑹叉覆鏌撳拰鍑瑰嚫鏄犲皠鐨勭▼搴忥紝浣嗘槸鎴戝湪榪欓噷灝嗕粙緇嶄竴縐嶆垜鍠滄鐨勬柟娉曟潵瀹炵幇錛?br>
    銆銆鐜板湪鎴戜滑闇瑕佸皢鍑瑰嚫鍥句腑鐨勯珮搴︿俊鎭漿鎹㈡垚琛ヨ壊娓叉煋鐢ㄥ埌鐨勬硶綰跨殑璋冭妭淇℃伅銆傝繖涓仛璧鋒潵涓嶉毦錛屼絾鏄В閲婅搗鏉ユ瘮杈冭垂鍔層?br>
    銆銆銆銆
    銆銆濂界殑錛屾垜浠幇鍦ㄥ皢鍑瑰嚫浣嶅浘鐨勪俊鎭漿鎹㈡垚涓浜涘皬鍚戦噺鈥斺斾竴涓悜閲忓搴斾簬涓涓偣銆傝鐪嬪乏杈逛竴鍓斁澶х殑鍑瑰嚫鍥俱傜浉瀵逛寒鐨勭偣姣旂浉瀵規殫鐨勭偣鏇翠負鍑稿嚭銆傜湅娓呮浜嗗悧錛熺幇鍦ㄨ綆楁瘡涓偣鐨勫悜閲忥紝榪欎簺鍚戦噺琛ㄥ緛浜嗘瘡涓偣鐨勫炬枩鎯呭喌錛岃鐪嬩笅鍥劇殑鎻忕粯銆傚浘涓孩鑹插皬鍦嗙偣琛ㄧず鍚戦噺鏄悜涓嬬殑錛?br>銆銆銆銆

    銆銆鏈夊緢澶氳綆楀悜閲忕殑鏂規硶錛屼笉鍚岀殑鏂規硶綺劇‘搴︿笉鍚岋紝浣嗘槸閫夋嫨浠涔堟柟娉曡鍙栧喅浜庝綘鎵瑕佹眰鐨勭簿紜害鏄釜浠涔堝眰嬈°傛渶閫氬父鐨勬柟娉曟槸鍒嗗埆璁$畻姣忎釜鐐逛笂X鍜孻鐨勫炬枩搴︼細

    銆銆x_gradient = pixel(x-1, y) - pixel(x+1, y)
    銆銆y_gradient = pixel(x, y-1) - pixel(x, y+1)


    鍦ㄥ緱鍑轟簡榪欎袱涓炬枩搴﹀悗錛屼綘灝卞彲浠ヨ綆楀杈瑰艦鐐圭殑娉曠嚎浜嗐?br>
    銆銆銆銆

    銆銆榪欓噷鏈変竴涓杈瑰艦錛屽浘涓婄粯鍑轟簡瀹冪殑涓鏉℃硶綰垮悜閲忊斺攏銆傞櫎姝わ紝榪樻湁涓ゆ潯鍚戦噺錛屽畠浠皢鐢ㄦ潵璋冭妭璇ョ偣娉曠嚎鍚戦噺銆傝繖涓ゆ潯鍚戦噺蹇呴』涓庡綋鍓嶈娓叉煋鐨勫杈瑰艦鐨勫嚬鍑稿浘瀵歸綈錛屾崲鍙ヨ瘽璇達紝瀹冧滑瑕佷笌鍑瑰嚫鍥句嬌鐢ㄥ悓涓縐嶅潗鏍囪醬銆備笅杈圭殑鍥懼垎鍒槸鍑瑰嚫鍥懼拰澶氳竟褰紝涓ゅ壇鍥鵑兘鏄劇ず浜哢銆乂涓ゆ潯鍚戦噺錛堣瘧鑰呮敞錛氫篃灝辨槸騫抽潰2D鍧愭爣鐨勪袱鏉¤醬錛夛細

    銆銆銆銆

    銆銆鐜板湪浣犲彲浠ョ湅鍒拌璋冭妭鍚庣殑鏂版硶綰垮悜閲忎簡銆傝繖涓皟鑺傚叕寮忓緢綆鍗曪細

    銆銆New_Normal = Normal + (U * x_gradient) + (V * y_gradient)

    鏈変簡鏂版硶綰垮悜閲忓悗錛屼綘灝卞彲浠ラ氳繃琛ヨ壊娓叉煋鎶鏈綆楀嚭澶氳竟褰㈡瘡涓偣鐨勪寒搴︿簡



    ]]>
    OCTREE 鏁欑▼http://www.shnenglu.com/winmain/archive/2010/02/23/108300.htmlCode KnightCode KnightTue, 23 Feb 2010 13:08:00 GMThttp://www.shnenglu.com/winmain/archive/2010/02/23/108300.htmlhttp://www.shnenglu.com/winmain/comments/108300.htmlhttp://www.shnenglu.com/winmain/archive/2010/02/23/108300.html#Feedback0http://www.shnenglu.com/winmain/comments/commentRss/108300.htmlhttp://www.shnenglu.com/winmain/services/trackbacks/108300.html
    瀵筄CTREE鐨勬弿榪?/strong>

    銆銆OCTREE 鏄3D絀洪棿榪涜鍒掑垎錛屼篃鍙互鍙┖闂村垎鍓層備粬鍏佽浣犲彧瀵逛綘鐨?D涓栫晫涓憚璞℃満鐓у皠鐨勫尯鍩熻繘琛屼綔鐢匯備粬涔熻兘鐢ㄤ簬鍐茬獊媯嫻嬨備笅闈㈣涓涓嬩負浠涔堣榪涜絀洪棿鍒嗗壊銆傚亣璁句綘寤虹珛浜嗕竴涓父鎴忎笘鐣岋紝榪欎釜涓栫晫鏈夎秴榪?00錛?00涓杈瑰艦瑕佺敾銆傚鏋滀綘寤虹珛涓涓驚鐜茍浼犻掕繖浜涘杈瑰艦錛岄偅閫熷害鏄緢鎱㈢殑銆傚嵆浣夸綘鏈変竴鍧楀緢濂界殑鏄劇ず鍗★紝浠栦篃浼氭湁寰堝ぇ鐨勯夯鐑︺備絾鏄帺浣犳父鎴忕殑鐜╁鐨勬樉紺哄崱涓嶄細瓚呰繃300$銆傛湁娌℃湁涓縐嶆柟娉曞彧娓叉煋鎽勮薄鏈虹湅瑙佺殑澶氳竟褰紵閭e氨鏄編涓界殑OCTREE銆備粬鍏佽浣犲揩閫熺殑鎵懼埌浣犺娓叉煋鐨勫杈瑰艦銆?br>

    OCTREE鏄庢牱宸ヤ綔鐨?/strong>

    銆銆OCTREE宸ヤ綔鍦ㄧ珛鏂逛綋涓傛渶鍒濓紝OCTREE浠庢牴鎺ョ偣寮濮嬶紝榪欎釜鏍規帴鐐瑰榻愪簬绔嬫柟浣撲腑鏁翠釜涓栫晫錛屾按騫蟲垨鍦烘櫙鐨刟xis涓績綰褲傚洜姝わ紝鎶婃垜浠殑鏁翠釜涓栫晫鎯寵薄鎴愪竴涓笉鍙鐨勭珛鏂逛綋銆?br>銆


    銆銆鐜板湪鏍規帴鐐瑰瓨鍌ㄤ簡涓栫晫涓殑鍏ㄩ儴欏剁偣銆傝繖鏄紝浠栬繕鏄笉鑳界粰鎴戜滑浠諱綍濂藉錛屽洜涓轟粬榪樹細鐢繪墍鏈夌殑涓滆タ銆傛垜浠兂鎶婅繖涓帴鐐瑰垎鎴?涓儴鍒嗐備竴嬈★紝鎴戜滑鍒掑垎鏃訛紝鏈?涓珛鏂逛綋鍖呭惈閭f渶鍒濈殑鏍規帴鐐圭殑绔嬫柟浣撱傞偅鎰忓懗鐫鏈?涓珛鏂逛綋鍦ㄤ笂闈紝4涓珛鏂逛綋鍦ㄤ笅闈€傝鐪嬩笅鍥撅細


    銆銆璁頒綇鍥句腑榛勮壊杞粨綰挎病鏈夈?br>銆銆鎴戜滑鍒氬垰鎶婅繖涓笘鐣屽垎鎴?涓儴鍒嗐傛兂璞′竴涓嬪鏋滄垜浠湁2錛?錛?涓儴鍒嗭紝鎴戜滑鐨勪笘鐣屽皢鏄庢牱錛熸垜浠殑鎽勮薄鏈哄湪涓栫晫鐨勪腑闂達紝鍚戠潃鍚庨潰闈犲彸鐨勮钀姐傚鏋滀綘鐪嬭繖浜涚嚎錛屼綘灝嗘敞鎰忓埌鍦∣CTREE涓?涓粨鐐逛腑鐨勭4涓傝繖浜涚粨鐐瑰寘鍚?涓悗闈㈢殑欏跺拰搴曠粨鐐廣傝繖鎰忓懗鐫鎴戜滑鍙敤鐢誨瓨鍌ㄥ湪榪欎簺緇撶偣涓殑欏剁偣銆?/font>


    銆銆鎴戜滑濡備綍媯嫻嬪嚭鎴戜滑瑕佺敾鐨勭粨鐐癸紵濡傛灉浣犲榪囩牬鐗囨嫞閫夛紙frustum culling),榪欏皢鏄緢綆鍗曠殑銆備綘鑳藉緱鍒拌繖浜涚牬鐗囩殑澶у皬騫舵嫻嬫瘡涓粨鐐癸紝鐪嬩粬鏄惁琚埅鏂垨鍦ㄤ綘鐨勮瑙夌牬鐗囦腑銆傛湁涓涓叧浜庣牬鐗囨嫞閫夌殑鏁欑▼鍦?a >http://www.gametutorials.com. 濡傛灉涓涓珛鏂逛綋鎴柇鐮寸墖錛屾垜浠氨灝嗙敾榪欎簺緇撶偣銆傚湪榪欎釜渚嬪瓙涓紝鎴戜滑鍒囩殑鏁伴噺鏄垜浠渶瑕佺敾鐨?0%銆傝浣忥紝榪欏彧鏄垜浠笘鐣屼腑鐨勪竴涓儴鍒嗐傞儴鍒嗚秺澶氾紝鎴戜滑灝卞皢瓚婄簿紜傚綋鐒訛紝鎴戜滑涓嶄細闇瑕佸お澶氱殑鐐廣備笅闈紝鎴戜滑鏉ョ湅涓涓嬩笅闈㈢殑鍥撅細


    銆銆鍦ㄤ笂闈㈣繖騫呭浘涓紝浣犲皢鍙戠幇璁稿鐨勪笉鍚屻傝繖涓緥瀛愪腑錛屼笉鏄湪鍘熷鐨?涓珛鏂逛綋鐨勬瘡涓涓粨鐐逛腑寤虹珛8涓柊鐨勭珛鏂逛綋銆傚師濮嬬殑8涓粨鐐圭殑欏跺拰搴曢潰娌℃湁緇嗗垎銆備綘鎬繪槸鎶婁竴涓粨鐐瑰垎鎴?涓垨鏇村鐨勭粨鐐癸紝浣嗘槸錛屽鏋滃湪榪欎釜闈㈡病鏈変笁瑙掑艦鍙互瀛樺偍錛屾垜浠皢蹇借榪欎釜緇撶偣騫朵笉緇欎粬鍒嗛厤鍐呭瓨銆傚鏋滄垜浠繘涓姝ョ殑緇嗗垎錛屾洿澶氱殑緇撶偣灝嗗艦鎴愬師濮嬬殑涓栫晫銆傚鏋滄垜浠彉鎹㈠埌鍙︿竴涓儴鍒嗭紝閭g珛鏂逛綋灝嗙浉浼肩殑鍙樻崲銆備負浜嗚鏄庤繖涓鐐癸紝璇風湅鍥撅細


    銆銆鍦ㄥ浘涓紝鏈変袱涓悆錛屼絾鏄柟鍚戠浉鍙嶃傛敞鎰忓乏杈圭殑閮ㄥ垎錛屼粬灝嗛偅涓栫晫鍒嗘垚2涓粨鐐癸紝涓嶆槸8涓傝繖鏄洜涓虹悆鍙2涓粨鐐廣傝鐪嬪彸杈圭殑鐞冩槸涓嶆槸鍜屽乏杈圭殑寰堢浉浼箋傝繖騫呭浘鍛婅瘔鎴戜滑錛氬彧鏄劇ず闇瑕佺殑閮ㄥ垎緇撶偣銆傚鏋滄病鏈変笁瑙掑艦鍗犵敤絀洪棿錛岀粨鐐瑰皢涓嶄細寤虹珛銆?br>

    浣曟椂鍋滄緇嗗垎

    銆銆鐜板湪錛屾垜浠槑鐧戒簡濡備綍緇嗗垎錛屼絾鏄垜浠篃闇瑕佺煡閬撴庢牱鍋滄緇嗗垎銆傛湁璁稿鐨勬柟娉曪細
    銆銆1銆傚鏋滃綋鏃剁殑涓夎褰㈡暟閲忓皯浜庢垜浠畾涔夌殑鏈澶х殑涓夎褰㈡暟閲忥紝鎴戜滑鍙互鍋滄緇嗗垎褰撳墠鐨勭粨鐐廣備婦涓緥瀛愶紝鎴戜滑瀹氫箟涓夎褰㈢殑鏈澶ф暟閲忎負100銆傝繖鎰忓懗鐫鎴戜滑鍦ㄧ粏鍒嗙粨鐐逛箣鍓嶏紝瑕佹嫻嬩竴涓嬪綋鍓嶄笁瑙掑艦鐨勬繪暟閲忔槸鍚﹀皬浜庢垨絳変簬鎴戜滑瀹氫箟鐨勬渶澶ф暟閲忥紝鐒跺悗鍐嶅仛鍐沖畾銆傚鏋滄暟閲忓皯浜庢垨絳変簬錛屾垜浠皢鍋滄緇嗗垎騫舵寚瀹氳繖浜涗笁瑙掑艦鍒伴偅涓粨鐐廣傝娉ㄦ剰鎴戜滑浠庝笉鎸囧畾浠諱綍涓夎褰㈠埌浠諱綍緇撶偣錛岄櫎闈炰粬鏄湯緇撶偣銆傚鏋滄垜浠垝鍒嗕竴涓粨鐐癸紝鎴戜滑涓嶈兘瀛樺偍涓夎褰㈠埌閭d釜緇撶偣錛屼絾鏄彲浠ュ瓨鍌ㄥ湪浠栫殑瀛愮粨鐐規垨浠栦滑鐨勫瓙緇撶偣涓紝鐢氳嚦鍒頒粬浠殑瀛愪腑錛岀瓑絳夈傚綋鎴戜滑澶嶄範浜嗘庢牱鐢?C鏍戝悗錛屽皢浼氭湁鏇村鐨勪簡瑙c?br>
    銆銆2銆傚彟涓涓柟娉曟槸鍦ㄥ仠姝㈢粏鍒嗘椂錛岀湅鎴戜滑鏄惁緇嗗垎鐨勬暟鐩槸鍚﹁秴榪囦簡緇嗗垎鐨勬爣鍑嗐備緥濡傦紝鎴戜滑鍙互鍏堝緩绔嬬粏鍒嗙殑鏍囧噯涓?0錛屽鏋滅粏鍒嗙殑鏁伴噺澶т簬榪欎釜鏍囧噯錛屾垜浠皢鍋滄騫舵寚瀹氳繖浜涘湪绔嬫柟浣撲腑榪欎釜闈㈢殑欏剁偣鍒伴偅涓粨鐐廣傚綋鎴戜滑璇?#8220;澶т簬榪欎釜鏍囧噯”灝辨剰鍛崇潃緇嗗垎鐨勬暟閲忔湁11涓?br>
    銆銆3銆傛渶鍚庣殑鏂規硶鏄湅緇撶偣鏁版槸鍚﹁秴榪囩粨鐐瑰彉閲忓畾涔夋椂鐨勫箋備緥濡傦紝鎴戜滑璁劇疆緇撶偣鍙橀噺鐨勫間負500銆傛瘡嬈★紝鎴戜滑寤虹珛涓涓粨鐐癸紝鐩稿簲鐨勭粨鐐規暟澧炲姞1銆傜劧鍚庡湪鎴戜滑姣忔寤虹珛鍙︿竴涓粨鐐規椂錛屾嫻嬩竴涓嬫垜浠綋鍓嶇殑緇撶偣鏁版槸鍚﹁秴榪囩粨鐐瑰彉閲忋傚鏋滅粨鐐規暟涓?01錛屾垜浠皢涓嶄細緇嗗垎榪欎釜緇撶偣錛屼絾鏄寚瀹氫粬鐨勫綋鍓嶉《鐐圭粰浠栥傛垜鑷繁鐢?1鍜?鐨勬柟娉曪紝浣嗘槸1鍜?涔熷緢濂斤紝鍥犱負浣犲彲浠ユ祴璇曚笉鍚岀殑緇嗗垎鐨勬爣鍑嗐?br>

    鎬庢牱鐢籓CTREE

    銆銆OCTREE寤虹珛鍚庯紝鎴戜滑灝卞彲浠ョ敾鎴戜滑闇瑕佺殑緇撶偣銆傞偅浜涚珛鏂逛綋涓嶆槸鍏ㄩ儴鍖呭惈鍦ㄦ垜浠殑瑙嗚涓殑錛屽彧鏈変竴閮ㄥ垎銆傝繖灝辨槸鎴戜滑涓轟粈涔堣璁$畻姣忎釜緇撶偣鐨勪笁瑙掑艦鐨勬暟閲忥紝濡傛灉鎴戜滑鍙渶瑕佷竴涓粨鐐逛腑鐨勪竴閮ㄥ垎錛岃繖鏍鋒垜浠氨涓嶉渶瑕佺敾鎴愬崈涓婁竾涓笁瑙掑艦銆傛垜浠粠鏍圭洰褰曞紑濮嬬敾OCTREE銆傚浜庢瘡涓粨鐐歸兘瀛樺偍鐫涓涓腑蹇冪偣銆傝繖鏄潪甯稿ソ鐨勶紝姣斿鍦ㄤ笅闈㈣繖涓嚱鏁頒腑錛?br>
    銆銆//榪欎釜鍑芥暟鍙栬蛋绔嬫柟浣擄紙X錛孻錛孼錛夌殑涓績鐐瑰拰浠栫殑澶у皬錛坵idth/2)
    銆銆bool CubeInFrustum(float x,float y,float z,float size);

    銆銆榪欎釜鍑芥暟榪斿洖true or false,鏄敱绔嬫柟浣撴槸鍚﹀湪鐮寸墖涓喅瀹氱殑銆傚鏋滅珛鏂逛綋鍦ㄧ牬鐗囦腑錛屾垜浠皢媯嫻嬫墍鏈変粬鐨勭粨鐐癸紝鐪嬩粬浠槸鍚﹀湪鐮寸墖涓紝鍚﹀垯鎴戜滑灝嗗拷綰︽爲涓殑鏁翠釜鍒嗘灊銆傚綋鎴戜滑寰楀埌浜嗙牬鐗囦腑鐨勭粨鐐癸紝浣嗘槸娌℃湁浠諱綍緇撶偣鍦ㄤ粬涓嬮潰銆傛垜浠兂鐢葷殑欏剁偣瀛樺偍鍦ㄦ湯緇撶偣涓傝浣忥紝鍙湁鏈粨鐐規湁欏剁偣瀛樺偍銆傜湅涓嬮潰鐨勫浘錛?/font>


    銆銆鏈夐槾褰辯殑绔嬫柟浣撴槸鍦ㄧ牬鐗囦腑銆傜櫧鑹茬殑绔嬫柟浣撲笉鏄湪鐮寸墖涓傝繖閲屾樉紺轟簡緇嗗垎鐨?灞傘?br>

    OCTREE 涓殑鍐茬獊

    銆銆OCTREE 涓嶆槸鐢ㄤ簬娓叉煋錛屼絾鏄敤浜庡啿紿佹嫻嬪緢濂姐傞殢鐫娓告垙鐨勫彂灞曪紝鍐茬獊媯嫻嬩篃鍦ㄦ敼鍙橈紝浣犲皢涓嶅緱涓嶅湪娓告垙涓栫晫涓繍鐢ㄨ嚜宸辯殑綆楀紡媯嫻嬩綘鐨勮鑹叉垨鐩爣鏄惁鍐茬獊銆備笅闈㈡槸涓浜涘啿紿佹嫻嬬殑渚嬪瓙錛?br>銆銆1銆備綘灝嗗緩绔嬩竴涓嚱鏁板厑璁鎬綘杞?D絀洪棿涓殑鐐瑰埌浣犵殑OCTREE騫惰繑鍥炲湪榪欎釜鐐瑰懆鍥寸殑欏剁偣銆備綘灝嗚漿閫掔殑閭d釜鐐規槸浣犵殑瑙掕壊鍜岀洰鏍囩殑涓績鐐廣傝繖铏界劧鍙互宸ヤ綔涓绔椂闂達紝浣嗗鏋滆繖涓偣闈犺繎涓涓珛鏂逛綋鐨勮竟鏃跺憿錛熶綘鐨勮鑹叉垨鐩爣鍙兘鍜屽彟涓涓珛鏂逛綋鐨勯《鐐圭浉鍐茬獊銆備負浜嗚В鍐寵繖涓棶棰橈紝浣犲皢鍋氫竴浜涗簨鎯呫備綘鍙互杞掕鑹?鐩爣鐨勫崐寰勬垨涓瀹氱殑絀洪棿錛岀劧鍚庢嫻嬪崐寰勬垨涓瀹氱殑絀洪棿鏄惁鍜屽懆鍥寸殑緇撶偣鐩稿啿紿併傝繖鐢變綘鐨勮鑹?鐩爣鐨勫艦鐘跺喅瀹氥備笅闈㈡槸涓浜涘吀鍨嬬殑鍑芥暟錛?br>
    銆銆//榪欎釜鍑芥暟鍙栬蛋瑙掕壊/鐩爣錛圶錛孻錛孼錛夌殑涓績鐐瑰茍榪斿洖闈犺繎浠栫殑欏剁偣
    銆銆CVector3 *GetVerticesFromPoint(float x,float y,float z);

    銆銆//榪欎釜鍑芥暟鍙栬蛋瑙掕壊/鐩爣錛圶錛孻錛孼錛夌殑涓績鐐瑰拰鍗婂緞錛岀劧鍚庤繑鍥炲拰浠栧啿紿佺殑緇撶偣涓殑欏剁偣
    銆銆CVector3 *GetVerticesFromPointAndRadius(float x,float y,float z,float radius);

    銆銆//榪欎釜鍑芥暟鍙栬蛋瑙掕壊/鐩爣錛圶錛孻錛孼錛夌殑涓績鐐瑰拰绔嬫柟浣撶殑澶у皬錛岀劧鍚庤繑鍥炲拰浠栧啿紿佺殑緇撶偣涓殑欏剁偣
    銆銆CVector3 *GetVerticesFromPointAndCube(float x,float y,float z,float size);

    銆銆鎴戠浉淇′綘鏈夋洿濂界殑鏂規硶蹇熺殑媯嫻嬶紝鍦ㄨ繖閲屽彧鏄粰浣犱竴鐐瑰熀紜銆?br>

    鎬葷粨

    銆銆榪欑瘒鏁欑▼鍙槸緇欎綘璁叉埅濡備綍寤虹珛鑷繁鐨凮CTREE銆傚叧浜庤繖綃囨枃绔犱腑鐨勪唬鐮佸湪www.gametutorials.com錛屾垜甯屾湜榪欑瘒鏂囩珷瀵逛綘鏈夌敤銆?br>

    涓枃璇戣咃細antking
    http://akinggame.gameres.com
    榪欑瘒鏂囩珷鐨勮嫳鏂囩増鍦?a >http://www.gametutorials.com/Tutorials/OpenGL/Octree.htm

    Ben Humphrey (DigiBen)
    Game Programmer
    DigiBen@GameTutorials.com
    Co-Web Host of www.GameTutorials.com



    ]]>
    璐?/title><link>http://www.shnenglu.com/winmain/archive/2009/12/29/104407.html</link><dc:creator>Code Knight</dc:creator><author>Code Knight</author><pubDate>Tue, 29 Dec 2009 13:54:00 GMT</pubDate><guid>http://www.shnenglu.com/winmain/archive/2009/12/29/104407.html</guid><wfw:comment>http://www.shnenglu.com/winmain/comments/104407.html</wfw:comment><comments>http://www.shnenglu.com/winmain/archive/2009/12/29/104407.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.shnenglu.com/winmain/comments/commentRss/104407.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/winmain/services/trackbacks/104407.html</trackback:ping><description><![CDATA[<img src="http://www.shnenglu.com/images/cppblog_com/winmain/screenshot_2.png" border="0"><img src="http://www.shnenglu.com/images/cppblog_com/winmain/screenshot_1.png" border="0"><br> <img src ="http://www.shnenglu.com/winmain/aggbug/104407.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/winmain/" target="_blank">Code Knight</a> 2009-12-29 21:54 <a href="http://www.shnenglu.com/winmain/archive/2009/12/29/104407.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>shader灝忕患http://www.shnenglu.com/winmain/archive/2009/12/27/104232.htmlCode KnightCode KnightSun, 27 Dec 2009 14:17:00 GMThttp://www.shnenglu.com/winmain/archive/2009/12/27/104232.htmlhttp://www.shnenglu.com/winmain/comments/104232.htmlhttp://www.shnenglu.com/winmain/archive/2009/12/27/104232.html#Feedback1http://www.shnenglu.com/winmain/comments/commentRss/104232.htmlhttp://www.shnenglu.com/winmain/services/trackbacks/104232.html綰圭悊錛圱exture錛?amp;鍙栨牱鍣紙Sampler錛?/strong>

    榪? 淇╀笢瑗垮彲浠ョ湅浣滅壒孌婄被鍨嬪彉閲忋傜汗鐞嗗氨鏄疭hader涓敤鍒扮殑璐村浘璧勬簮錛岃繖鎴戞兂娌′粈涔堝ソ璇寸殑銆傛潵瑙i噴涓涓嬪彇鏍峰櫒錛氬疄闄呬笂姣忓紶璐村浘鍦ㄤ嬌鐢ㄧ殑鏃跺欓兘瑕佺敤涓涓彇鏍? 鍣ㄣ傚彇鏍峰櫒鐩稿綋浜庤繖鏍蜂竴涓粨鏋勶紝闄や簡淇濆瓨璐村浘鏈韓鏁版嵁涔嬪錛岃繕鍖呮嫭榪囨護鍙傛暟絳夊彇鏍蜂俊鎭傞氬父錛岃鍙栬創鍥捐繖鏍風殑鎸囦護鎺ユ敹鐨勯兘鏄彇鏍峰櫒綾誨瀷鐨勫弬鏁拌屽茍闈炵洿鎺ユ帴 鏀剁汗鐞嗚創鍥俱傚0鏄庡強浣跨敤綰圭悊鎴栧彇鏍峰櫒璺熶嬌鐢ㄦ櫘閫氬彉閲忎竴鏍楓傝繖閲屾湁涓浜涘垵濮嬪寲鍙栨牱鍣ㄧ殑鏂規硶錛岃繕鏄瓑鍒板悗闈㈢殑瀹炰緥涓榪板惂銆?br>
    Semantic & Annotation

    浠? 浣曠被鍨嬬殑鍙橀噺錛堝寘鎷汗鐞嗗拰鍙栨牱鍣級錛屾垜浠兘鍙互鐢⊿emantic鎴朅nnotation淇グ鏉ヨ搗鍒頒竴浜涚壒孌婁綔鐢ㄣ係emantic鏆傛椂緲昏瘧鎴愯涔夛紱 Annotation鏆傛椂緲昏瘧鎴愭敞瑙o紝榪欐槸HLSL涓嫭鐗圭殑涓滆タ銆備笅闈㈣繖涓よ涓紝絎竴涓彉閲忓啋鍙峰悗闈㈢殑POSITION灝辨槸Semantic錛岀浜屼釜鍙橀噺 鍚庨潰鐢ㄤ竴瀵瑰皷鎷彿<>鍦堣搗鏉ョ殑琛ㄨ揪寮忓氨鏄疉nnotation錛屼竴緇?lt;>涓彲浠ユ湁寰堝涓〃杈懼紡銆?br>
    float3 OmniPos : POSITION;
    texture TexMap < string name = "test.dds"; >;

    涓鑸潵璁詫紝Semantic鏄憡璇夊簲鐢ㄧ▼搴忔垨D3D榪欎釜琚慨楗扮殑鍙橀噺鏄仛浠涔堢敤鐨勶紝Annotation鏄憡璇夌▼搴忚繖涓彉閲忔庝箞鐢ㄣ? 寰堜簯灞遍浘緗╂槸鍚楋紝鏄繖鏍鳳紝鍦ㄥ簲鐢ㄧ▼搴忎唬鐮佷腑錛屾槸鍙互璋冪敤D3D鐨凙PI璁ゅ嚭Semantic鍜孉nnotation鐨勩備緥濡備笂闈㈣繖涓よ錛岀▼搴忕殑閫昏緫灝卞彲鑳? 鏄繖鏍鳳細棣栧厛鍐欎富紼嬪簭鐨勭敳鍜屽啓Shader鐨勪箼綰﹀畾濂絇OSITION鏍囪瘑璇ュ彉閲忎唬琛ㄧ伅娉鐨勪綅緗紝鐢插湪紼嬪簭閲屽啓錛歿鐏場A.浣嶇疆 = XXX; 鎵懼埌Shader涓甫POSITION鐨勫彉閲? 緇欒鍙橀噺璧嬪間負鐏場A.浣嶇疆; return;} 閭d箞鐢插彲浠ヤ笉鐭ラ亾涔欏湪Shader涓粰榪欎釜瑕佺敤鐏場A浣嶇疆鐨勫彉閲忚搗浜嗕粈涔堝悕錛岃屼笖涔欏彲浠ュ湪濂藉嚑涓猄hader涓粰鐢ㄨ繖涓暟鎹殑鍙橀噺璧蜂笉鍚岀殑鍚嶃傜劧鍚庯紝鐢插拰 涔欏啀綰﹀畾閬囧埌Annotation涓殑“name”灝卞皢鍚庨潰鐨勫瓧絎︿覆浣滀負鏂囦歡鍚嶅緩绔嬭創鍥俱備簬鏄敳鐨勭▼搴忓氨浠嶴hader涓鍑轟簡涓涓枃浠跺悕錛屽緩绔嬩簡涓涓創 鍥句互渚涜繖涓猼exture鍙橀噺浣跨敤銆係emantic鍜孉nnotation澶ф灝辮繖涔堢敤錛岄鍏堣綰﹀畾濂藉悇涓猄emantic鍜孉nnotation閮芥槸 浠涔堟剰鎬濓紝榪欐槸up to you鐨勶紝鐒跺悗灝辨槸閫氳繃瀹冧滑鐨勬爣璇嗘潵緇欏彉閲忚祴鍊兼垨浣滃叾浠栬緟鍔╂у伐浣滀簡銆?br>
    鏃㈢劧閮芥槸鍋氳緟鍔╄鏄庣殑涓轟粈涔堣繕瑕佸垎鎴怱emantic鍜孉nnotation錛屾垜鐨勬兂娉曟槸Semantic綆鍗曟柟渚胯孉nnotation鑳藉共鐨勪簨鏇村銆備笉璇磋繖涓簡錛屾棤鍏沖ぇ灞銆傝璇寸殑鏄紝D3D涔熻窡鎴戜滑綰﹀畾浜嗕竴濂桽emantic錛屽畠浠ぇ浣撲笂閮借兘欏懼悕鎬濅箟,鎺у埗嫻?br>
    鎺? 鍒舵祦錛屽氨鏄痠f…else錛宖or錛寃hile浠涔堢殑銆傚湪CPU涓紝榪欎簺鎺у埗嫻侀犳垚鐨勫疄闄呬笂鏄寚浠よ煩杞備絾鍦℅PU涓寚浠よ煩杞茍涓嶈騫挎硾鐨勬敮鎸侊紝浠ュ線鐨勫ぇ 閮ㄥ垎鏄懼崱鍙噦寰楁寜欏哄簭涓鍙ヤ竴鍙ユ墽琛屾寚浠ゃ傚洜姝LSL鐨勭紪璇戝櫒鍙兘浼氬仛鍑鴻濡傚睍寮寰幆銆侀亶鍘嗗垎鏀瓑絳夎幗鎾炵殑浜嬫潵閫傚簲鏄懼崱銆傛墍浠ヤ嬌鐢ㄦ椂瑕佺壒鍒皬蹇冿紝鑰屼笖涓嶆槸 鎵鏈夋儏鍐電殑鎺у埗嫻佽鍙ラ兘琚敮鎸併?br>
    鍑芥暟

    HLSL 涓彁渚涗簡寰堝鍑芥暟鍙緵璋冪敤錛屽湪Direct3D 鏂囨。 -> DirectX Graphics -> Reference -> HLSL Shader Reference -> HLSL Intrinsic Functions涓湁榪欎簺鍑芥暟鐨勮緇嗗垪琛ㄣ備篃鍙嚜宸卞啓鍑芥暟鐢紝浣嗘槸鍦ㄨ緝鏃╃殑Shader鐗堟湰涓紝灝卞儚鍐呰仈鍑芥暟涓鏍風紪璇戞椂鏈緇堣灝嗗嚱鏁板睍寮鎻掑叆鍒板嚱鏁拌皟鐢? 澶勩傝繕鏈変竴鐐規垜鎯充綘涓瀹氫細鎯沖埌鐨勫氨鏄富鍑芥暟浼氭槸浠涔堛俈ertex Shader鍜孭ixel Shader鍚勮嚜闇瑕佷竴涓富鍑芥暟錛岀敱紼嬪簭鍛樻潵鎸囧畾錛佹病閿欙紝紼嬪簭鍛樺湪Shader澶栭儴鎸囧畾銆?


    ]]>
    澶嶄範涓嬫渶鍩烘湰鐨勬暟瀛︾煡璇?/title><link>http://www.shnenglu.com/winmain/archive/2009/12/08/102819.html</link><dc:creator>Code Knight</dc:creator><author>Code Knight</author><pubDate>Tue, 08 Dec 2009 14:28:00 GMT</pubDate><guid>http://www.shnenglu.com/winmain/archive/2009/12/08/102819.html</guid><wfw:comment>http://www.shnenglu.com/winmain/comments/102819.html</wfw:comment><comments>http://www.shnenglu.com/winmain/archive/2009/12/08/102819.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/winmain/comments/commentRss/102819.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/winmain/services/trackbacks/102819.html</trackback:ping><description><![CDATA[<img alt="" src="http://www.shnenglu.com/images/cppblog_com/winmain/dot.jpg"><br> <img src ="http://www.shnenglu.com/winmain/aggbug/102819.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/winmain/" target="_blank">Code Knight</a> 2009-12-08 22:28 <a href="http://www.shnenglu.com/winmain/archive/2009/12/08/102819.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鏄忓ご錛佽Intersect鎶樿吘浜嗗崐澶╋紒http://www.shnenglu.com/winmain/archive/2009/02/11/73482.htmlCode KnightCode KnightWed, 11 Feb 2009 09:41:00 GMThttp://www.shnenglu.com/winmain/archive/2009/02/11/73482.htmlhttp://www.shnenglu.com/winmain/comments/73482.htmlhttp://www.shnenglu.com/winmain/archive/2009/02/11/73482.html#Feedback0http://www.shnenglu.com/winmain/comments/commentRss/73482.htmlhttp://www.shnenglu.com/winmain/services/trackbacks/73482.html         
      1 BOOL IntersectTest(LPDIRECT3DVERTEXBUFFER9 pVB,
      2                    LPDIRECT3DINDEXBUFFER9 pIB,
      3                    int nStride,
      4                    int dwNumFaces,
      5                    D3DXVECTOR3* vPickRayOrig,
      6                    D3DXVECTOR3* vPickRay,
      7                    D3DXVECTOR3 *pVRet,
      8                    DWORD dwFlag=0// 涓昏媯嫻嬩笌鍦板艦鐩鎬氦 // 姝ゅ嚱鏁扮浉褰撹楄垂CPU// 鐢熸垚鍦板艦鏈?3W涓潰錛岄愪竴媯鏌ユ槸鍚︾浉浜?/span>
      9 {
     10     WORD*        pIndices;
     11     BYTE*        pVertices;
     12     D3DINDEXBUFFER_DESC IB_Desc;
     13 
     14     FLOAT fBary1, fBary2,fDist=1e+32f;
     15 
     16     FLOAT t_fBary1, t_fBary2,t_fDist;
     17     DWORD dwFace=-1;
     18     DWORD  dwUpperLower;    
     19 
     20     D3DXVECTOR3* pV[3];
     21     ULONG  n;
     22 
     23     pIB->GetDesc(&IB_Desc); 
     24     pIB->Lock( 00, (void**)&pIndices, 0 );
     25     pVB->Lock( 00, (void**)&pVertices,0 );
     26 
     27 
     28     for( DWORD i=0; i<dwNumFaces; i++ )
     29     {
     30         for(int j=0;j<3;j++)
     31         {
     32             if(IB_Desc.Format==D3DFMT_INDEX16)            
     33                 n=(WORD)pIndices[3*i+j];
     34             else if(IB_Desc.Format==D3DFMT_INDEX32)        
     35                 n=*(DWORD*)&pIndices[2*(3*i+j)];
     36             else 
     37                 return FALSE;
     38             pV[j]=(D3DXVECTOR3*)(pVertices+nStride*n); 
     39         }
     40 
     41         dwUpperLower=0;
     42 
     43          if(dwFlag) // 榪欐鏄繀欏昏鐨勶紝鍏蜂綋鏄庝箞鍋氬埌鐨勶紵
     44          {
     45              if(dwFlag & INTERSECT_NEGATIVEY) 
     46              {
     47                 for(int j=0;j<3;j++)
     48                 {
     49                     dwUpperLower|=vPickRayOrig->x>pV[j]->x? 0x0010:0x0001
     50                     dwUpperLower|=vPickRayOrig->z>pV[j]->z? 0x1000:0x0100
     51 
     52                 }
     53                 if(dwUpperLower!=0x1111continue;        
     54             }
     55             else if(dwFlag & INTERSECT_HORIZENTAL) 
     56             {
     57                 for(int j=0;j<3;j++)
     58                 {
     59                     dwUpperLower|=(vPickRayOrig->> pV[j]->y)? 0x0010:0x0001;
     60                 }
     61 
     62                 if(dwUpperLower!=0x0011continue;    
     63             }
     64 
     65 
     66         }
     67 
     68 
     69 
     70         // 媯嫻嬫槸鍚︾┛榪囦笁瑙掑艦
     71         if( IntersectTriangle( *vPickRayOrig, *vPickRay, *pV[0], *pV[1], *pV[2],
     72             &t_fDist, &t_fBary1, &t_fBary2 ) )
     73         {
     74             if(    t_fDist < fDist )    //鏄惁榪斿洖鏈榪戠殑涓涓偣
     75             {
     76                 dwFace = i;
     77                 fBary1 = t_fBary1;
     78                 fBary2 = t_fBary2;
     79                 fDist  = t_fDist;
     80             }
     81         }
     82     }
     83     
     84 
     85     if(dwFace<dwNumFaces && dwFace>=0 )
     86     {
     87 
     88         for(int j=0;j<3;j++)
     89         {
     90             if(IB_Desc.Format==D3DFMT_INDEX16)            
     91                 n=(WORD)pIndices[3*dwFace +j];
     92             else if(IB_Desc.Format==D3DFMT_INDEX32)        
     93                 n=*(DWORD*)&pIndices[2*(3*dwFace+j)];
     94             else 
     95                 return FALSE;
     96             pV[j]=(D3DXVECTOR3*)(pVertices+nStride*n);
     97         }
     98         *pVRet=*pV[0+fBary1*(*pV[1]-*pV[0])+fBary2*(*pV[2]-*pV[0]);  
     99 
    100 
    101         pVB->Unlock();
    102         pIB->Unlock();
    103         return 1;
    104     }
    105 
    106 
    107     pVB->Unlock();
    108     pIB->Unlock();
    109 
    110 
    111 
    112     return 0;
    113 }
    鍙︿竴涓棶棰橈紝澶ц妯$殑鍦板艦涓鑸浣曟渶澶х▼搴︾殑浼樺寲閬垮厤瀵規墍鏈夌殑闈㈣繘琛屾嫻嬶紵鐢↙OD涔堬紵



    ]]>
    青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              欧美亚洲一区| 欧美一进一出视频| 可以看av的网站久久看| 午夜久久福利| 在线精品高清中文字幕| 欧美激情五月| 欧美激情综合亚洲一二区| 一区二区三区.www| 亚洲欧美日韩国产一区二区三区| 国产麻豆综合| 免费在线观看成人av| 欧美国产精品久久| 香蕉久久夜色| 久久免费视频观看| 一区二区精品国产| 欧美亚洲免费| 一区二区三区三区在线| 午夜一区二区三区不卡视频| 亚洲国产一区二区视频| 一本色道精品久久一区二区三区| 国产日韩av一区二区| 欧美国产日韩二区| 国产精品户外野外| 欧美黑人多人双交| 国产欧美日韩精品a在线观看| 欧美福利视频在线观看| 国产精品理论片| 亚洲第一精品夜夜躁人人爽| 欧美女激情福利| 久久夜色精品国产噜噜av| 欧美日本韩国一区| 麻豆精品视频在线| 国产麻豆综合| 99精品视频一区| 在线日韩欧美| 欧美亚洲色图校园春色| 一区二区三区视频在线看| 久久久91精品国产一区二区三区| 亚洲私拍自拍| 免费在线欧美视频| 久久综合五月| 国产一二精品视频| 亚洲一二区在线| 99在线热播精品免费| 玖玖在线精品| 久久久综合视频| 国产精品一区免费视频| 夜夜嗨网站十八久久| 亚洲人被黑人高潮完整版| 久久久www成人免费精品| 欧美一区在线视频| 国产精品人人做人人爽人人添| 亚洲国产欧美一区二区三区久久| 国内精品国语自产拍在线观看| 亚洲深夜福利网站| 亚洲午夜av电影| 欧美全黄视频| 亚洲人体1000| 中文欧美日韩| 欧美日韩一区二区欧美激情| 亚洲国产天堂久久综合| 91久久黄色| 欧美激情亚洲| 日韩午夜视频在线观看| 一区二区欧美在线观看| 欧美日韩在线观看一区二区| 亚洲三级影院| 亚洲性视频h| 国产精品久久久久久久久久妞妞| 亚洲婷婷免费| 久久都是精品| 加勒比av一区二区| 久久久国产精品一区| 免费看精品久久片| 亚洲精品欧洲| 欧美午夜精品理论片a级按摩 | 在线不卡中文字幕| 麻豆成人91精品二区三区| 欧美18av| 99国产精品| 国产精品国产精品国产专区不蜜| 亚洲校园激情| 久久综合九色综合欧美狠狠| 亚洲第一综合天堂另类专| 欧美国产日韩精品免费观看| 亚洲精品四区| 久久成人免费电影| 亚洲福利视频专区| 欧美日韩国产黄| 亚洲免费在线看| 欧美成人伊人久久综合网| 中文欧美在线视频| 国产婷婷色一区二区三区在线| 久久美女艺术照精彩视频福利播放| 亚洲国产小视频| 午夜欧美大片免费观看| 亚洲电影在线| 国产精品美女午夜av| 久久婷婷国产综合精品青草 | 午夜视频久久久| 在线看国产日韩| 国产精品久久久久9999| 久久婷婷麻豆| 亚洲一区尤物| 亚洲国产成人av| 久久久高清一区二区三区| 亚洲精品中文字| 国内外成人在线| 国产精品高清网站| 暖暖成人免费视频| 午夜在线成人av| 日韩视频在线一区二区| 免费久久99精品国产自在现线| 亚洲欧美激情在线视频| 亚洲精品免费观看| 黄色日韩在线| 国产精品综合色区在线观看| 欧美激情精品久久久久久久变态 | 欧美激情亚洲自拍| 久久久不卡网国产精品一区| 在线视频亚洲欧美| 亚洲激情综合| 男人的天堂亚洲| 久久久久亚洲综合| 欧美一区二区三区四区夜夜大片 | 久久国产手机看片| 亚洲一区国产视频| 99国产精品视频免费观看| 在线精品福利| 一区久久精品| 黄色日韩在线| 一区精品在线播放| 国一区二区在线观看| 国产亚洲精品久久久久久| 国产精品入口66mio| 国产精品国码视频| 国产精品毛片a∨一区二区三区| 欧美极品色图| 欧美人与性动交α欧美精品济南到| 免费成人毛片| 欧美成人精品不卡视频在线观看| 另类av一区二区| 久热精品在线视频| 欧美国产日韩一区二区在线观看 | 欧美黄色成人网| 欧美福利网址| 欧美日韩福利| 欧美性猛片xxxx免费看久爱| 欧美日本在线观看| 国产精品magnet| 国产美女精品在线| 国产专区欧美精品| 亚洲高清一区二| 亚洲美女精品久久| 亚洲私人影吧| 久久国产欧美| 欧美大片一区二区| 亚洲精品久久久久久久久久久久久| 亚洲国产一区二区三区在线播 | 香蕉久久精品日日躁夜夜躁| 欧美一区二区啪啪| 另类激情亚洲| 欧美日韩亚洲一区三区| 国产精品亚洲一区| 在线观看不卡av| 亚洲精选视频免费看| 亚洲影音一区| 免费不卡在线视频| 最新亚洲视频| 小黄鸭视频精品导航| 麻豆精品视频在线观看| 欧美日韩亚洲高清一区二区| 国产欧美一区二区精品仙草咪 | 亚洲精品日韩欧美| 午夜天堂精品久久久久| 久久亚洲精品一区| 亚洲免费久久| 久久精品欧洲| 国产精品久久久久久久久久ktv | 好看不卡的中文字幕| 99国产精品国产精品久久| 欧美主播一区二区三区| 免费在线观看精品| 亚洲综合国产激情另类一区| 免播放器亚洲一区| 国产老女人精品毛片久久| 亚洲黄色天堂| 久久成人国产| 夜夜爽99久久国产综合精品女不卡 | 久久久久久亚洲综合影院红桃 | 久久久久国产免费免费| 欧美日韩精品二区| 国内精品视频666| 亚洲男女毛片无遮挡| 欧美国产日韩一区二区在线观看 | 午夜激情一区| 国产精品久久久久久超碰| 亚洲精品国产精品乱码不99| 久久只精品国产| 亚洲欧美中文另类|