4D星宇

c++

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  57 随笔 :: 0 文章 :: 39 评论 :: 0 Trackbacks

#

有Effect版:
    DWORD         g_dwShaderFlags; // Shader compilate and link flags
      LPD3DXBUFFER  g_pCompiledFragments = NULL; 

    D3DXGatherFragmentsFromFile( L"FragmentLinker.fx", NULL,
                NULL, g_dwShaderFlags, &g_pCompiledFragments, NULL );

D3DXGatherFragmentsFromFile requires the .fx file, pointers to the #define and #include handlers (both set to NULL in this example), and the shader compile flags. The method returns a buffer which contains the compiled shader fragment. The method can return a second buffer with compile errors, which is set to NULL in this example because it is not used. D3DXGatherFragments is overloaded to handle loading fragments from a string, a file, or a resource.

Set your debugger to break on this method to look for compile errors in the debugger. The compiler can catch errors in syntax, but it cannot check for registers that are shared incorrectly due to the fact that it has no way to predict which parameters a user may want to share between fragments.

You need a fragment linker to manage the compiled fragments. Create the fragment linker by calling D3DXCreateFragmentLinker:

ID3DXFragmentLinker* g_pFragmentLinker = NULL;     // Fragment linker interface
IDirect3DDevice9*    pd3dDevice        = NULL;

    // Initialize the device before using it
 ...
 
    // Create the fragment linker interface
    D3DXCreateFragmentLinker( pd3dDevice, 0, &g_pFragmentLinker );

Then simply add the compiled fragments to the fragment linker using ID3DXFragmentLinker::AddFragments.

    // Add the compiled fragments to a list
    g_pFragmentLinker->AddFragments(    
              (DWORD*)g_pCompiledFragments->GetBufferPointer() );

ID3DXFragmentLinker::AddFragments requires a pointer to the DWORD stream that contains the compiled shader.

After compiling fragments and creating a fragment linker, there are several ways to link fragments. One way to link a vertex shader fragment is to call ID3DXFragmentLinker::LinkVertexShader. Here is an example that links two vertex shader fragments:

    // Get a handle to each fragment   
    D3DXHANDLE fragmentHandle[2];
 fragmentHandle[0] =
     (D3DXHANDLE)g_pFragmentLinker->GetFragmentHandleByName("Ambient");
 fragmentHandle[1] =
     (D3DXHANDLE)g_pFragmentLinker->GetFragmentHandleByName("AmbientDiffuseFragment");
   
    // Link the fragments together to form a vertex shader
    IDirect3DVertexShader9* pVertexShader = NULL;
    g_pFragmentLinker->LinkVertexShader( "vs_1_1", g_dwShaderFlags,
           fragmentHandle, 2, &pVertexShader, NULL );

This requires a shader compile target, the shader compile and link flags, and a handle to each of the fragments to link. If the fragments are successfully linked, ID3DXFragmentLinker::LinkVertexShader returns a vertex shader (IDirect3DVertexShader9). The vertex shader needs to be set in the effect before rendering. But before this, here's how the shader is declared in the effect:

VertexShader MyVertexShader; // Vertex shader set by the application

The effect technique contains all the state set for a pass. This pass specifies the vertex shader like this:

technique RenderScene
{
    pass P0
    {
        VertexShader = <MyVertexShader>;   
        PixelShader = compile ps_1_1 ModulateTexture();   
    }

With the effect's vertex shader created and initialized, the render code also sets the uniform constants and calls the render loop. Set the uniform constants similar to this:

    // Update the uniform shader constants.
    g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection );
    g_pEffect->SetMatrix( "g_mWorld", &mWorld );
    g_pEffect->SetFloat( "g_fTime", (float)fTime );   
Then render the effect by setting the current technique and pass:

    // Render the scene
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    { 
        // Apply the technique contained in the effect
        UINT cPasses, iPass;
        g_pEffect->Begin(&cPasses, 0);

        for (iPass = 0; iPass < cPasses; iPass++)
        {
            g_pEffect->BeginPass(iPass);

            // Render the mesh with the applied technique
            g_pMesh->DrawSubset(0);

            g_pEffect->EndPass();
        }
        g_pEffect->End();

        pd3dDevice->EndScene();
    }

