什么是最快和最灵活(适用于大多数情况下)使用VBO的方法?
我正在开发一个openGL应用程序,我希望它能达到最佳性能,所以我需要有人来回答这些问题.我读了很多问题和答案,但我想有很多我不需要的信息弄乱了我的大脑......
我正在使用自己的(不是内置的opengl)灯.这是我的片段着色器程序:
#version 330
in vec4 vertexPosition;
in vec3 surfaceNormal;
in vec2 textureCoordinate;
in vec3 eyeVecNormal;
out vec4 outputColor;
uniform sampler2D texture_diffuse;
uniform bool specular;
uniform float shininess;
struct Light {
vec4 position;
vec4 ambientColor;
vec4 diffuseColor;
vec4 specularColor;
};
uniform Light lights[8];
void main()
{
outputColor = texture2D(texture_diffuse, textureCoordinate);
for (int l = 0; l < 8; l++) {
vec3 lightDirection = normalize(lights[l].position.xyz - vertexPosition.xyz);
float diffuseLightIntensity = max(0, dot(surfaceNormal, lightDirection));
outputColor.rgb += lights[l].ambientColor.rgb * lights[l].ambientColor.a;
outputColor.rgb += lights[l].diffuseColor.rgb * …
Run Code Online (Sandbox Code Playgroud) 最近我正在努力适应PSR标准.在PSR-1文件中声明:
文件应该声明符号(类,函数,常量等)或引起副作用(例如生成输出,更改.ini设置等),但不应该同时执行这两种操作.
这是否意味着echo '<b>some bold text</b>';
在类中的函数中写输出(比如说)是我不应该做的?
在我的游戏中,我想为每种情况创建单独的GLSL着色器.在举例来说,如果我将有3款车型character
,shiny sword
并且blury ghost
我想设置renderShader
,animationShader
并lightingShader
到character
,然后renderShader
,lightingShader
和specularShader
到shiny sword
,最后我想设置renderShader
,lightingShader
并blurShader
到blury ghost
.
本renderShader
应通过投影,世界等矩阵相乘顶点的位置,这是fragmet着色器应该简单纹理设置为模型.
animationShader
应该通过给定的骨骼变换来变换顶点.
lightingShader
应该做照明,specularLighting
应该做镜面照明.
blurShader
应该做模糊效果.
首先,我如何在不同的着色器上进行多个顶点变换?因为animationShader
应该计算顶点的动画位置,然后renderShader
应该获得该位置并通过某些矩阵对其进行转换.
其次,如何在不同的着色器上更改片段的颜色?
基本的想法是,我希望能够为每个sutuations /效果使用不同的着色器,我不知道如何实现它.
我需要知道如何在opengl中使用这些着色器,以及我应该如何使用GLSL以便所有着色器相互完成,并且着色器不关心是否使用了另一个着色器.
我正在写一个.smd导入器,我被困在骨骼动画部分.问题是我不确切知道它是如何工作的.我用这本写的出口国,但它并没有说明如何使用存储在文件中的信息.
我想所有具有相同骨骼id的顶点都应该被分组,平移和旋转,因为你无法旋转每个顶点.但我不知道我是否正确,即使我是,我仍然不知道如何通过脚本来做到这一点......
所以问题是:我如何使用存储在文件中的骨架动画信息?
我在不同的源文件中有两个函数:
a.cpp
void A()
{
B();
}
Run Code Online (Sandbox Code Playgroud)
b.cpp
void B()
{
std::cout << "B() called from file: " << ??? << " line: " << ??? << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
如何获取呼叫的文件名和行号?
让我们说我有这个代码:
float[] bigA = {1,2,3,4};
for (int i = 0; i < bigA.length; ++i) {
float abc = bigA[i] - 1;
float[] bigerAbc = {abc};
float[][] wcs = {bigerAbc};
}
Run Code Online (Sandbox Code Playgroud)
该float[][] wcs = {abc};
部分每次都定义了wcs数组,而wcs的最终结果是{{3}},但是我希望wcs被定义为一个空数组,而不是float[][] wcs = {abc};
我想写一些代码来添加bigerAbc到底wcs,最后wcs应该更像是{{0},{1},{2},{3}} ......
问题是:如何将一维数组添加到二维数组的末尾?
我正在尝试学习现代GLSL,但我甚至无法展示我的立方体......
这就是我创建VBO的方式:
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
glBufferData(GL_ARRAY_BUFFER, normalData, GL_STATIC_DRAW);
glNormalPointer(GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, vboTextureHandle);
glBufferData(GL_ARRAY_BUFFER, textureData, GL_STATIC_DRAW);
glTexCoordPointer(2, GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, 0);
Run Code Online (Sandbox Code Playgroud)
这就是我渲染vbo的方式:
glLoadIdentity();
glPushAttrib(GL_TRANSFORM_BIT);
glMatrixMode(GL_MODELVIEW);
glTranslatef(0f, 0f, camera.zoom);
glRotatef(camera.rotation.x, 1, 0, 0);
glRotatef(camera.rotation.y, 0, 1, 0);
glRotatef(camera.rotation.z, 0, 0, 1);
glTranslatef(camera.position.x, camera.position.y, camera.position.z);
glPopAttrib();
texture.bind();
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glVertexPointer(3, GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
glNormalPointer(GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, vboTextureHandle);
glTexCoordPointer(2, GL_FLOAT, 0, 0L);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glMaterialf(GL_FRONT, GL_SHININESS, 10f);
glDrawArrays(GL_TRIANGLES, 0, triangles.size() …
Run Code Online (Sandbox Code Playgroud) 我如何设置 opengl 光泽度浮动,以便我可以在着色器程序中使用它gl_FrontMaterial.shininess
?
我尝试了这个glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100f);
,但亮点并没有变小,所以我猜光泽没有改变。
编辑: 这是我使用的片段着色器程序:
varying vec4 varyingColor;
varying vec3 varyingNormal;
varying vec4 varyingVertex;
varying vec2 varyingTexCoord;
uniform sampler2D my_color_texture;
varying vec3 varyingEyeVec;
void main() {
vec3 vertexPosition = (gl_ModelViewMatrix * varyingVertex).xyz;
vec3 surfaceNormal = normalize((gl_NormalMatrix * varyingNormal).xyz);
vec3 lightDirection = normalize(gl_LightSource[0].position.xyz - vertexPosition);
float diffuseLightIntensity = max(0, dot(surfaceNormal, lightDirection));
gl_FragColor.rgb = diffuseLightIntensity * varyingColor.rgb;
gl_FragColor += gl_LightModel.ambient;
vec3 reflectionDirection = normalize(reflect(lightDirection, surfaceNormal));
vec3 eyeVecNormal = normalize(varyingEyeVec);
float specular = max(0.0, dot(eyeVecNormal, reflectionDirection)); …
Run Code Online (Sandbox Code Playgroud)