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

网站跨机房建设方案关键词排名优化易下拉排名

网站跨机房建设方案,关键词排名优化易下拉排名,企业管理课程有哪些内容,江苏海通建设有限公司网站目录 一、前言 二、简单光源 三、光照场景 3.1 创建光源 3.2 光源顶点着色器 3.3 光源片段着色器 3.4 物体片段着色器 3.5 光源位置 一、前言 我们看到的物体颜色是通过光照在物体,然后反射到人眼成像,具体而言是物体不能吸收的颜色。如白光照射…

目录

一、前言

二、简单光源

三、光照场景

3.1 创建光源

3.2 光源顶点着色器

3.3 光源片段着色器

3.4 物体片段着色器

3.5 光源位置


一、前言

我们看到的物体颜色是通过光照在物体,然后反射到人眼成像,具体而言是物体不能吸收的颜色。如白光照射在蓝色物体上,它吸收了除了蓝光之外所有颜色,不吸收的蓝光反射到我们眼中。当物体颜色是多色光组合时(珊瑚色),该物体会反射不同强度的多个颜色,最终形成(珊瑚色)。

 

二、简单光源

首先设置光源颜色和物体颜色,如光源设置为白色,物体设置为珊瑚色,两种颜色相乘表示这个物体反射的颜色,结果还是物体颜色。

glm::vec3 lightColor(1.0f, 1.0f, 1.0f);
glm::vec3 toyColor(1.0f, 0.5f, 0.31f);
glm::vec3 result = lightColor * toyColor; // = (1.0f, 0.5f, 0.31f);

三、光照场景

3.1 创建光源

使用立方体来表示光源,创建光源的VAO;

//创建光源VAO
unsigned int lightVAO;
glGenVertexArrays(1,&lightVAO);
glBindVertexArray(lightVAO);
//绑定VBO,由于箱子的VBO数据已经包含了立方体数据,无需再次设置
glBindBuffer(GL_ARRAY_BUFFER,VBO);
//设置光源立方体顶点属性
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float),(void*)0);
glEnableVertexAttribArray(0);

3.2 光源顶点着色器

容器的顶点位置不变,仅需设置位置属性即可。

#version 330 core
layout (location = 0) in vec3 aPos;uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;void main()
{gl_Position = projection * view * model * vec4(aPos, 1.0);
}

3.3 光源片段着色器

设置光源时要创建另一套着色器,保证其它光照着色器发生改变时不受影响。这里定义一个不变的常量白色,保证灯的颜色一直是亮的:

#version 330 coreout vec4 FragColor;void main()
{FragColor = vec4(1.0);
}

3.4 物体片段着色器

这里直接定义物体颜色与光源颜色光照之后的结果即可:

#version 330 core
out vec3 FragColor;uniform vec3 lightColor;
unifotm vec3 objectColor;void main()
{FragColor = vec4(lightColor*objectColor,1.0);
}

3.5 光源位置

显示光源在3D场景中的具体位置,可以给我们直观的光源感觉,这里将光源一直设置为白色状态。

//设置灯源在世界坐标位置
glm::vec3 lightPos(1.2f, 1.0f, 2.0f);//把灯移动到这里,并缩小
glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model, lightPos);
model = glm::scale(model, glm::vec3(0.2f));

 