When setting uniform shader constants, it is more efficient to cache a handle to the parameter by calling ID3DXBaseEffect::GetParameterByName. This avoids the string lookup that is necessary when calling effect methods like ID3DXBaseEffect::SetMatrix.

  // Instead of setting a uniform constant like this in the render loop
  g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection );

  // Get a handle to a uniform constant outside of the render loop
  D3DXHANDLE hParameter;
  GetParameterByName( hParameter,"g_mWorldViewProjection");

  ...
 
  // Use the handle to set the uniform constant in the render loop
  g_pEffect->SetMatrix(hParameter);

无Effect版:
 LPD3DXCONSTANTTABLE pConstantTable;
    LPD3DXBUFFER pShaderBuf;
    IDirect3DVertexShader9* pVertexShader = NULL;

    // Compile the fragments to a buffer.
    D3DXGatherFragmentsFromFile( L"FragmentLinker.fx", NULL, NULL,
         g_dwShaderFlags, &g_pCompiledFragments, NULL );
   
    g_pFragmentLinker->AddFragments((DWORD*)g_pCompiledFragments->GetBufferPointer());
    g_pFragmentLinker->LinkShader(
     "vs_1_1",
     g_dwShaderFlags,
     aHandles,
     NUM_FRAGMENTS,
     &pShaderBuf,
     NULL);
    D3DXGetShaderConstantTable(
     (DWORD*)pShaderBuf->GetBufferPointer(),
     &pConstantTable );
   
    pDevice->CreateVertexShader(
     (DWORD*)pShaderBuf->GetBufferPointer(),
     &pVertexShader);
    RELEASE(pShaderBuf);

posted @ 2008-05-12 19:51 bloodbao 阅读(434) | 评论 (0)编辑 收藏

OGRE场景管理:
PCZSceneManager : public SceneManager
节点:
    typedef std::list < SceneNode * > NodeList;
    typedef std::list < WireBoundingBox * > BoxList;
摄像机:
    class PCZCamera;
天空:
    void setSkyZone(PCZone * zone);
光照:
    createLight(const String& name);
地带:
    class PCZone;
    PCZone * createZone(const String& zoneType, const String& instanceName);
释放节点:
    void removeSceneNode( SceneNode * );
节点查找:
    void findNodesIn( const AxisAlignedBox &box,
        PCZSceneNodeList &list,
        PCZone * startZone,
        PCZSceneNode *exclude = 0 );

    class PCZIntersectionSceneQuery;-----相交查询
    class PCZRaySceneQuery;---------射线查询
    class PCZSphereSceneQuery;--------球面查询
    class PCZAxisAlignedBoxSceneQuery;------箱查询(沿轴向)
    class PCZPlaneBoundedVolumeListSceneQuery;-------表查询
简单地看了OGRE的场景管理,除了OGREMAIN部分,还用了PCZ插件来实继承并实现。
(class PCZSceneManagerFactory : public SceneManagerFactory)挺复杂的,相比之下,鬼火的场景管理就简单了,
可调用多种节点。

posted @ 2008-05-11 11:42 bloodbao 阅读(1449) | 评论 (0)编辑 收藏

posted @ 2008-05-10 22:00 bloodbao 阅读(169) | 评论 (1)编辑 收藏

175.5K MilkShape_3D_v1.8.2.zip
 
已经成功地保存在Mofile
文件提取码: 4330054774071826
 
    当您的朋友需要提取此文件时只需:
     匿名提取文件连接 http://pickup.mofile.com/4330054774071826
     或登录Mofile,使用提取码 4330054774071826 提取文件
