当前位置:网站首页>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 .
边栏推荐
- Debug No5基础光照
- Jenkins continuous integration error stderr: fatal: unsafe repository ('/home/water/water' is owned by someone else)
- Charles' bag grabbing tool test practice
- 【JZOF】10斐波那契数列
- Beifu PLC and C transmit int type variables through ads communication
- 【可视化调度软件】上海道宁为SMB组织带来NETRONIC下载、试用、教程
- Space shooting part 2-2: enemy spirit
- 功能测试转自动化测试,十年自动化测试经验分享
- 转行软件测试有学历要求吗?低于大专是真的没出路吗?
- 【 Visual Dispatching Software】 Shanghai Dow Ning apporte netronic download, Trial, tutoriel pour l'Organisation SMB
猜你喜欢
随机推荐
Notes du jour 7
Notes on the ninth day
UI automation
第十一天笔记
Beifu PLC and C transmit int array type variables through ads communication
Outlook tutorial, how to switch calendar views and create meetings in outlook?
Defi will never die?
What happens when you enter the web address and the web page is displayed
Jenkins continuous integration error stderr: fatal: unsafe repository ('/home/water/water' is owned by someone else)
【 Visual Dispatching Software】 Shanghai Dow Ning apporte netronic download, Trial, tutoriel pour l'Organisation SMB
行业现状令人失望,工作之后我又回到UC伯克利读博了
JVM详细解析
What is the reason for the failure of video playback and RTMP repeated streaming on easygbs platform?
Space shooting part 1: player spirit and control
射击游戏 第 1-2 课:使用精灵
EasyGBS平台出现录像无法播放并存在RTMP重复推流现象,是什么原因?
【JZOF】07 重建二叉树
How to prevent repeated payment of orders?
太空射击 Part 1: 玩家精灵和控制
网易白帽子黑客训练营笔记(2)





![[jzof] 10 Fibonacci series](/img/65/ab5b22b0879644c210abb38b0ce640.png)



