blender2.8 使用教程 贴图纹理快捷键等。

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/lengyoumo/article/details/90237454

新版本blender2.8虽然与2.79版本号只差0.01,但却有着天翻地覆的变化。新版本功能更加强大,交互更加人性,但也有不少问题。
新版本不仅支持雕塑功能,还支持编辑uv,但是,mac系统瞎绝不能用 texturepaint 闪退 闪退 闪退!!!win系统没问题。

可以看出blender的野心非常大,现在的blender不仅是一个出色的建模工具,还是一个很好的影视工具和游戏引擎

2.8 的bug:
我觉得最严重的bug 莫过于使用texture editor 视图会崩溃的问题。这个太狠了。mac 下。

添加贴图

1,选中物体,按tab 进入模型编辑模式。
2,按A 全选模型所有面
3,按u 选择智能扩展,将uv展开。选择textre即可查看uv位置
3.1 此时选择菜单uv 中最下方的导出uv图,即可导入带格子的图,用ps等软件加工好uv图后可以选择重
载,将图倒回来。
4,点击选项卡,进入shading视图
5,shading视图的下方是节点视图,点击add,添加 image texture,然后选择指定的texture(也可以是3.1里处理过倒图),并将color节点与输出节点的基础色相连,即完成了贴图。

即时绘制贴图 或 雕刻模型

1,选中物体,按tab 进入模型编辑模式。
2,按A 全选模型所有面
3,按u 选择智能扩展,将uv展开。
3.1 此时选择菜单uv 中最下方的导出uv图,即可导入带格子的图,用ps等软件加工好uv图后可以选择重
载,将图倒回来。
3.1 也可以直接打开已有的贴图
3 .2 可以在图像菜单中将贴图另存为

4,点击选项卡,进入shading视图
5,shading视图的下方是节点视图,点击add,添加 image texture,然后选择指定的texture(也可以是3.1里处理过倒图),并将color节点与输出节点的基础色相连,即完成了贴图。

6,进图texture paint模式,或是在任意视图的编辑模式改为纹理绘制模式。
7,点击右侧的工具栏,进入texture栏目,选择一个合适的图像类型 和颜色,然后就可以在texture paint视图或纹理绘制模式中直接对模型进行上色修改。

对了,要在 设置右上角当前视图显示模式为渲染才 能看到效果

操作技巧 + 快捷键

tab:切换物体模式与编辑模式
command / ctrl + 1-5 :细分模型。
u: 选择展开uv模式
p: 分离
shift + d :复制整个模型,或复制模型的一部分作为独立的模型出来。一般在编辑模式下,选中物体的一部分然后按,当回到物体模式后就会看到部分独立了。 如果 shift +d > x/y/z >数字 就沿着固定位置
alt +z 切换模型显示模式
F:填充 选择几个点,按f就填充了面
ctrl + 鼠标右键: 范围选择
B: 矩形选择
ctrl+j :合并连个物体
M: 选中后按m 成组
j: 填充边 选中两个边。自动增加边

alt 加 鼠标左键 循环选择
ctrl i 反选

O : 范围选择模式。 激活o, 选中一个点线面后,进行缩放、旋转,移动就会范围激活,按住左键的同时鼠标滚轮可以调整范围, 也可以在屏幕上中方设定范围的类型,很有用。

ctrl +鼠标右键: 点的编辑模式下,添加新的节点。

非常强大的重要技巧

ctrl l : 物体选择
alt + 鼠标左键:快速圈选点,边,面
选中点线面 > alt+ r/g/s : 沿着法线 旋转/移动/缩放
选中几个点线面 > r/g/s/ > x/y/z > 数值 沿着指定的方向,旋转/移动/缩放,指定的数值
(如果是选中半个球体的面,然后 s > z > 0,就会把那个方向的球面铺平,
如果是一条点参差不齐的边, 选中几个点后, s > z > 0,就会让乱边变整齐,非常神奇)

选中点线面 > G > x/y/z >数值 沿着 x y z 移动指定数值
选中点线面 > G > G > 数值 : 沿着已有的轨迹移动,填数值的话就是精确移动。

shift + tab : 吸附/捕捉 模式。 也可以通过在屏幕右上角设置。可以设置吸附点线面。

点边模式,按ctrl+R 然后点击任意一个边,都可以 在中点加一个节点(可一个面上的多条连续边同时分点,也可以按住鼠标移动到指定的位置加点。) ,如果此时用鼠标左键拖,就能生成一个按比例调整的线

