• <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>

            4D星宇

            c++

              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              57 隨筆 :: 0 文章 :: 39 評(píng)論 :: 0 Trackbacks

            2008年12月8日 #

                          改寫(xiě)代碼心得
                   由于BLOOD渲染器的API由DX9轉(zhuǎn)向DX10,在轉(zhuǎn)化架構(gòu)和改寫(xiě)代碼的過(guò)程中,出現(xiàn)很多異常。
            在測(cè)試過(guò)程中,發(fā)現(xiàn)很多錯(cuò)誤都是由于沒(méi)有進(jìn)行正確的初始化造成的。比如分配內(nèi)存的容間,變量的正確賦值等等。已調(diào)完VB,IB,TEXTURE,RENDERTARGET等部分,還有MESH等大部未調(diào)。
                   特此MARK,以作記錄。
            posted @ 2008-12-08 10:21 bloodbao 閱讀(207) | 評(píng)論 (0)編輯 收藏

            2008年11月9日 #

            DX9下使用
            D3DXPLANE plane; 
             D3DXPlaneFromPointNormal( &plane, &vPoint, &vNormal ); //生成這個(gè)平面
            D3DXMatrixReflect( &matReflect, &plane ); //取得該平面的反射矩陣
            //設(shè)置剪切平面,使反射面上的內(nèi)容被渲染,面下的被丟棄
             m_pd3dDevice->SetClipPlane( 0, plane );
             m_pd3dDevice->SetRenderState( D3DRS_CLIPPLANEENABLE, 0x01 );
            DX10下模擬:
            User Clip PlanesUser Clip Planes are emulated by specifying a clip distance output from the Vertex Shader with the SV_ClipDistance[n] flag, where n is either 0 or 1. Each component can hold up to 4 clip distances in x, y, z, and w giving a total of 8 clip distances.

                用戶裁減平面通過(guò)在VS里設(shè)定一個(gè)SV_ClipDistance[n]標(biāo)記,定義一個(gè)裁減距離輸出得到,n為0或1。這里一共能存放8個(gè)Clip Plane距離,分別使用數(shù)組兩個(gè)元素的x,y,z,w通道。

            In this scenario, each clip planes is defined by a plane equation of the form:

            在這個(gè)場(chǎng)景里,每個(gè)clip plane被一個(gè)平面方程定義:

            Ax + By + Cz + D =0;

            Where <A,B,C> is the normal of the plane, and D is the distance of the plane from the origin. Plugging in any point <x,y,z> into this equation gives its distance from the plane. Therefore, all points <x,y,z> that satisfy the equation Ax + By + Cz + D = 0 are on the plane. All points that satisfy Ax + By + Cz + D < 0 are below the plane. All points that satisfy Ax + By + Cz + D > 0 are above the plane.

            <A,B,C>是平面法向,D是平面到原點(diǎn)的距離。把任意點(diǎn)<x,y,z>代入方程能得到它到平面的距離。所有滿足方程=0的點(diǎn)在平面上,<0的點(diǎn)在平面下而 >0的點(diǎn)在平面上。

            In the Vertex Shader, each vertex is tested against each plane equation to produce a distance to the clip plane. Each of the three clip distances are stored in the first three components of the output component with the semantic SV_ClipDistance0. These clip distances get interpolated over the triangle during rasterization and clipped if the value every goes below 0.

                在VS中,每個(gè)頂點(diǎn)會(huì)帶入平面方程做測(cè)試。每個(gè)三角形的Clip距離存在SV_ClipDistance0語(yǔ)義輸出的前三個(gè)通道中。這個(gè)距離在光柵化中被線性插值,所有小于0的像素被剔除。

            posted @ 2008-11-09 20:47 bloodbao 閱讀(1204) | 評(píng)論 (0)編輯 收藏

            2008年10月23日 #

            近期較閑,主要修改rendering架構(gòu),減少DX9的接口,全面使用DX10的接口,修改變動(dòng)非常大,初調(diào)試三千多個(gè)ERROR,現(xiàn)減為850多個(gè),不過(guò),內(nèi)部錯(cuò)誤還是很多。希望能在DX11發(fā)布前,全部改完。第二步,會(huì)建立更龐大的ISCENENODE,以滿足快速測(cè)試和新版SCENEEDIT需要。暫記下。
            posted @ 2008-10-23 21:55 bloodbao 閱讀(197) | 評(píng)論 (0)編輯 收藏

            2008年9月18日 #

            不知不覺(jué),九月已經(jīng)過(guò)去太半了,而我卻由于沉迷于游戲,反而沒(méi)學(xué)到什么東西,這樣浪費(fèi)時(shí)間,真的是一種罪過(guò)。 過(guò)了一個(gè)多月時(shí)間,只簡(jiǎn)單的支持了XML和一點(diǎn)點(diǎn)LIGHT。小貓的引擎,離我承諾的精彩的水面,漂亮的粒子系統(tǒng),復(fù)雜的天氣系統(tǒng),流暢的骨骼動(dòng)畫(huà)和人工智能,越來(lái)越遠(yuǎn)。 革命遠(yuǎn)未成功,小貓還需努力,為了錢(qián)和生活,多一點(diǎn)自制,少玩一些游戲吧! 退路已斷,前方無(wú)路,人生豈能如些墮落。貓行天下,人生何缺悲壯,也需幾多拼搏。十分耕耘,萬(wàn)分努力,或許成功! 期小貓自勉!
            posted @ 2008-09-18 21:58 bloodbao 閱讀(182) | 評(píng)論 (0)編輯 收藏

            2008年8月11日 #

                                 Main Features in my blood engine
            Direct3D 9 is used to render the scene
            User input is gathered though DirectInput
            Single pass multi-texturing using the fixed-function pipeline (FFP)
            Light-mapping
            Frustum culling
            Simple skybox
            Keyframe Animation with GPU-based frame interpolation through a custom vertex and pixel shader written in HLSL. This technique is also known as Vertex Tweening or even Morph Target
            Support for Quake2 models (.md2)
            Support for DirectX models (.x)
            Support for PCX texture loading in addition to the other image formats already supported by Direct3D
            Support for Quake3:Arena levels
            Lightmaps
            Curved surfaces using Bezier patches
            Partial support of Quake3 materials and effects (.shader)
            Uses the BSP/PVS to quickly discard non visible geometry
            Collision detection using the BSP tree (supports ray, sphere and box sweeps)
            A flexible scene graph system where entities can be attached to each other in order to perform hierarchical transformations and geometry culling
            Quake-like player movement physics
            A powerful in-game console system:
            Outputs vital information
            Can take command inputs from the user
            Console variables can be dynamically edited at runtime
            Commands and console variable settings can be loaded from a user-specified text file (cfg)
            Garbage collection of unused resources through reference counting
            Control keys can be dynamically changed in-game through the console, using the bind command
            User input is abstracted through an Action Manager which maps inputs to actions
            A smart chase-camera controller that will detect collisions with the world to prevent the view from being occluded by other pieces of world geometry.
            Error handling through exceptions
            The in-game HUD can display vital performance statistics about the game, such as frames per second, total number of triangles on the screen, number of textures loaded, etc…
            posted @ 2008-08-11 15:05 bloodbao 閱讀(221) | 評(píng)論 (0)編輯 收藏

            2008年8月6日 #

                   為了這次面試,我休息了很多天,都沒(méi)工作。結(jié)果,得到的又是一個(gè)失敗的結(jié)局。分析原因,都認(rèn)為我的C++基礎(chǔ)很薄弱吧,要不就是因?yàn)槲乙郧皬氖碌墓ぷ骱同F(xiàn)在的工作差別太大了。
                  作為一名新手,我很迷茫,在學(xué)習(xí)的道路我沒(méi)有被打敗,卻在兩次面試中,深受打擊。我不僅在想,這是否是我要選擇的路。僅剩半個(gè)多月的時(shí)間,暑期就結(jié)束了,我再不出去,就沒(méi)機(jī)會(huì)了。事實(shí)上,做不做游戲,我無(wú)所謂,但現(xiàn)在的生活一直不是我想要的。我不斷地在否定自已的路上,越走越遠(yuǎn),找不到真實(shí)的我。
                  兩個(gè)月很快就過(guò)去了,我只能靜下心來(lái)去做事情,把這些煩人的事,都拋于腦后。路還是要走,人總是要成長(zhǎng)的,希望能從失敗中走出來(lái)。
                  記下今天的失敗,以作自勉。

            posted @ 2008-08-06 10:36 bloodbao 閱讀(461) | 評(píng)論 (10)編輯 收藏

            2008年7月20日 #


            主要是用模板緩沖區(qū)來(lái)實(shí)現(xiàn)。
            DepthStencilState StencilShadow
            {
                DepthEnable = true;
                DepthWriteMask = ZERO;
                DepthFunc = LESS;
               
                StencilEnable = true;
                StencilReadMask = 0xFFFFFFFF;
                StencilWriteMask = 0xFFFFFFFF;
               
                FrontFaceStencilFunc = ALWAYS;
                FrontFaceStencilPass = INCR;
                FrontFaceStencilFail = Keep;
               
                BackFaceStencilFunc = ALWAYS;
                BackFaceStencilPass = DECR;
              BackFaceStencilFail = Keep;
            };
            BlendState AdditiveBlending
            {
                AlphaToCoverageEnable = FALSE;
                BlendEnable[0] = TRUE;
                SrcBlend = SRC_ALPHA ;
                DestBlend = INV_SRC_ALPHA ;
                BlendOp = ADD;
                SrcBlendAlpha = ZERO;
                DestBlendAlpha = ZERO;
                BlendOpAlpha = ADD;
                RenderTargetWriteMask[0] = 0x0F;
            };

            Rendering Shadows

            At the top level, the rendering steps look like the following:

            • If ambient lighting is enabled, render the entire scene with ambient only.
            • For each light in the scene, do the following:
              • Disable depth-buffer and frame-buffer writing.
              • Prepare the stencil buffer render states for rendering the shadow volume.
              • Render the shadow volume mesh with a vertex extruding shader. This sets up the stencil buffer according to whether or not the pixels are in the shadow volume.
              • Prepare the stencil buffer render states for lighting.
              • Prepare the additive blending mode.
              • Render the scene for lighting with only the light being processed.

            Shadow Volume并不是一個(gè)沒(méi)有缺陷的技術(shù)。除了高像素填充率和陰影邊界檢測(cè)外,在繪制過(guò)程中還可能出現(xiàn)錯(cuò)誤。錯(cuò)誤的主要原因是當(dāng)一個(gè)幾何模型在計(jì)算自陰影時(shí),它的面通常被完全照亮或者完全變暗,這取決于這個(gè)面是否朝向光源。光照計(jì)算必須使用頂點(diǎn)法向而非表面法向。對(duì)于接近平行光源的面,它會(huì)被完全照亮或者完全變暗,而實(shí)際上應(yīng)該部分處于光源中。這是從stencil shadow volume中繼承來(lái)的問(wèn)題,在計(jì)算陰影時(shí)必須被考慮。這個(gè)問(wèn)題可以通過(guò)增加mesh密度來(lái)解決,這也增加了處理mesh的時(shí)間。頂點(diǎn)法向和面法向越接近,表面的問(wèn)題就越少。如果程序不能把問(wèn)題限制在可接受的范圍內(nèi),就必須考慮使用其他的算法,比如PRT或者Shadow Map。
            posted @ 2008-07-20 10:48 bloodbao 閱讀(345) | 評(píng)論 (0)編輯 收藏

            Fixed-function Lighting Pipeline
            ColorsOutput CalcLighting( float3 worldNormal, float3 worldPos, float3 cameraPos )
            {
                ColorsOutput output = (ColorsOutput)0.0;
               
                for(int i=0; i<8; i++)
            {
                 //光線方向
                    float3 toLight = g_lights[i].Position.xyz - worldPos;
                     //離光源距離
                    float lightDist = length( toLight );
                     //atten=(1/(a[2]*d*d+a[1]*d+a[1])
                    float fAtten = 1.0/dot( g_lights[i].Atten, float4(1,lightDist,lightDist*lightDist,0) );
                    float3 lightDir = normalize( toLight );
                     //H
                    float3 halfAngle = normalize( normalize(-cameraPos) + lightDir );
                   
                     //Phong方程,逐頂點(diǎn)光照
                    output.Diffuse += max(0,dot( lightDir, worldNormal ) * g_lights[i].Diffuse * fAtten) + g_lights[i].Ambient;
                    output.Specular += max(0,pow( dot( halfAngle, worldNormal ), 64 ) * g_lights[i].Specular * fAtten );
                }
               
                return output;
            }
            簡(jiǎn)單ALPHA測(cè)試
            //
            // PS for rendering with alpha test
            //
            float4 PSAlphaTestmain(PSSceneIn input) : COLOR0
            {       
                     float4 color =  tex2D( g_samLinear, g_txDiffuse, input.tex ) * input.colorD;
                     if( color.a < 0.5 )
                             discard;
                     return color;
            }
            霧化:

            //
            // Calculates fog factor based upon distance
            //
            // E is defined as the base of the natural logarithm (2.71828)
            float CalcFogFactor( float d )
            {
                     float fogCoeff = 1.0;
                    
                     if( FOGMODE_LINEAR == g_fogMode )
                     {
                             fogCoeff = (g_fogEnd - d)/(g_fogEnd - g_fogStart);
                     }
                     else if( FOGMODE_EXP == g_fogMode )
                     {
                             fogCoeff = 1.0 / pow( E, d*g_fogDensity );
                     }
                     else if( FOGMODE_EXP2 == g_fogMode )
                     {
                             fogCoeff = 1.0 / pow( E, d*d*g_fogDensity*g_fogDensity );
                     }
                    
                     return clamp( fogCoeff, 0, 1 );
            }

            Finally, the pixel shader uses the fog factor to determine how much of the original color and how much of the fog color to output to the pixel.

            最后,PS使用霧化參數(shù)確定霧顏色和紋理顏色的混合程度。
            return fog * normalColor + (1.0 - fog)*g_fogColor;

            posted @ 2008-07-20 10:31 bloodbao 閱讀(334) | 評(píng)論 (0)編輯 收藏

            2008年7月17日 #

            剛開(kāi)始學(xué)習(xí)DX10,發(fā)覺(jué)模型文件已經(jīng)從原來(lái)的X格式變?yōu)镾DKMESH格式,也就是說(shuō)DX10不直接支持X文件了,
            那現(xiàn)在該怎么辦,我在NVSDK下找到了他的解決方案,先用DX9的接口打開(kāi)X文件,再用DX10接口來(lái)渲染文件。
                     在DX10下,缺少了很多以前在DX9下的元素。比如,光照,材質(zhì)等。
                     要實(shí)現(xiàn)這些元素,就必須在SHADER下手動(dòng)去實(shí)現(xiàn),那就意味著你必須熟悉圖形學(xué)的內(nèi)容,特別是其中的光照模型等內(nèi)容。
            比如,方向光的實(shí)現(xiàn):
                //directional light-----------------------------------------------------------------
                float3 lightDir = g_lightPos - In.worldPos;
                float3 lightDirNorm = normalize(lightDir);
                float3 SDir = normalize( g_lightPos - g_eyePos);
                float cosGammaDir = dot(SDir, V);
                float dirLighting = g_Kd*dirLightIntensity*saturate( dot( N,lightDirNorm ) );
                //diffuse
                float3 diffuseDirLight = dirLighting*exDir;       
                //airlight
                float3 dirAirLight = phaseFunctionSchlick(cosGammaDir)* dirLightIntensity*float3(1-exDir.x,1-exDir.y,1-exDir.z);
                //specular
                float3 specularDirLight = saturate( pow(  dot(lightDirNorm,reflVect),g_specPower)) * dirLightIntensity * g_KsDir * exDir;
            點(diǎn)光源的實(shí)現(xiàn):
              //point light 1---------------------------------------------------------------------
                //diffuse surface radiance and airlight due to point light
                float3 pointLightDir = g_PointLightPos - In.worldPos;
                //diffuse
                float3 diffusePointLight1 = calculateDiffusePointLight(0.1,Dvp,g_DSVPointLight,pointLightDir,N,V);
                //airlight
                float3 airlight1 = calculateAirLightPointLight(Dvp,g_DSVPointLight,g_VecPointLightEye,V);
                //specular
                float3 specularPointLight = Specular(g_PointLightIntensity, g_KsPoint, length(pointLightDir), Dvp, g_specPower, normalize(pointLightDir), reflVect);
            計(jì)算點(diǎn)光源的漫射光:
            float3 calculateDiffusePointLight(float Kd,float Dvp,float Dsv,float3 pointLightDir,float3 N,float3 V)
            {

                float Dsp = length(pointLightDir);
                float3 L = pointLightDir/Dsp;
                float thetas = acos(dot(N, L));
                float lightIntensity = g_PointLightIntensity * 100;
               
                //spotlight
                float angleToSpotLight = dot(-L, g_SpotLightDir);
                if(g_useSpotLight)
                {    if(angleToSpotLight > g_cosSpotlightAngle)
                         lightIntensity *= abs((angleToSpotLight - g_cosSpotlightAngle)/(1-g_cosSpotlightAngle));
                     else
                         lightIntensity = 0;        
                }  
               
                //diffuse contribution
                float t1 = exp(-g_beta.x*Dsp)*max(cos(thetas),0)/Dsp;
                float4 t2 = g_beta.x*Gtable.SampleLevel(samLinearClamp, float2((g_beta.x*Dsp-g_diffXOffset)*g_diffXScale, (thetas-g_diffYOffset)*g_diffYScale),0)/(2*PI);
                float rCol = (t1+t2.x)*exp(-g_beta.x*Dvp)*Kd*lightIntensity/Dsp;
                float diffusePointLight = float3(rCol,rCol,rCol); 
                return diffusePointLight.xxx;
            }
            計(jì)算高光:
            float3 Specular(float lightIntensity, float Ks, float Dsp, float Dvp, float specPow, float3 L, float3 VReflect)
            {
                lightIntensity = lightIntensity * 100;
                float LDotVReflect = dot(L,VReflect);
                float thetas = acos(LDotVReflect);

                float t1 = exp(-g_beta*Dsp)*pow(max(LDotVReflect,0),specPow)/Dsp;
                float4 t2 = g_beta.x*G_20table.SampleLevel(samLinearClamp, float2((g_beta.x*Dsp-g_20XOffset)*g_20XScale, (thetas-g_20YOffset)*g_20YScale),0)/(2*PI);
                float specular = (t1+t2.x)*exp(-g_beta.x*Dvp)*Ks*lightIntensity/Dsp;
                return specular.xxx;
            }
            下一步,考慮如何不通過(guò)DX9接口,直接導(dǎo)入X文件。

            posted @ 2008-07-17 10:26 bloodbao 閱讀(851) | 評(píng)論 (2)編輯 收藏

            2008年7月15日 #

                   唉,終于放署假了,我應(yīng)該做些什么了。
                  本來(lái)想寫(xiě)個(gè)程序的,可是我發(fā)覺(jué)自已的自控力太差了。剛摸到一本小說(shuō),就被迷住了,以至于這一周都在看那本小說(shuō),程序方面是一點(diǎn)進(jìn)度都有。那是本關(guān)于SC的小說(shuō),但為一個(gè)星際迷,我深深地被吸引了,每當(dāng)我一摸到電腦,就不自覺(jué)地點(diǎn)進(jìn)小說(shuō)的網(wǎng)頁(yè)中,進(jìn)入那個(gè)SC的虛幻空間。
            看完小說(shuō),本以為還能干點(diǎn)什么,結(jié)果又下了本DOOM啟示錄,又迷進(jìn)去了。哎,看來(lái)小說(shuō)是不能碰啦,我可不想永遠(yuǎn)呆在這個(gè)鬼地方。
            等找到工作,再看小說(shuō)吧。
            posted @ 2008-07-15 15:53 bloodbao 閱讀(168) | 評(píng)論 (0)編輯 收藏

            僅列出標(biāo)題  下一頁(yè)
            久久久久久国产精品无码下载 | 国内高清久久久久久| 成人精品一区二区久久久| 国产精品久久精品| 日本免费一区二区久久人人澡| 欧洲精品久久久av无码电影| 久久精品国产色蜜蜜麻豆| 国产亚洲精久久久久久无码77777| 久久久午夜精品| 中文字幕无码免费久久| 久久亚洲精品成人AV| 国产精品久久久久久久久| 99久久精品免费看国产一区二区三区| 狠狠色丁香久久婷婷综| 国产精品欧美久久久久无广告| 99久久夜色精品国产网站| 无码任你躁久久久久久久| 久久99久久99精品免视看动漫 | 久久久久久久免费视频| 久久久久久久久久久精品尤物| 中文无码久久精品| 精品999久久久久久中文字幕| 91精品国产高清久久久久久国产嫩草| 久久国产免费| 亚洲成色WWW久久网站| 国产精品久久久久国产A级| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久亚洲日韩看片无码| 日韩精品久久久肉伦网站| 久久久久一区二区三区| 狠狠精品久久久无码中文字幕| 香蕉aa三级久久毛片| 97久久精品国产精品青草| 久久无码一区二区三区少妇| 久久香蕉国产线看观看精品yw| 亚洲国产成人久久综合一| 久久久久久亚洲精品影院| 亚洲成人精品久久| 无码伊人66久久大杳蕉网站谷歌| 99久久精品费精品国产| 亚洲AV无码久久精品色欲|