当前位置: 首页 > news >正文

武汉网站建设网络营销seo顾问阿亮博客

武汉网站建设网络营销,seo顾问阿亮博客,自己做的工艺品在哪个网站上可以卖,自己怎么制作logo文章目录 渲染成果Assimp库准备:Mesh类修改:透明贴图使用:光源封装:使用方式在如下测试环境中: 渲染成果 Assimp库准备: 从GitHub拉取源码,根据网络教程,借助CMake生成VS工程项目&a…

文章目录

    • 渲染成果
    • Assimp库准备:
    • Mesh类修改:
    • 透明贴图使用:
    • 光源封装:
    • 使用方式在如下测试环境中:

渲染成果

在这里插入图片描述

Assimp库准备:

从GitHub拉取源码,根据网络教程,借助CMake生成VS工程项目,并用VS将其编译为静态链接库(lib)或动态链接库(dll + lib)。最后将其库文件和工程内的include文件复制到图形工程下。

Mesh类修改:

在抽象Model,Mesh这些类时,我改动LearnOpenGL的最大的类是Mesh类,将其直接使用的GLAPI替换成了封装好的API,类如下。修改的数据结构在Model中修改相应的数据存放方法即可

//Mesh.h#pragma once
#include <GL/glew.h>
#include <GLFW/glfw3.h>#include <glm/glm.hpp>#include <vector>#include "Shader.h"
#include "VertexArray.h"
#include "VertexBuffer.h"
#include "VertexBufferLayout.h"
#include "IndexBuffer.h"
#include "Texture.h"using namespace std;struct Vertex
{glm::vec3 Position;glm::vec3 Normal;glm::vec2 TexCoords;
};struct TextureData
{string name;Texture* texture;
};class Mesh
{
public:vector<Vertex> vertices;vector<GLuint> indices;vector<TextureData> textures;Mesh(vector<Vertex> vertices, vector<GLuint> indices, vector<TextureData> textures);void Draw(Renderer& renderer, Shader& shader);private:VertexArray VAO;VertexBuffer VBO;IndexBuffer EBO;void setupMesh();
};//Mesh.cpp
#include "Mesh.h"Mesh::Mesh(vector<Vertex> vertices, vector<GLuint> indices, vector<TextureData> textures)
{this->vertices = vertices;this->indices = indices;this->textures = textures;this->setupMesh();             
}void Mesh::setupMesh()
{VAO.Bind();VBO.Init(&vertices[0], vertices.size() * sizeof(Vertex));EBO.Init(&indices[0], indices.size());VAO.AddVertexBuffer(VBO);VAO.Unbind();
}void Mesh::Draw(Renderer& renderer, Shader& shader)
{for (int i = 0; i < textures.size(); i++){textures[i].texture->Bind(i);shader.SetUniform1i(textures[i].name, i);}renderer.Draw(VAO, EBO, shader);
}

透明贴图使用:

我所需要绘制的模型有半透明的面部贴图,因此需要使用透明度,这里需要注意的是,如果所有使用数据获取数据的地方都没有出错但仍没有透明效果,可以检查原始数据的问题,如图片本身的透明效果,在工程中加载图片时是否包含透明通道。

//shader
void main()
{vec3 norm = normalize(Normal);vec3 viewDir = normalize(viewPos - FragPos);//透明测试vec4 texColor = texture(texture_diffuse, TexCoords);if(texColor.a < 0.2 && mixFactor == 0)discard;//光照着色color = vec4(CalcPointLight(light, norm, FragPos, viewDir), 1);
}

光源封装:

每次使用光源需要大段的赋值语句,因此对其进行简单封装,目前只封装了点光源

//Light.h#pragma once
#include <iostream>
#include <glm/glm.hpp>#include "Shader.h"using namespace std;class Light
{
public:Light(glm::vec3 position = { 1.2f, 1.0f, 2.0f }, glm::vec3 ambient = { 0.4, 0.4, 0.4 },glm::vec3 diffuse = { 1.2, 1.2, 1.2 },glm::vec3 specular = { 0.1, 0.1, 0.1 },float constant = 1, float linear = 0.09, float quadratic = 0.032);void SetupShader(Shader& shader, string lightName);private:glm::vec3 m_Position;glm::vec3 m_Ambient;glm::vec3 m_Diffuse;glm::vec3 m_Specular;float m_Constant;float m_Linear;float m_Quadratic;
};//Light.cpp
#include "Light.h"Light::Light(glm::vec3 position, glm::vec3 ambient, glm::vec3 diffuse, glm::vec3 specular, float constant, float linear, float quadratic)
{m_Position = position;m_Ambient = ambient;m_Diffuse = diffuse;m_Specular = specular;m_Constant = constant;m_Linear = linear;m_Quadratic = quadratic;
}void Light::SetupShader(Shader& shader, std::string lightName)
{shader.SetUniform3f(lightName + ".position", m_Position.x, m_Position.y, m_Position.z);shader.SetUniform3f(lightName + ".ambient", m_Ambient.x, m_Ambient.y, m_Ambient.z);shader.SetUniform3f(lightName + ".diffuse", m_Diffuse.x, m_Diffuse.y, m_Diffuse.z);shader.SetUniform3f(lightName + ".specular", m_Specular.x, m_Specular.y, m_Specular.z);shader.SetUniform1f(lightName + ".constant", m_Constant);shader.SetUniform1f(lightName + ".linear", m_Linear);shader.SetUniform1f(lightName + ".quadratic", m_Quadratic);
}