x : 是删除菜单,里面的limited ssolve 是底边型化神器

shift + g: 高级选择

修改器

修改器,只能在物体模式下才能应用

knife的用法

使用knife 切割模型后 按回车即可确认切割。

曲线转换成模型

方法一

1,add 一个曲线,然后按tab进入编辑模式。
2,将曲线改成需要的形状后,选择左上角的物体 - >转换为(不是转换!)->曲线/绒球/曲面/文字转网格, 此时曲线已经成为网格对象,切换到物体模式。
3,切换到物体模式,选择修改器->表皮,即可完成曲线转模型

方法二

1,add 一个曲线,然后按tab进入编辑模式。
2,在右边修改栏中 选择曲线的 物理数据->集合数据-> 设置深度与倒角,可以看到曲线已经变成模型了。只设置深度则只会生成面。

生成的面方向不对/反向 /反转面/反转法线

当编辑线段或顶点后,按f封面,有时就会发现面是黑的,也就是反方向的。这时候只需要点击模型,进入编辑模式,选中面,然后点击左上角的mesh>normals>reculculat inside / outside 。即可让面变过来!

2.8预览
https://docs.blender.org/manual/zh-hans/dev/modeling/modifiers/deform/laplacian_smooth.html

展开阅读全文

纹理贴图)问题

Deleting intermediate files and output files for project '3D2 - Win32 Debug'.rn--------------------Configuration: 3D2 - Win32 Debug--------------------rnCompiling resources...rnCompiling...rnStdAfx.cpprnCompiling...rn3D2.cpprn3D2Doc.cpprn3D2View.cpprnD3DWnd.cpprnD:\3D\3D2\D3DWnd.cpp(195) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of datarnD:\3D\3D2\D3DWnd.cpp(195) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of datarnD:\3D\3D2\D3DWnd.cpp(196) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of datarnD:\3D\3D2\D3DWnd.cpp(196) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of datarnMainFrm.cpprnTHRDCORE.CPPrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(267) : error C2065: '_AFX_CTL3D_STATE' : undeclared identifierrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(267) : error C2065: 'pCtl3dState' : undeclared identifierrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(267) : error C2065: '_afxCtl3dState' : undeclared identifierrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(267) : error C2106: '=' : left operand must be l-valuernF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(268) : error C2227: left of '->m_pfnAutoSubclass' must point to class/struct/unionrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(269) : error C2227: left of '->m_pfnAutoSubclass' must point to class/struct/unionrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(272) : error C2065: '_AFX_CTL3D_THREAD' : undeclared identifierrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(272) : error C2065: 'pTemp' : undeclared identifierrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(272) : error C2065: '_afxCtl3dThread' : undeclared identifierrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(272) : error C2106: '=' : left operand must be l-valuernF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(553) : error C2065: 'WM_IDLEUPDATECMDUI' : undeclared identifierrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(631) : error C2065: 'AfxFindMessageEntry' : undeclared identifierrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(632) : error C2440: '=' : cannot convert from 'int' to 'const struct AFX_MSGMAP_ENTRY *'rn Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style castrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(639) : error C2440: '=' : cannot convert from 'int' to 'const struct AFX_MSGMAP_ENTRY *'rn Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style castrnF:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP(639) : fatal error C1903: unable to recover from previous error(s); stopping compilationrnGenerating Code...rnError executing cl.exe.rnrn3D2.exe - 15 error(s), 4 warning(s)rnrnrn不知道\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP 这个CPP文件是出了什么问题rn谢谢高人,辛苦了rn 论坛

'); (window.slotbydup = window.slotbydup || []).push({ id: "u4221910", container: s }); })();

懂OSG的请进!关于贴图纹理的问题!