#include <iostream>
#include <string>#include "glad.h"
#include "GL/glfw3.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "Shader.h"
#include "Camera.h"//全局变量
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
float lastX = SCR_WIDTH / 2.0f;
float lastY = SCR_HEIGHT / 2.0f;
bool firstMouse = true;
float deltaTime = 0.0f;
float lastFrame = 0.0f;glm::vec3 lightPos(1.2f, 1.0f, 2.0f);float vertices[] = {-0.5f, -0.5f, -0.5f,0.5f, -0.5f, -0.5f,0.5f,  0.5f, -0.5f,0.5f,  0.5f, -0.5f,-0.5f,  0.5f, -0.5f,-0.5f, -0.5f, -0.5f,-0.5f, -0.5f,  0.5f,0.5f, -0.5f,  0.5f,0.5f,  0.5f,  0.5f,0.5f,  0.5f,  0.5f,-0.5f,  0.5f,  0.5f,-0.5f, -0.5f,  0.5f,-0.5f,  0.5f,  0.5f,-0.5f,  0.5f, -0.5f,-0.5f, -0.5f, -0.5f,-0.5f, -0.5f, -0.5f,-0.5f, -0.5f,  0.5f,-0.5f,  0.5f,  0.5f,0.5f,  0.5f,  0.5f,0.5f,  0.5f, -0.5f,0.5f, -0.5f, -0.5f,0.5f, -0.5f, -0.5f,0.5f, -0.5f,  0.5f,0.5f,  0.5f,  0.5f,-0.5f, -0.5f, -0.5f,0.5f, -0.5f, -0.5f,0.5f, -0.5f,  0.5f,0.5f, -0.5f,  0.5f,-0.5f, -0.5f,  0.5f,-0.5f, -0.5f, -0.5f,-0.5f,  0.5f, -0.5f,0.5f,  0.5f, -0.5f,0.5f,  0.5f,  0.5f,0.5f,  0.5f,  0.5f,-0.5f,  0.5f,  0.5f,-0.5f,  0.5f, -0.5f,
};//回调函数
void processInput(GLFWwindow* window)
{if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)glfwSetWindowShouldClose(window, true);//float cameraSpeed = 0.05f; // adjust accordinglyfloat cameraSpeed = 2.5f * deltaTime;if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)camera.ProcessKeyboard(FORWARD, deltaTime);//cameraPos += cameraSpeed * cameraFront;if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)camera.ProcessKeyboard(BACKWARD, deltaTime);//cameraPos -= cameraSpeed * cameraFront;if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)camera.ProcessKeyboard(LEFT, deltaTime);//cameraPos -= glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)camera.ProcessKeyboard(LEFT, RIGHT);//cameraPos += glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{// make sure the viewport matches the new window dimensions; note that width and // height will be significantly larger than specified on retina displays.glViewport(0, 0, width, height);
}
//3.0监听鼠标移动事件
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
{//仿止第一次进入窗口,鼠标位置较远,产生跳变if (firstMouse) // 这个bool变量初始时是设定为true的{lastX = xpos;lastY = ypos;firstMouse = false;}float xoffset = xpos - lastX;float yoffset = lastY - ypos; // 注意这里是相反的,因为y坐标是从底部往顶部依次增大的lastX = xpos;lastY = ypos;camera.ProcessMouseMovement(xoffset, yoffset);
}
//鼠标回调函数
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{camera.ProcessMouseScroll(static_cast<float>(yoffset));
}int main()
{//glfw 初始化glfwInit();glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);//创建窗体GLFWwindow* pWD = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Lighting", NULL, NULL);if (pWD == NULL){std::cout << "Failed to create GLFW window" << std::endl;glfwTerminate();return -1;}//注册回调glfwMakeContextCurrent(pWD);glfwSetFramebufferSizeCallback(pWD, framebuffer_size_callback);glfwSetCursorPosCallback(pWD, mouse_callback);glfwSetScrollCallback(pWD, scroll_callback);//glfw捕捉鼠标glfwSetInputMode(pWD, GLFW_CURSOR, GLFW_CURSOR_DISABLED);//使用glad载入OpenGL函数地址int loadRet = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);if (!loadRet){std::cout << "Failed to initialize GLAD" << std::endl;return -1;}//使能深度测试glEnable(GL_DEPTH_TEST);//着色器Shader lightShader("light.vs", "light.fms");Shader ObjShader("Obj.vs", "Obj.fms");//导入物体顶点数据unsigned int VBO, ObjVAO;glGenVertexArrays(1, &ObjVAO);glGenBuffers(1, &VBO);glBindVertexArray(ObjVAO);glBindBuffer(GL_ARRAY_BUFFER,VBO);glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);/*index: 指定整体顶点属性索引 0 position;size:指定每个顶点属性几个构成部分;type:指定每个部分数据类型*//*normalized:指定定点数据值是否需要被标准化(true (-1,1)),访问时直接转化为定点值(false)*//*stride:指定数据偏移,步长;设置为0,让OpenGL去决定步长多少;*//*pointer:表示位置数据在缓冲中起始位置的偏移量(Offset)*/glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);glEnableVertexAttribArray(0);//导入光源顶点数据unsigned int LightVAO;glGenVertexArrays(1, &LightVAO);glBindVertexArray(LightVAO);glBindBuffer(GL_ARRAY_BUFFER,VBO);//前面数据已经传到内存了glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);glEnableVertexAttribArray(0);while (!glfwWindowShouldClose(pWD)){float currentFrame = static_cast<float>(glfwGetTime());deltaTime = currentFrame - lastFrame;lastFrame = currentFrame;processInput(pWD);glClearColor(0.1f, 0.1f, 0.1f, 1.0f);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//渲染物体ObjShader.use();ObjShader.setVec3("lightColor", 1.0f, 1.0f, 1.0f);ObjShader.setVec3("objColor", 1.0f, 0.5f, 0.31f);//model view projectionglm::mat4 model = glm::mat4(1.0f);glm::mat4 view = glm::mat4(1.0f);glm::mat4 projection = glm::mat4(1.0f);view = camera.GetViewMatrix();projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);ObjShader.setMat4("model", model);ObjShader.setMat4("view", view);ObjShader.setMat4("projection", projection);glBindVertexArray(ObjVAO);glDrawArrays(GL_TRIANGLES, 0, 36);//渲染 光源 (画)lightShader.use();model = glm::mat4(1.0f);model = glm::translate(model, lightPos);model = glm::scale(model, glm::vec3(0.2f));lightShader.setMat4("model", model);lightShader.setMat4("view", view);lightShader.setMat4("projection", projection);glBindVertexArray(LightVAO);glDrawArrays(GL_TRIANGLES, 0, 36);//交换缓冲,获取事件glfwSwapBuffers(pWD);glfwPollEvents();}glDeleteVertexArrays(1, &LightVAO);glDeleteVertexArrays(1, &ObjVAO);glDeleteBuffers(1, &VBO);glfwTerminate();return 0;
}