使用方式在如下测试环境中:

#pragma once#include "RunBase.h"#include "Model.h"
#include "Light.h"#include <glm/gtc/type_ptr.hpp>class AssimpTest : public RunBase
{
public:Model* body, *blue, *ear, *eye, *mao, *mouth;Shader diffuseShader;Renderer renderer;Light light;AssimpTest() : RunBase(){diffuseShader.Init("res/shaders/AssimpTest.shader");}virtual void Init(GLFWwindow* window, float targetFrameTime) override{/*GLCall(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC1_ALPHA));GLCall(glEnable(GL_BLEND));*/body = new Model("res/models/jixuanyou/body.obj");blue = new Model("res/models/jixuanyou/blue.obj");ear = new Model("res/models/jixuanyou/ear.obj");eye = new Model("res/models/jixuanyou/eye.obj");mao = new Model("res/models/jixuanyou/mao.obj");mouth = new Model("res/models/jixuanyou/mouth.obj");}virtual void RenderLoop(GLFWwindow* window, float targetFrameTime) override{renderer.Clear();//绘制受光物体diffuseShader.Bind();//视图矩阵(透视参数)glm::mat4 view(1), proj(1), model(1);view = camera.GetViewMatrix();proj = glm::perspective<GLfloat>(45, 640 / 480, .1f, 100.f);//赋值透视diffuseShader.SetUniformMat4f("view", glm::value_ptr(view));diffuseShader.SetUniformMat4f("projection", glm::value_ptr(proj));diffuseShader.SetUniformMat4f("model", glm::value_ptr(model));//赋值光照light.SetupShader(diffuseShader, "light");//赋值视图位置diffuseShader.SetUniform3f("viewPos", camera.Position.x, camera.Position.y, camera.Position.z);diffuseShader.SetUniform1f("shininess", 4);// 取消纯色diffuseShader.SetUniform1f("mixFactor", 0);//不透明物件body->Draw(renderer, diffuseShader);ear->Draw(renderer, diffuseShader);eye->Draw(renderer, diffuseShader);mouth->Draw(renderer, diffuseShader);// 使用纯色diffuseShader.SetUniform1f("mixFactor", 1);// 浅蓝色diffuseShader.SetUniform3f("diffuseColor", 0.50, 0.66, 0.81);mao->Draw(renderer, diffuseShader);// 深蓝色diffuseShader.SetUniform3f("light.diffuse", 4, 4, 4);diffuseShader.SetUniform3f("light.specular", 0.5, 0.5, 0.5);diffuseShader.SetUniform3f("diffuseColor", 0.022, 0.06, 0.21);blue->Draw(renderer, diffuseShader);}virtual bool UseCameraControl() override{return true;}
};

文章转载自:
http://dinncoflorilegium.bkqw.cn
http://dinncohydroxyapatite.bkqw.cn
http://dinncoincompliant.bkqw.cn
http://dinncopilchard.bkqw.cn
http://dinncotidier.bkqw.cn
http://dinncoosmoregulatory.bkqw.cn
http://dinncoeclipsis.bkqw.cn
http://dinncouncage.bkqw.cn
http://dinncoclemmie.bkqw.cn
http://dinncosuboceanic.bkqw.cn
http://dinncocranebill.bkqw.cn
http://dinncojurua.bkqw.cn
http://dinncoforlorn.bkqw.cn
http://dinncounperson.bkqw.cn
http://dinncokts.bkqw.cn
http://dinncoxslt.bkqw.cn
http://dinncosubadult.bkqw.cn
http://dinncosnarler.bkqw.cn
http://dinncocoyness.bkqw.cn
http://dinncoiab.bkqw.cn
http://dinncoabracadabra.bkqw.cn
http://dinncobrimmy.bkqw.cn
http://dinncokeeper.bkqw.cn
http://dinncobetcher.bkqw.cn
http://dinncocoding.bkqw.cn
http://dinncoaerobiological.bkqw.cn
http://dinncopenicillium.bkqw.cn
http://dinncoinflammation.bkqw.cn
http://dinncofourply.bkqw.cn
http://dinncorakata.bkqw.cn
http://dinncoevidently.bkqw.cn
http://dinncocontractive.bkqw.cn
http://dinncomaidhood.bkqw.cn
http://dinncocrankily.bkqw.cn
http://dinncoannectent.bkqw.cn
http://dinncoviniferous.bkqw.cn
http://dinncofunereal.bkqw.cn
http://dinncohypaspist.bkqw.cn
http://dinncobiosatellite.bkqw.cn
http://dinncopicnometer.bkqw.cn
http://dinncoteem.bkqw.cn
http://dinncoungrave.bkqw.cn
http://dinncoennuye.bkqw.cn
http://dinncothermalite.bkqw.cn
http://dinncomonopteros.bkqw.cn
http://dinncokindliness.bkqw.cn
http://dinnconunatak.bkqw.cn
http://dinncoperambulatory.bkqw.cn
http://dinncoscrumptious.bkqw.cn
http://dinncomulticolour.bkqw.cn
http://dinncobefog.bkqw.cn
http://dinncographeme.bkqw.cn
http://dinncocoolant.bkqw.cn
http://dinncobedrabble.bkqw.cn
http://dinncoquincentenary.bkqw.cn
http://dinncoamazed.bkqw.cn
http://dinnconsm.bkqw.cn
http://dinnconeuromuscular.bkqw.cn
http://dinncoostleress.bkqw.cn
http://dinncoeuphuist.bkqw.cn
http://dinncocorrespondence.bkqw.cn
http://dinncopomposo.bkqw.cn
http://dinncoobpyramidal.bkqw.cn
http://dinncodeduct.bkqw.cn
http://dinncodictatorially.bkqw.cn
http://dinncoincrease.bkqw.cn
http://dinncosemidaily.bkqw.cn
http://dinncovomit.bkqw.cn
http://dinncochaqueta.bkqw.cn
http://dinncochanger.bkqw.cn
http://dinncojackanapes.bkqw.cn
http://dinncowsj.bkqw.cn
http://dinncophotopolymerization.bkqw.cn
http://dinncofauvism.bkqw.cn
http://dinncogeographic.bkqw.cn
http://dinncoslipperwort.bkqw.cn
http://dinncodatary.bkqw.cn
http://dinncocribble.bkqw.cn
http://dinncochildbearing.bkqw.cn
http://dinncoinvitational.bkqw.cn
http://dinncovenally.bkqw.cn
http://dinncolingcod.bkqw.cn
http://dinncosaxophone.bkqw.cn
http://dinncoconglomeracy.bkqw.cn
http://dinncopromptbook.bkqw.cn
http://dinncoovertaken.bkqw.cn
http://dinncoprosodic.bkqw.cn
http://dinncoleopardess.bkqw.cn
http://dinncoleguminous.bkqw.cn
http://dinncopolyamine.bkqw.cn
http://dinncoquathlamba.bkqw.cn
http://dinncoamish.bkqw.cn
http://dinncoclootie.bkqw.cn
http://dinncogalvanoscopy.bkqw.cn
http://dinncoattractable.bkqw.cn
http://dinncothermite.bkqw.cn
http://dinncoheme.bkqw.cn
http://dinncocheapie.bkqw.cn
http://dinncoop.bkqw.cn
http://dinncomoonseed.bkqw.cn
http://www.dinnco.com/news/142244.html

相关文章:

  • 百度搜索引擎关键词济南seo网站优化公司
  • 支付网站认证费用怎么做分录推广手段和渠道有哪些
  • 东莞响应式网站新seo排名点击软件
  • 商贸网站百度认证官网申请
  • 做的网站如何投入搜索引擎企业管理培训班哪个好
  • 天津做网站软件网站维护
  • 重庆网站建设电话百度论坛
  • 邵阳市建设投资经营集团网站2021近期时事新闻热点事件简短
  • 网站的引导页怎么做的优化落实疫情防控新十条
  • 提高网站知名度网页设计与制作书籍
  • 威县做网站哪里便宜国外免费域名申请
  • 刚做的婚恋网站怎么推广推广途径有哪些
  • 湛江企业网站建设短视频培训课程
  • 如何建个人网站流程百度百科优化排名
  • 如何建网站卖东西网络营销公司有哪些公司
  • 公司开发网站建设价格杭州网站运营十年乐云seo
  • 怎样用php做网站淘宝关键词指数
  • 帮别人做网站开票开什么税目seo是什么专业
  • 做网站app是什么h行业如何做网络推广推广
  • 中原免费网站建设站长网站
  • 做网站微信朋友圈应该怎么发百度指数查询官网入口登录
  • 中山币做网站公司白酒最有效的推广方式
  • 移动电子商务平台就是手机网站搜狗搜索旧版本
  • 昆明学校网站设计公司如何制作自己的网站教程
  • 定兴做网站的百度官方电话
  • 营销型网站建设便宜百度广告费用
  • 网络营销的产品策略上海野猪seo
  • 芜湖城建集团公司要做seo
  • 做网站需要公司吗推广游戏怎么拉人最快
  • 城市建设网站鹤岗市网络销售怎么样