[code=C/C++]rn//这是OSG画矩形并贴上纹理图片的函数rnosg::ref_ptr setTex(const std::string& filename)rnrn osg::Group* group = new osg::Group;rn osg::Geometry* geom = new osg::Geometry;rnrn osg::Vec3Array* vertices = new osg::Vec3Array(4);rn vertices->push_back(osg::Vec3(0,0,0));rn vertices->push_back(osg::Vec3(0,0,1));rn vertices->push_back(osg::Vec3(1,0,1));rn vertices->push_back(osg::Vec3(1,0,0));rn geom->setVertexArray(vertices);rnrn osg::Vec2Array* texcoords = new osg::Vec2Array(4);rn texcoords->push_back(osg::Vec2(0.0f,0.0f));rn texcoords->push_back(osg::Vec2(1.0f,0.0f));rn texcoords->push_back(osg::Vec2(1.0f,1.0f));rn texcoords->push_back(osg::Vec2(0.0f,1.0f));rnrn //(*texcoords)[0].set(0.0f,0.0f);rn //(*texcoords)[1].set(1.0f,0.0f);rn //(*texcoords)[2].set(1.0f,1.0f);rn //(*texcoords)[3].set(0.0f,1.0f);rn geom->setTexCoordArray(0,texcoords);rnrn //osg::Vec3Array* normals = new osg::Vec3Array(1);rn //(*normals)[0].set(-1.0f,0.0f,0.0f);rn //geom->setNormalArray(normals);rn //geom->setNormalBinding(osg::Geometry::BIND_OVERALL);rnrn //osg::Vec4Array* colors = new osg::Vec4Array(1);rn //(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);rn //geom->setColorArray(colors);rn //geom->setColorBinding(osg::Geometry::BIND_OVERALL);rnrn geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,4));rnrn // set up the texture state. rn osg::Texture2D* texture = new osg::Texture2D;rn texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state.rn //texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);rn //texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);rn //texture->setBorderColor(osg::Vec4(1.0f,1.0f,1.0f,0.5f)); // only used when wrap is set to CLAMP_TO_BORDERrn texture->setImage(osgDB::readImageFile(filename));rnrn osg::StateSet* stateset = geom->getOrCreateStateSet();rn stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);rn stateset->setMode(GL_BLEND,osg::StateAttribute::ON);rn stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);rnrn osg::Geode* geode = new osg::Geode;rn geode->addDrawable(geom);rn group->addChild(geode);rnrn return group;rnrn[/code]rn[code=C/C++]rn//mian()rnint main(int argc, char* argv[])rnrn osgViewer::Viewer viewer; rn osg::Group * root = new osg::Group(); rnrn root->addChild(setTex("forestRoof.png").get());rn viewer.setSceneData(root); rnrn viewer.run(); rn return 0;rnrn[/code]rnrnVS2008 SP1 ,XP ,OSG2.9.8rn问题是贴不上贴图纹理。请大牛解析一下。谢谢!rnrn 论坛

'); (window.slotbydup = window.slotbydup || []).push({ id: "u4623113", container: s }); })();

openGL贴图显示纹理的标准流程是什么?

