当前位置:网站首页>Debug No5 basic lighting
Debug No5 basic lighting
2022-07-23 13:30:00 【Liu jingyiru】
2022 Year afternoon 15:14
1.bug state : Do not show rendering . An error message indicates that vertex shaders and fragment shaders failed to compile .
analysis :Asset No problem with the data , There may be problems in the component production line , The first step is initModel(), And then there was initShader(). Moreover is rend() The order problem in , Check step by step .


solve : Find a place initShader() It's through cube Shader call . It is found that , Because the name of the packaged component , Conflict with member function of class with the same name , Instead of calling here to compile two cubes shader Component method , Instead, only one compiled cube is called shader Member method of .
Harvest : Avoid conflicting naming when packaging . Member methods are called through class objects , Ordinary functions can be called directly . It can be seen that the foundation is not solid .
2.bug state : Show only one ( Render complete )cube Cube , Instead of displaying the light cube .

analysis : Although the vertex attributes passed in have position and UV. But I think for the light cube, we can omit the texture and UV Information . So the problem here must be , I set to read too much attribute information , And in the rend() The link does not resolve the corresponding variable in the shader . Or attribute information is missing in the shader I read , But resolved some variables that do not exist in the shader . But either way , I didn't even see VS The compiler reported an error , Unless the error about the shader is the error of opening the shader file or the shader and its obvious syntax error .

solve : Deleted redundant variables such as textures in shaders , stay rend() The link has no bound texture .
Harvest : In fact, shader reading data is very flexible , For example, the native data of vertex attributes has texture , Location , Color data , But I You can only receive data that I may use in vertex shaders . For example, the vertex shader of the light cube only receives position information and I don't need to deal with other attribute information when rendering .

void rend()
{
// buffer
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
// Describe the camera
_projMatrix = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f); // Custom projection matrix
_camera.update(); // Update the camera matrix in real time
cube_shader.shader_Begin();
// Resource description
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _texture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, _texture2);
glm::mat4 _modelMatrix(1.0f);
// Resolve shaders Variable , And pass in the data
cube_shader.setMatrix("_modelMatrix", _modelMatrix);
cube_shader.setMatrix("_viewMatrix", _camera.getMatrix());// Input data to the matrix of the corresponding name
cube_shader.setMatrix("_projMatrix", _projMatrix);
cube_shader.setInt("_texture", 0);
cube_shader.setInt("_texture2", 1);
// Bind vertex array , Draw the outline
glBindVertexArray(VAO_cube);
glDrawArrays(GL_TRIANGLES, 0, 36);
cube_shader.shader_End();
sun_shader.shader_Begin();
// Resolve shaders Variable , And pass in the data
sun_shader.setMatrix("_modelMatrix", _modelMatrix);
sun_shader.setMatrix("_viewMatrix", _camera.getMatrix());// Input data to the matrix of the corresponding name
sun_shader.setMatrix("_projMatrix", _projMatrix);
_modelMatrix = glm::translate(_modelMatrix, glm::vec3(3.0f, 0.0f, 0.0f));
sun_shader.setMatrix("_modelMatrix", _modelMatrix);
// Bind vertex array , Draw the outline
glBindVertexArray(VAO_sun);
glDrawArrays(GL_TRIANGLES, 0, 36);
sun_shader.shader_End();
}summary : After grasping the basic framework and detailed framework of knowledge , After summarizing the overall framework , We should practice more . Improve proficiency .
3.bug3 : Rendering effect , The light is blue .( Light intensity setting from 0.5--1.0---1.5) But the contrast between the color and the original picture shows that it is incorrect .