呼呼,,高兴啊,刚收到朋友发来的UNREAL3的源码!可以好好的研究一下啦,找不到工作,我就做自已的游戏,自已的引擎!
posted @ 2008-05-08 19:35 bloodbao 阅读(460) | 评论 (0)编辑 收藏

这一次的应聘是彻底失败了,不过,也算是见识了福建的网游公司。
一天坐了九个小时的车,我算是体验到了讨生活的艰辛。
中午坐车的时候天还是炎热的,下午开始狂下雨,我穿着两件衣服还一直在发抖。
先来谈谈感受:
1.公司内部环境不错,很漂亮的游泳池,攀沿壁,会议室,食堂。我比较喜欢那个游泳池,感觉很不错。
2.美女很多,特别是人事部门的,那么冷的天气,穿着超短裙,简是要风度不要温度。不过,特别养眼。
3.工作环境,两三百个人挤在一个大厅中。好像,各个开发组都在一起吧,有些成员面前放着两台很大的液晶,很上去就挺爽的。只是这么吵杂的环境适合开发吗,偶是不知道的。
4.人事部的MM挺勤快的,不过,依旧有被扔在一旁的感觉,特别是在等与主程见面的时间,差不多快一个小时。幸好旁边的一个帅哥给了本杂志,让我打发时间。
5.每时每刻都有人在应聘,不过,都是招文员。感觉就去了一个PHP的,也算技术的。
6.主程很厉害,用现在的话讲,叫很牛。人事的MM,说他很严格,面试的题目都是他出的,非常难。面谈时果然很严,偶不是计算机科班出身的,虽然C++用的不是炉火纯青,但也有两三年的基础,对基本概念都是小懂的,可是要我按书本上背出来,让我有点难以接受(也背不出来啊)。
至于题目的难度,有用的C++的朋友,应该都是了解的。还有就是那个主程一直想让我讲优点和缺点,估计是出于岗位安排考虑,可是俺一直找不来自已的特色,这算是我面试的败笔吧。最大的败笔可能是对人事的MM,说了句这考题太EASY了。
7.带去代码用的调试环境太高,这是我的错!哎,谁让我的开发环境是VISTA+VC2008!嗯,难道ND都没有一台电脑跑这个的?
那主程说程序打不开。哎,我的错。直觉告诉我,这个主程比华为面试官差多了,简直是两个档次的。以前,在和华为的交流时,那态度啊,对代码的分析,都很不错。可怜,那时我刚学C++,傻乎乎的就跑去面试,华为招硬件+C的比较多,和偶的不适合(我不懂数字电路,模电等硬件方面的知识)。
8.我说了我的优势在对数学的了解上,比如矩阵可能在引擎上有一定的应用。那主程直接和我说,数学在游戏开发上应用不太。我忽视了,ND好像用的是UNREAL,别人的引擎,不用自已开发底层吧?
C++
1.什么是继承?
2.什么是多态性?
3.什么是Iterator,有什么作用?
4.STL是什么?
5.STACK,LIST和MAP有什么不同?
6.什么是重载(overloading)和重写(overridding)?有什么区别?
7.多线程有几种。。。?
8.MUTEX和CRITICALSECTION有什么区别?
9.ENTERCRITICALSECTION和TRYENTERCRITICALSECTION有什么不同?
D3D
1.材质是什么?有些什么元素?
2.LOD时产生T型裂缝和呼吸效应,有什么优化方案?
3.浅解HDR技术?
4.什么是BILLBOARD,怎么实现?
5.什么是BSP?用在室内还是室外?怎么实现?
6.模板缓冲区的应用?
7.逆矩阵有什么应用?
面试时:
1.D3D或ONPENGL,实现一个三角形?(过程)
2.用过什么物理引擎?
3.用过什么脚本?
4.自已的优缺点?
5.有什么作品并介绍?
6.对3D中的什么最熟悉?
总结:败军之将,谈什么都是没用的,找不到好工作苦的是自已,赶快加深自身的修养。特别是表达和沟通能力。
posted @ 2008-05-08 14:38 bloodbao 阅读(825) | 评论 (8)编辑 收藏