我有个贴图显示纹理图像的openglGL程序,在一台式机(HP Compaq dc7600,xp系统)上运行显示没有问题,考到一台联想(7663MS3,windows7系统)上怎么就一点不显示呢?应该不是硬件的问题,因为我从别人那里考的一个opengl的exe能够显示纹理。rn我猜想是不是我的程序不规范?rn我写一下我的程序流程,请高手帮我查一查:rn1.OnCreate()中:rnif(hglrc==NULL)rnrn PIXELFORMATDESCRIPTOR pfd=rn sizeof(PIXELFORMATDESCRIPTOR),rn 1,rn PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,rn PFD_TYPE_RGBA,rn 32,//32位颜色深度rn 0,0,0,0,0,0,rn 1,//alpharn 0,rn 0,//rn 0,0,0,0,rn 32,//32位z缓存rn 0,rn 0,rn PFD_MAIN_PLANE,rn 0,0,0,0rn ;rnrn CClientDC clientdc(this);rn this->GetClientRect(&m_ClientRect);//窗口大小rn int cpf=ChoosePixelFormat(clientdc.m_hDC,&pfd);rn SetPixelFormat(clientdc.m_hDC,cpf,&pfd);rn hglrc=wglCreateContext(clientdc.m_hDC); rnrnrn2.OnSize()中:rnGLsizei w=m_ClientRect.Width();rnGLsizei h=m_ClientRect.Height();rnif(!h)rn return;rnCClientDC clientDC(this);rnwglMakeCurrent(clientDC.m_hDC,hglrc);rnglViewport(0,0,w,h);rnglMatrixMode(GL_PROJECTION);rnglLoadIdentity(); rngluPerspective(45.0f,(GLfloat)w/(GLfloat)h,1.0f,50.0f);rnglMatrixMode(GL_MODELVIEW); rnglLoadIdentity(); rnrn3.init()函数:rnrnglGenTextures(1,&intexture[0]); rnglBindTexture(GL_TEXTURE_2D,intexture[0]);rngluBuild2DMipmaps(GL_TEXTURE_2D,4, g_imgbmpWidth2,g_imgbmpHeight2,GL_RGBA,GL_UNSIGNED_BYTE,symbol);rnrnglGenTextures(1,&intexture[1]); rnglBindTexture(GL_TEXTURE_2D,intexture[1]);rngluBuild2DMipmaps(GL_TEXTURE_2D,4, g_terbmpWidth1,g_terbmpHeight1,GL_RGBA,GL_UNSIGNED_BYTE,m_symbol);rnrnglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);rnglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);rnglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);rnglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);rnglTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE,GL_DECAL);rnglEnable(GL_TEXTURE_2D);rnglShadeModel(GL_SMOOTH);rnglEnable(GL_BLEND);//rnglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);// rnrn4.OnDraw()函数中:rnglClearColor(float(m_Bred)/255.0f,float(m_Bgreen)/255.0f,float(m_Bblue)/255.0f,1.0);rnglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);rnrnglEnable(GL_DEPTH_TEST); rnglDepthFunc(GL_LEQUAL); rnrnglTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE,GL_BLEND);rnglEnable(GL_TEXTURE_2D);rnglBindTexture(GL_TEXTURE_2D,intexture[0]); rnrnglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);rnglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);rnglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);rnglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);rnrnglEnable(GL_LINE_SMOOTH);//反走样rnglEnable(GL_BLEND);rnglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);//alpha模式下反走样rn//glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);//20100322无效果rnrnglShadeModel(GL_SMOOTH);rnglPushMatrix();rn glTranslatef(m_fMoveX,m_fMoveY,-3.5);rn glRotatef(m_fAngleX,1.0,0.0,0.0);rn glRotatef(m_fAngleY,0.0,1.0,0.0);rn glRotatef(m_fAngleZ,0.0,0.0,1.0);rn glScalef(m_fGlobalScale,m_fGlobalScale,m_fGlobalScale);//缩放rnrn if(g_imgbmpWidth2>0 && g_imgbmpHeight2>0)rn drawPic();//画纹理1rnrn if(g_terbmpWidth1>0 && g_terbmpHeight1>0)rn rn glBindTexture(GL_TEXTURE_2D,intexture[1]); rn glTexSubImage2D(GL_TEXTURE_2D,0,0,0,g_terbmpWidth1,g_terbmpHeight1,GL_RGBA,GL_UNSIGNED_BYTE,m_symbol); rn glEnable(GL_LIGHTING); rn glEnable(GL_LIGHT0); rn GLfloat light_position[]=0.0f,6.0f,5.5f,0.0f; rn GLfloat light_ambient[]=1.0f,1.0f,1.0f,0.0f; rn GLfloat mat_env[]=0.75f,0.75f,0.75f,0.0f; rn glLightfv(GL_LIGHT0,GL_POSITION,light_position); rn glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); rn glMaterialfv(GL_FRONT,GL_AMBIENT,mat_env); rn draw(); //画纹理2rn glDisable(GL_LIGHTING);rn rn glDisable(GL_TEXTURE_2D);rn glDisable(GL_BLEND);rnglPopMatrix();rnglFlush();rnSwapBuffers(pdc->m_hDC);rnrnrn一共4个地方,我按顺序写的,请帮我看看哪里有问题,恳请帮我指出来,谢谢!rn 论坛

shader 贴图纹理失真,求救啊!!