analysis : I guess it's because the color of the light source is read incorrectly , But after checking the process for many times, no data error was found . stay RenderDoc in , Prompt vertex shader compilation problem ... After the output light source , I found that the light source was blue , But after observation, we found that this blue is not a coincidence , It is (1.0f) Blue +(1.0f) Green and blue . And I adjust the red value in Figure 2 , It doesn't work anyway , But blue and green values are available . So connect the two , See light suddenly ! It turned out that the red value passed during initialization topped the red value at the time of assignment , Invalidate the red color in the assignment .
// happen bug Front code
glm::vec3 ligntColor(1.0f);
// This way of writing means only changing 1.0f Red , Other colors are not transmitted .
// This is related to glm::mat3(1.0f) There are differences in the way of writing , The latter means to pass in an identity matrix .


resolvent : When declaring the color and position of the light source , Do not write initialization as glm::vec3 light_color(1.0f); Instead, re assign values below . Or initialize directly to the target value .
But it has not been solved RenderDoc Wrong report in . The tip is API The use is not standardized . The reason has not been proved .

Harvest : Testing is the only criterion for practicing truth , Don't let go of any details . In addition to glm::vec3 The data is C++ data , and uniform It's from CPU Direct transmission GPU The data of , So you need to resolve variables in shaders alone . but uniform Variable data and uniform irrelevant , It will only affect the transmission mode .
4.bug state : Under diffuse reflection cube Lose texture .
analysis : It indicates that there is an error in the texture , There is a problem in reading data of shader in the first step , So I checked the vertex attribute pointer , It is found that the offset is taken incorrectly , The color is normal after modification .
The final summary : I need to improve my ability , Is the ability to generalize errors into technical terms . such as : Not as expected bug There are many states , But there is only one precise generalization . Code capabilities and debug The improvement of ability , It's a process of constantly simplifying requirements . A few days ago bug It is easy to change the process type , But now bug You need to analyze data through data .
边栏推荐
- 【JZOF】09用两个栈实现队列
- MySQL----复合查询 外连接
- The unity model is displayed in front of the UI, and the UI behind it jitters
- -XX:+UseCGroupMemoryLimitForHeap 无法创建虚拟机问题
- com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value:
- 【可視化調度軟件】上海道寧為SMB組織帶來NETRONIC下載、試用、教程
- 太空射击 Part 2-3: 子弹与敌人碰撞处理
- php框架MVC类代码审计
- Opencv video operation
- 射击游戏 第 1-2 课:使用精灵
猜你喜欢

UI自动化

MySQL的索引事务&&JDBC编程

When using fastjson to parse and assign JSON data, the order of JSON fields is inconsistent

High voltage MOS tube knx42150 1500v/3a is applied to frequency converter power supply inverter, etc

射击游戏 第 1-2 课:使用精灵

【JZOF】12矩阵中的路径

Beifu PLC and C transmit bool array variables through ads communication

Summary of time complexity( Ο Is the asymptotic upper bound, Ω is the asymptotic lower bound, P, NP, NP hard, NPC problem)

How to prevent repeated payment of orders?

MySQL index transaction & JDBC programming
随机推荐
Talk about "people" in the R & D team
In depth interpretation of EVM's ecological Empire
Problem solving: script file 'scripts\pip script py‘ is not present.
JVM内存模型简介
C语言插入排序(直接插入排序)
-XX:+UseCGroupMemoryLimitForHeap 无法创建虚拟机问题
【JZOF】12矩阵中的路径
知识图谱:基本概念
[jzof] 07 rebuild binary tree
功能测试转自动化测试,十年自动化测试经验分享
Space shooting part 1: player spirit and control
成功 万象奥科与CODESYS技术联合调测
[actf2020 freshman competition]backupfile 1
Communicate 11 tips for poor performance 
Image processing image feature extraction and description
Machine learning: Li Hang - statistical learning method (II) perceptron + code implementation (primitive + dual form)
给1万帧视频做目标分割,显存占用还不到1.4GB | ECCV2022
Uncaught (in promise) Neo4jError: WebSocket connection failure. Due to security constraints in your
深入解读 EVM 的生态帝国
吴恩达机器学习系列篇p31~p42