该项目使用INI来实现数据的读取。
比如:
1.节点读取
INI部分:
外观
Look
 Body
  model=impreza.3ds
  scale=1 1 1
 Wheels
  model=wheel.3ds
  scale=1 1 1
声音
Sound
 Engine
  wave=206_engine.wav
  pitch_low=0.2
  pitch_high=1.5
程序部分:
//load car

 body.node=loadModel(cfg, "Look/Body/", device, sm, driver);

 body.node_debug=sm->addCubeSceneNode(1, 0, -1, core::vector3df(0, 0, 0), core::vector3df(0, 0, 0),
  cfg.Getval_vector("Body/Chassis/1/scale", core::vector3df(1, 1, 1))
  );
 body.node_debug->setMaterialTexture(0, driver->getTexture("data/misc/checked.jpg"));
2.车轮的属性
 Wheel #default
  damp=30000
  spring=50000
  radius=0.38
  weight=20
  width=0.10 #not yet used if user specifies wheel model
  brakes=0 # 0.0 - 1.0
 Wheel_1 #fl
  pos=1.39 -0.145 0.823
  attr=STEER
  brakes=0.8
  rotation_z=1.5707963 #used just by client part
 Wheel_2 #fr
  pos=1.39 -0.145 -0.823
  attr=STEER
  brakes=0.8
  rotation_z=4.7123889
 Wheel_3 #rl
  pos=-1.350 -0.15 0.823
  attr=STRAIGHT|THURST
  brakes=0.2
  rotation_z=1.5707963
 Wheel_4 #rr
  pos=-1.350 -0.15 -0.823
  attr=STRAIGHT|THURST
  brakes=0.2
  rotation_z=4.7123889
for (int i=0; ; i++) {
  char buf2[128];

  sprintf(buf2, "Body/Wheel_%d/", i+1);
  buf=buf2;

  if (!cfg.Getval_exists(buf+"attr")) break;

  double radius=cfg.Getval_double((string)buf+"radius", cfg.Getval_double("Body/Wheel/radius", 1));
  double width=cfg.Getval_double((string)buf+"width", cfg.Getval_double("Body/Wheel/width", 1));

  scene::ISceneNode* node=loadModel(cfg, "Look/Wheels/", device, sm, driver);
  CModelAttr wm;

  scene::IMesh* cm=CreateCylinder(25, 2, 1);
  scene::ISceneNode* node_debug=sm->addMeshSceneNode(cm);
  node_debug->setScale(core::vector3df((f32)(radius), (f32)width, (f32)(radius)));
  node_debug->setMaterialTexture(0, driver->getTexture("data/misc/checked.jpg"));
  node_debug->getMaterial(0).EmissiveColor.set(255,255,255,255);

  wm.arot=core::vector3df((f32)cfg.Getval_double(buf+"rotation_x", 0),
    (f32)cfg.Getval_double(buf+"rotation_y", 0),
    (f32)cfg.Getval_double(buf+"rotation_z", 0));
  wm.node=node;
  wm.node_debug=node_debug;

  wheels.push_back(wm);
 }
3.声音---车开动时的轰鸣声
 //load sounds
 try {
  snd_engine = new openalpp::Source((ALbyte*)("data/cars/"+profile+"/"+cfg.Getval_str("Sound/Engine/wave")).c_str());
  if (!snd_engine.valid())
   DBGCOUT("ALUT", "Coulnd't load file", ("data/cars/"+profile+"/"+cfg.Getval_str("Sound/Engine/wave")).c_str());
  else {
   snd_engine->setGain(1);
   snd_engine->setPosition(0.0,0.0,0.0);
   snd_engine->setLooping(true);
  }
  snd_engine_pitch_low=cfg.Getval_double("Sound/Engine/pitch_low");
  snd_engine_pitch_high=cfg.Getval_double("Sound/Engine/pitch_high");
 } catch(openalpp::Error e) {
  std::cerr << e << "\n";
 }