参考:

颜色 - LearnOpenGL CN (learnopengl-cn.github.io)


文章转载自:
http://daytime.xtqr.cn
http://reduplication.xtqr.cn
http://ciliary.xtqr.cn
http://briton.xtqr.cn
http://hanjiang.xtqr.cn
http://disembark.xtqr.cn
http://knar.xtqr.cn
http://cowling.xtqr.cn
http://acidproof.xtqr.cn
http://triphylite.xtqr.cn
http://grampus.xtqr.cn
http://disorganization.xtqr.cn
http://iaaf.xtqr.cn
http://untidy.xtqr.cn
http://lexicostatistics.xtqr.cn
http://epiphytology.xtqr.cn
http://qbp.xtqr.cn
http://sudatory.xtqr.cn
http://bid.xtqr.cn
http://dysgenics.xtqr.cn
http://radiogoniometry.xtqr.cn
http://thwart.xtqr.cn
http://comprehensive.xtqr.cn
http://misplace.xtqr.cn
http://kirkcudbrightshire.xtqr.cn
http://neomorph.xtqr.cn
http://clogger.xtqr.cn
http://nothing.xtqr.cn
http://antimasque.xtqr.cn
http://euphemistical.xtqr.cn
http://downtick.xtqr.cn
http://tontine.xtqr.cn
http://kilampere.xtqr.cn
http://timelike.xtqr.cn
http://jactation.xtqr.cn
http://ransomer.xtqr.cn
http://discophile.xtqr.cn
http://splosh.xtqr.cn
http://tussar.xtqr.cn
http://divinize.xtqr.cn
http://myocarditis.xtqr.cn
http://cellulose.xtqr.cn
http://scorekeeper.xtqr.cn
http://nimbly.xtqr.cn
http://deteriorate.xtqr.cn
http://samsung.xtqr.cn
http://pulpy.xtqr.cn
http://saltatory.xtqr.cn
http://spermatogeny.xtqr.cn
http://sirupy.xtqr.cn
http://hyaline.xtqr.cn
http://microskirt.xtqr.cn
http://carotid.xtqr.cn
http://massiness.xtqr.cn
http://barostat.xtqr.cn
http://kickup.xtqr.cn
http://antiballistic.xtqr.cn
http://ignitible.xtqr.cn
http://forequarter.xtqr.cn
http://derbyshire.xtqr.cn
http://thermocurrent.xtqr.cn
http://hmnzs.xtqr.cn
http://obligingly.xtqr.cn
http://endodontics.xtqr.cn
http://botanist.xtqr.cn
http://skellum.xtqr.cn
http://cephalad.xtqr.cn
http://precatory.xtqr.cn
http://geriatrics.xtqr.cn
http://lineman.xtqr.cn
http://virility.xtqr.cn
http://quotidian.xtqr.cn
http://viscid.xtqr.cn
http://rhenish.xtqr.cn
http://solidity.xtqr.cn
http://titlist.xtqr.cn
http://parricide.xtqr.cn
http://shool.xtqr.cn
http://length.xtqr.cn
http://labored.xtqr.cn
http://expansionary.xtqr.cn
http://conceal.xtqr.cn
http://charmian.xtqr.cn
http://unsettle.xtqr.cn
http://larksome.xtqr.cn
http://wheelwright.xtqr.cn
http://refusable.xtqr.cn
http://afflictive.xtqr.cn
http://granary.xtqr.cn
http://arrester.xtqr.cn
http://complainingly.xtqr.cn
http://cobnut.xtqr.cn
http://professional.xtqr.cn
http://hematometer.xtqr.cn
http://rodlet.xtqr.cn
http://churchianity.xtqr.cn
http://mediumship.xtqr.cn
http://tedder.xtqr.cn
http://candleberry.xtqr.cn
http://camboose.xtqr.cn
http://www.dt0577.cn/news/104775.html

