LeeMcQueen / GameDemo

Demo
0 stars 0 forks source link

2021/10/28 1.水面的反射相机是固定值 2.主角的光线和相机是固定值 #40

Open LeeMcQueen opened 3 years ago

LeeMcQueen commented 3 years ago
  1. reflectionCamera.setviewDirection(glm::vec3(0.0f, -30.0f, 70.0f));

//把相机的全部属性赋值给新的相机(reflectionCamera) auto reflectionCamera = camera; //计算距离 也就是相机距离水面的高度的反值 float distance = 2.0f * (camera.getPosition().y - waterTile.getHeight()); //利用计算出来的高度 对反射相机的位置参数进行赋值 auto position = reflectionCamera .getPosition() - glm::vec3(0, distance, 0); //把参数的值用set方法给到结构体里面去 reflectionCam.set_position(position);

水面反射的问题还需要详细研究 thinmatrix就是把高度移动到相反位置,然后再把角度也取反 应该和我的相机位置和角度是完全一致的 但是为什么我的水面反射还是错误的 原因有可能是剪切或者是单纯的高度计算错误了 所以导致反射的范围过小

//把参数的值用set方法给到结构体里面去 reflectionCamera.setPosition(position); 上面打上断点 然后看看具体数值 再把GUI调大 容易发现问题

LeeMcQueen commented 3 years ago

2.主角的光线和相机是固定值

1. //骨骼动画shader的uniform参数传输接口 unsigned int modelMatrixLocation = glGetUniformLocation(shader, "model_matrix"); unsigned int boneMatricesLocation = glGetUniformLocation(shader, "bone_transforms"); unsigned int textureLocation = glGetUniformLocation(shader, "diff_texture"); unsigned int emissionLocation = glGetUniformLocation(shader, "emission_texture"); unsigned int normalLocation = glGetUniformLocation(shader, "normal_texture"); unsigned int timeLocation = glGetUniformLocation(shader, "time"); unsigned int cameraPositionLocation = glGetUniformLocation(shader, "cameraPosition"); unsigned int lightPositionLocation = glGetUniformLocation(shader, "lightPosition");

2. glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, glm::value_ptr(camera.getViewMatrix())); glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, glm::value_ptr(masterRenderer.getProjectionMatrix())); glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, glm::value_ptr(skeletonModelMatrix)); glUniformMatrix4fv(boneMatricesLocation, animaModelLoader.getbBoneCount(), GL_FALSE, glm::value_ptr(currentPose[0])); //新追加的通过location把相机和光的位置传给骨骼动画shader的uniform glUniform3f(cameraPositionLocation, camera.getPosition().x, camera.getPosition().y, camera.getPosition().z); glUniform3f(lightPositionLocation, light.getPosition().x, light.getPosition().y, light.getPosition().z); glBindVertexArray(vao);

3. vertexShader uniform vec3 cameraPosition; uniform vec3 lightPosition;

LeeMcQueen commented 3 years ago

水面会变黑的问题 应该是反射和折射的角度造成的 out_Colour = mix(reflectionColor, refractionColor, refractiveFactor); out_Colour = mix(reflectionColor, refractionColor, 0.5);

LeeMcQueen commented 3 years ago

1.水面的反射相机是固定值 参考800兄的方法 他的相机也是使用了glm的lookat方法 1.camera .cpp https://github.com/michaelh800/thinmatrix-game-engine/blob/e0e6173202943433f926c5a3699c007397b67272/src/entities/camera.cpp

2.camera.h https://github.com/michaelh800/thinmatrix-game-engine/blob/e0e6173202943433f926c5a3699c007397b67272/src/entities/camera.hpp

3.waterVertex.glsl https://github.com/michaelh800/thinmatrix-game-engine/blob/e0e6173202943433f926c5a3699c007397b67272/res/shaders/water.v.glsl

4.waterFragment.glsl https://github.com/michaelh800/thinmatrix-game-engine/blob/e0e6173202943433f926c5a3699c007397b67272/res/shaders/water.v.glsl

5.mainLogic https://github.com/michaelh800/thinmatrix-game-engine/blob/e0e6173202943433f926c5a3699c007397b67272/src/engine_tester/game_engine.cpp

*PS 看了他的水面反射和折射效果,感觉好像是有一个综合计算,可以避免角度过低产生黑色的问题