posted @ 2008-05-08 10:31 bloodbao 阅读(188) | 评论 (0)编辑 收藏

ODE常用变量:
dWorldID world;
dSpaceID space;
dJointGroupID  contactgroup;
dBodyID body;
dGeomID geom;
初始化:
void InitODE(){
 dInitODE();
 world=dWorldCreate();
 space=dHashSpaceCreate(0);
 contactgroup=dJointGroupCreate(0);
 dWorldSetGravity(world,0,-9.8,0);
}
回调函数:计算碰撞点
void nearCallback(void* node, dGeomID o1, dGeomID o2)
{
  int i=0;
  dBodyID b1=dGeomGetBody(o1);
  dBodyID b2=dGeomGetBody(o2);
  const int MAX_CONTACTS = 8;
  if(b1 && b2 && dAreConnectedExcluding(b1,b2,dJointTypeContact))return;
  dContact contact[MAX_CONTACTS];
    for(i=0;i<MAX_CONTACTS;++i)
  {
    contact[i].surface.mode=dContactBounce | dContactSoftCFM;
    contact[i].surface.mu=100000.0;
    contact[i].surface.mu2=.00001;
    contact[i].surface.bounce=.2;
    contact[i].surface.bounce_vel=.1;
    contact[i].surface.soft_cfm=.0000001;
  }
    int numc=dCollide(o1,o2,MAX_CONTACTS,&contact[0].geom,sizeof(dContact));
  if(numc>0)
  {
    for(i=0;i<numc;i++)
    {
      dJointID c=dJointCreateContact(world,contactgroup,&contact[i]);
      dJointAttach(c,b1,b2);
    }
  }
}
程序主循环
while(device->run())
 {
  setPosition(geom);
  dJointGroupEmpty (contactgroup);    //清空碰撞点组
  driver->beginScene(true, true, SColor(0,200,200,200));
  dSpaceCollide (space,0,&nearCallback); //通过回调函数计算碰撞点等数据
  dWorldQuickStep(world,0.025); //使物理世界随着时间变化
  smgr->drawAll();
  guienv->drawAll();

  driver->endScene();
 }

posted @ 2008-05-08 10:27 bloodbao 阅读(506) | 评论 (4)编辑 收藏


概要:雨粒子每刻的动画使用输出流,在每一帧都使用geometry Shader扩成billboard.
最后,雨粒子的渲染使用的纹理库存储在一个纹理阵列。使用DX10和GeForce8 系列GPU。
1.应用风和重力使粒子一直在作动画。
2.把粒子扩成要在每一帧渲染的精灵。
3.渲染精灵
1.(1)C++使用输出流
//设立渲染点列表,每个粒子存一个顶点。
pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
pd3dDevice->IASetInputLayout(g_pVertexLayoutRainVertex);
//决定哪个顶点缓冲我们既将要渲染
假如这是第一帧我们渲染一个预产生的顶点帧g_pParticleStart
 static bool firstFrame=true;
 ID3D10Buffer* pBuffers[1];
 if(firstFrame)
  pBuffers[0]=g_pParticleStart;
 else
  pBuffers[0]=g_pParticleDrawFrom;
 pDevice->IASetVertexBuffers(0,1,pBuffers,stride,offset);
 //指向正确的输出缓冲
 pBuffers[0] = g_pParticleStreamTo;
        pd3dDevice->SOSetTargets( 1, pBuffers, offset );
       
        // 画图,使粒子动画
        D3D10_TECHNIQUE_DESC techDesc;
        g_pTechniqueAdvanceRain->GetDesc( &techDesc );
        g_pTechniqueAdvanceRain->GetPassByIndex(0)->Apply(0);

        pd3dDevice->Draw(g_numRainVertices , 0 );

        // Get back to normal
        pBuffers[0] = NULL;
        pd3dDevice->SOSetTargets( 1, pBuffers, offset );

        // Swap buffers交换缓冲区
        ID3D10Buffer* pTemp = g_pParticleDrawFrom;
        g_pParticleDrawFrom = g_pParticleStreamTo;
        g_pParticleStreamTo = pTemp;
   
        firstFrame = false;