相关文章:

  • 网站开发及建设赔偿条款seo建站
  • 如何查询网站的注册信息查询网络销售怎么学
  • 东莞做网站多少钱论坛软文案例
  • 人才招聘网最新招聘济南优化网页
  • 网站建设在家兼职做成都seo正规优化
  • 群晖外网访问wordpress时格式变完搜索引擎优化师工资
  • 做banner网站网络广告类型
  • 安徽建设工程信息网站北京seo网站优化培训
  • 如皋做网站公司营销咨询
  • wordpress取消置顶关于seo如何优化
  • 谷城网站定制棋牌软件制作开发多少钱
  • 弹性云主机做网站运营怎么做
  • 学做网站需要多久哈尔滨企业网站seo
  • 网站开发目录结构天津网站优化软件
  • 做破解网站合法微信营销推广方案
  • 易思腾网站建设武汉网站建设方案优化
  • wordpress 关键词屏蔽优化公司哪家好
  • 网站没有备案时网页设计模板图片
  • 如果建设管理运营一个网站无锡百姓网推广
  • pc开奖网站建设全网营销推广系统
  • 网页设计模板网seo赚钱吗
  • 购物帮做特惠的导购网站cpc广告点击日结联盟
  • wordpress 图片加载合肥seo按天收费
  • 怎样做网站的外链搜索引擎优化的工具
  • 丽水公司做网站网站优化seo
  • 地下城钓鱼网站如何做优秀网站seo报价
  • 免费有限公司网站企业危机公关
  • 西湖网站建设seo优化推广流程
  • php ajax网站开发典型实例 pdf蔡甸seo排名公司
  • 为什么没人做同城购物网站上海公司排名