我现在做的是:手动创建了一个房间(一个长方体),其每个面加载了一张图片纹理,房间里放了一些3D模型,使用了16个聚光灯光照(延时光照处理),这些功能都实现了,但是问题是:所有的图片纹理与加入的图片不一样,很难看,颜色严重失真,请看下面的两幅图:rnrnshader文件.fx如下(修改别人的代码),望各们大侠指教啊!rn//-------------------------------------------------------------------------------rn// Name: deferred.fxrn// Author: Nikita Kindt (nk47@bk.ru)rn// Last Modified: 17/06/06rn//-------------------------------------------------------------------------------rnfloat4x3 c_mWorld;rnfloat4x3 c_mView;rnfloat4x3 c_mViewInverse;rnfloat4x4 c_mProjection;rnfloat4x4 c_mViewProjection;rn// light parametersrnfloat3 c_vLightDir;rnfloat4 c_vLightPos;rnfloat4 c_vSpotlightCoeff;rnfloat4 c_vLightDiffuse;rnfloat4 c_vLightSpecular;rn// material parametersrnfloat4 c_vMaterialDiffuse;rnfloat4 c_vMaterialSpecular;rnfloat c_fSpecularPower;rn// texturesrntexture2D c_tDiffuseMap;rntexture2D c_tSceneMaterialMap;rntexture2D c_tSceneNormalMap;rntexture2D c_tScenePositionXYMap;rntexture2D c_tScenePositionZMap;rnrnsampler DiffuseSampler = sampler_staternrnTexture = ;rnrnAddressU = Wrap;rnAddressV = Wrap;rnrnMagFilter = Linear;rnMinFilter = Linear;rnMipFilter = Linear;rn;rn// rendertargetsrnsampler SceneMaterialSampler = sampler_staternrnTexture = ;rnMagFilter = Point;rnMinFilter = Point;rn;rnsampler SceneNormalSampler = sampler_staternrnTexture = ;rnMagFilter = Point;rnMinFilter = Point;rn;rnsampler ScenePositionXYSampler = sampler_staternrnTexture = ;rnMagFilter = Point;rnMinFilter = Point;rn;rnsampler ScenePositionZSampler = sampler_staternrnTexture = ;rnMagFilter = Point;rnMinFilter = Point;rn;rnrnstruct VS_INPUT_BUILDrnrn float3 vPos : POSITION0;rn float2 vTex0 : TEXCOORD0;rn float3 vNrm : NORMAL0;rn float3 vTan : TANGENT0;rn float3 vBin : BINORMAL0;rn;rnstruct VS_OUTPUT_BUILDrnrnfloat4 vPos : POSITION0;rn float2 vTex0 : TEXCOORD0;rnfloat3 vWorldPos : TEXCOORD1;rnfloat3 vWorldNrm : TEXCOORD2;rn;rnstruct PS_OUTPUT_BUILDrnrnfloat4 vMaterial : COLOR0;rnfloat4 vWorldNrm : COLOR1;rnfloat4 vWorldPosXY : COLOR2;rnfloat4 vWorldPosZ : COLOR3;rn;rnVS_OUTPUT_BUILD vsBuild(VS_INPUT_BUILD i)rnrnVS_OUTPUT_BUILD o;rno.vWorldPos = mul(float4(i.vPos, 1), c_mWorld);rno.vPos = mul(float4(o.vWorldPos, 1), c_mViewProjection); rno.vTex0 = i.vTex0; rno.vWorldNrm = normalize(mul(float4(i.vNrm, 0), c_mWorld));rnrnreturn o;rn;rn// psBuild()rn// put geometry data into render targetsrnPS_OUTPUT_BUILD psBuild(VS_OUTPUT_BUILD i) rnrnPS_OUTPUT_BUILD o;rn// materialrnfloat4 vDiffuseMaterial = tex2D(DiffuseSampler, i.vTex0);rno.vMaterial.rgb = vDiffuseMaterial;rno.vMaterial.a = 1.0;rnrn// convert normal to texture space [-1;+1] -> [0;1]rno.vWorldNrm.xyz = i.vWorldNrm * 0.5 + 0.5;rno.vWorldNrm.w = 0.0;rnrn// positionrno.vWorldPosXY = float4(i.vWorldPos.xy, 0, 0);rno.vWorldPosZ = float4(i.vWorldPos.z, 0, 0, 0);rnreturn o;rn;rnrnstruct PS_INPUT_LIGHTrnrnfloat2 vTex0 : TEXCOORD0;rn;rn// psLighting()rn// uses data from textures (previous render targets)rnfloat4 psLighting(PS_INPUT_LIGHT i) : COLOR0rnrnfloat3 vDiffuseMaterial = tex2D(SceneMaterialSampler, i.vTex0).rgb;rnfloat3 vSpecularMaterial = tex2D(SceneMaterialSampler, i.vTex0).a;rnrn// normals are stored in texture space [0,1] -> convert them back to [-1,+1] rangernfloat3 vWorldNrm = (tex2D(SceneNormalSampler, i.vTex0) - 0.5) * 2;rnfloat3 vWorldPos;rnvWorldPos.xy = tex2D(ScenePositionXYSampler, i.vTex0).xy;rnvWorldPos.z = tex2D(ScenePositionZSampler, i.vTex0).x;rnfloat3 vLightDir = normalize(c_vLightPos - vWorldPos);rnfloat4 color;rnrn//float3 vEyeVec = normalize(c_mViewInverse[3].xyz - vWorldPos); rn//float3 vHalfVector = normalize(vEyeVec+vLightDir);rn//float fLength = distance(c_vLightPos,vWorldPos);rn//float fAttenuation = 1.0f-fLength/c_vLightPos.w;rn//float3 vDiffuseIntensity = c_vLightDiffuse.xyz*saturate(dot(vLightDir, vWorldNrm))* vDiffuseMaterial;rn//float3 vSpecularIntensity = c_vLightSpecular.xyz*pow(saturate(dot(vHalfVector,vWorldNrm)),30.0f)*vSpecularMaterial;rn//float fSpotlightcosine=saturate(dot(-vLightDir, c_vLightDir)); rn//if(fSpotlightcosine < 0.98 )rn//rn //fSpotlightcosine=0.0f;rn// rn//float fSpotlightEffect=pow(fSpotlightcosine,c_vSpotlightCoeff.y);rn//color.rgb = (vDiffuseIntensity + vSpecularIntensity )*fAttenuation*fSpotlightEffect;rn//color.rgb += 0.0025 * vDiffuseMaterial;rn//color.a = 1.0;rn rnfloat coneDot = saturate(dot(-vLightDir, c_vLightDir)); rnrnbool coneCondition = (coneDot >= 0.98);rnif (coneCondition)rnrn float3 vEyeVec = normalize(c_mViewInverse[3].xyz - vWorldPos); rn float3 vDiffuseIntensity = saturate(dot(vLightDir, vWorldNrm));rn float3 vSpecularIntensity = pow(saturate(dot(vEyeVec, reflect(-vLightDir, vWorldNrm))), c_fSpecularPower);rn rn color.rgb = vDiffuseIntensity* c_vLightDiffuse.xyz*vDiffuseMaterial +rn vSpecularIntensity * c_vLightSpecular.xyz * vSpecularMaterial;rn //color.rgb = vDiffuseIntensity* c_vLightDiffuse.xyz*vDiffuseMaterial;rn rn float coneAttenuation = pow(coneDot,20);rn color.rgb = color.rgb * coneAttenuation+0.0085 * vDiffuseMaterial;rn color.a = 1.0;rn rnrnelsernrn color.rgb = 0.0095 * vDiffuseMaterial ;rn color.a = 1.0;rnrnrn// here we add color to show how lighting pass affects the scenern//color.rgb += c_vLightSpecular*0.005;rnrnreturn color;rn;rnrntechnique buildPassrnrnpass p0rnrn VertexShader = compile vs_1_1 vsBuild();rn PixelShader = compile ps_2_0 psBuild();rn rn CullMode = ccw;rn FillMode = solid;rn Zenable = true;rn ZWriteEnable = true;rn ZFunc = less;rn StencilEnable = false;rn AlphaBlendEnable = false;rn AlphaTestEnable = false; rn ColorWriteEnable = red | green | blue;rnrnrntechnique lightPassrnrn pass p0rnrn VertexShader = NULL;rn PixelShader = compile ps_2_0 psLighting();rn rn CullMode = none;rn FillMode = solid;rn Zenable = false;[img=c://pic.png][/img][img=c://pic1.png][/img]rn StencilEnable = true; rn AlphaBlendEnable = true;rn Srcblend = One;rn Destblend = One;rn AlphaTestEnable = false; rn ColorWriteEnable = red | green | blue;rnrn;rn 论坛

feedLoading.gif

没有更多推荐了,返回首页

原创
73
粉丝
13
喜欢
23
评论
13
等级:
访问:
6万+
积分:
1387
排名:
5万+
勋章:

GitHub

绑定GitHub第三方账户获取

专栏达人

授予成功创建个人博客专栏的用户。专栏中添加五篇以上博文即可点亮!撰写博客专栏浓缩技术精华,专栏达人就是你!

持之以恒

授予每个自然月内发布4篇或4篇以上原创或翻译IT博文的用户。不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!

勤写标兵Lv1

授予每个自然周发布1篇到3篇原创IT博文的用户。本勋章将于次周周三上午根据用户上周的博文发布情况由系统自动颁发。

最新评论


此为网页(blog.csdn.net)快照,查看来源