2.(2)HLSL--使用Geometry shader Expanding

GeometryShader gsStreamOut = ConstructGSWithSO( CompileShader( vs_4_0, VSAdvanceRain() ), "POSITION.xyz; SEED.xyz; SPEED.xyz; RAND.x; TYPE.x" ); 
technique10 AdvanceParticles
{
    pass p0
    {
        SetVertexShader( CompileShader( vs_4_0, VSAdvanceRain() ) );
        SetGeometryShader( gsStreamOut );
        SetPixelShader( NULL );
       
        SetDepthStencilState( DisableDepth, 0 );
    } 
}
(3)HLSL--使用Geometry shader Extruding
// GS for rendering rain as point sprites.  Takes a point and turns it into 2 tris.
[maxvertexcount(4)]
void GSRenderRain(point VSParticleIn input[1], inout TriangleStream<PSSceneIn> SpriteStream)
{
    float totalIntensity = g_PointLightIntensity*g_ResponsePointLight + dirLightIntensity*g_ResponseDirLight;
    if(!cullSprite(input[0].pos,2*g_SpriteSize) && totalIntensity > 0)
    {   
        PSSceneIn output = (PSSceneIn)0;
        output.type = input[0].Type;
        output.random = input[0].random;
      
        float3 pos[4];
        GenRainSpriteVertices(input[0].pos.xyz, input[0].speed.xyz/g_FrameRate + g_TotalVel, g_eyePos, pos);
       
        float3 closestPointLight = g_PointLightPos;
        float closestDistance = length(g_PointLightPos - pos[0]);
        if( length(g_PointLightPos2 - pos[0]) < closestDistance )
           closestPointLight = g_PointLightPos2;
       
        output.pos = mul( float4(pos[0],1.0), g_mWorldViewProj );
        output.lightDir = g_lightPos - pos[0];
        output.pointLightDir = closestPointLight - pos[0];
        output.eyeVec = g_eyePos - pos[0];
        output.tex = g_texcoords[0];
        SpriteStream.Append(output);
               
        output.pos = mul( float4(pos[1],1.0), g_mWorldViewProj );
        output.lightDir = g_lightPos - pos[1];
        output.pointLightDir = closestPointLight - pos[1];
        output.eyeVec = g_eyePos - pos[1];
        output.tex = g_texcoords[1];
        SpriteStream.Append(output);
       
        output.pos = mul( float4(pos[2],1.0), g_mWorldViewProj );
        output.lightDir = g_lightPos - pos[2];
        output.pointLightDir = closestPointLight - pos[2];
        output.eyeVec = g_eyePos - pos[2];
        output.tex = g_texcoords[2];
        SpriteStream.Append(output);
               
        output.pos = mul( float4(pos[3],1.0), g_mWorldViewProj );
        output.lightDir = g_lightPos - pos[3];
        output.pointLightDir = closestPointLight - pos[3];
        output.eyeVec = g_eyePos - pos[3];
        output.tex = g_texcoords[3];
        SpriteStream.Append(output);
       
        SpriteStream.RestartStrip();
    }  
}

3.
渲染点精灵
使用DX10新特性Texture Array
渲染雾
运行范例:
范例显示两个点光源和一条直射光下的桥。
左键控制直射光。

posted @ 2008-05-08 10:25 bloodbao 阅读(376) | 评论 (0)编辑 收藏

posted @ 2008-05-06 21:28 bloodbao 阅读(178) | 评论 (0)编辑 收藏

哎,,被雨淋得死,全身都在发抖,明显不在状态,结果是回去等通知。 估计是没戏了,再过两三天把面试过程总结出来。 无语中。。。。。。。。。。。。。
posted @ 2008-05-06 21:02 bloodbao 阅读(108) | 评论 (0)编辑 收藏

仅列出标题
共6页: 1 2 3 4 5 6