Solo usuarios registrados pueden comentar y agradecer, Logueate o Registrate

Autor Topic: takumi12 - VAO (Vertex Array Object) SHADER MAIN 5.2  (Visto 9510 veces)

0 Miembros and 1 Guest are viewing this topic.

Offline Smudevelop #20 Posteado: March 07, 2025, 11:59:18 AM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 12
  • Gracias recibida: 131
  • np
void BMD::RenderVertexBuffer(int i, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
   GLuint shader_id = gShaderGL->GetShaderId();
   glUseProgram(shader_id);
    glm::mat4 model;
    for (int j = 0; j < m->NumVertices; j++)
   {
        Vertex_t* v = &m->Vertices[j];

        float* vp = VertexTransform[j];
        VectorTransform(v->Position, BoneMatrix[v->Node], vp);
       VectorRotate(v->Position, BoneMatrix[v->Node], vp);
      vp[0] = vp[0] * BoneScale + BoneMatrix[v->Node][0][3];
      vp[1] = vp[1] * BoneScale + BoneMatrix[v->Node][1][3];
      vp[2] = vp[2] * BoneScale + BoneMatrix[v->Node][2][3];
        model = glm::translate(glm::mat4(1.0f), vp);
               
    }

   glm::mat4 view = glm::lookAt(glm::vec3(-CameraPosition[0], -CameraPosition[1], -CameraPosition[2]), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
   glm::mat4 projection = glm::perspective(glm::radians(CameraFOV), (float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

   glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

   // Enviar la matriz de vista
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));

   // Enviar la matriz de modelo
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));


   glBindVertexArray(m->VAO);
   glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);
   glBindVertexArray(0);
   glUseProgram(0);
}

it will look like this

Gracias:


Offline vcore30 #21 Posteado: March 10, 2025, 04:43:46 PM

  • 0 puntos por ventas
  • *
  • Rank: Destacado
  • Posts: 97
  • Gracias recibida: 898
  • ru
@takumi12  Hello. Please tell me what needs to be transferred to the vertex_index parameter ??

Code: [Select]

void BMD::RenderVertexBuffer(int i, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
      .....
}


void BMD::RenderMesh(int i, int RenderFlag, float Alpha, int BlendMesh, float BlendMeshLight, float BlendMeshTexCoordU, float BlendMeshTexCoordV, int MeshTexture)
{
if (i >= NumMeshs || i < 0)
{
return;
}

Mesh_t* m = &Meshs[i];

if (m->NumTriangles == 0)
{
return;
}

RenderVertexBuffer(i, m, ??????????, nullptr, nullptr);

return;
}

Gracias:


Offline afiqui #22 Posteado: March 10, 2025, 08:21:20 PM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 4
  • Gracias recibida: 0
  • br
void BMD::RenderVertexBuffer(int i, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
   GLuint shader_id = gShaderGL->GetShaderId();
   glUseProgram(shader_id);
    glm::mat4 model;
    for (int j = 0; j < m->NumVertices; j++)
   {
        Vertex_t* v = &m->Vertices[j];

        float* vp = VertexTransform[j];
        VectorTransform(v->Position, BoneMatrix[v->Node], vp);
       VectorRotate(v->Position, BoneMatrix[v->Node], vp);
      vp[0] = vp[0] * BoneScale + BoneMatrix[v->Node][0][3];
      vp[1] = vp[1] * BoneScale + BoneMatrix[v->Node][1][3];
      vp[2] = vp[2] * BoneScale + BoneMatrix[v->Node][2][3];
        model = glm::translate(glm::mat4(1.0f), vp);
               
    }

   glm::mat4 view = glm::lookAt(glm::vec3(-CameraPosition[0], -CameraPosition[1], -CameraPosition[2]), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
   glm::mat4 projection = glm::perspective(glm::radians(CameraFOV), (float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

   glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

   // Enviar la matriz de vista
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));

   // Enviar la matriz de modelo
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));


   glBindVertexArray(m->VAO);
   glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);
   glBindVertexArray(0);
   glUseProgram(0);
}

it will look like this
How to implement in the renderMesh and other renders?


Offline Smudevelop #23 Posteado: March 10, 2025, 08:26:30 PM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 12
  • Gracias recibida: 131
  • np
@takumi12  Hello. Please tell me what needs to be transferred to the vertex_index parameter ??

Code: [Select]

void BMD::RenderVertexBuffer(int i, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
      .....
}


void BMD::RenderMesh(int i, int RenderFlag, float Alpha, int BlendMesh, float BlendMeshLight, float BlendMeshTexCoordU, float BlendMeshTexCoordV, int MeshTexture)
{
if (i >= NumMeshs || i < 0)
{
return;
}

Mesh_t* m = &Meshs[i];

if (m->NumTriangles == 0)
{
return;
}

RenderVertexBuffer(i, m, ??????????, nullptr, nullptr);

return;
}

send the states int RenderFlag, float Alpha, int BlendMesh, float BlendMeshLight, float BlendMeshTexCoordU, float BlendMeshTexCoordV, int MeshTexture , to the shader by uniform buffer like "model" "view" "proj"


Offline Smudevelop #24 Posteado: March 10, 2025, 08:33:20 PM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 12
  • Gracias recibida: 131
  • np
it will look like this
shader.vs
#version 330 core

layout(std140, binding = 0) uniform MeshState {
    int RenderFlag;
    float Alpha;
    float BlendMeshTexCoordU;
    float BlendMeshTexCoordV;
    float BlendMeshLight;
};

uniform mat4 uModelView;
uniform mat4 uProjection;

layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec2 aTexCoord;
layout(location = 2) in vec3 aNormal;

out vec2 TexCoord;
out vec3 LightEffect;

void main() {
    gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);

    TexCoord = aTexCoord;
    if (RenderFlag == 1) {  // RENDER_TEXTURE
        TexCoord.x += BlendMeshTexCoordU;
        TexCoord.y += BlendMeshTexCoordV;
    }

    LightEffect = vec3(BlendMeshLight);
}

struct MeshRenderState {
    int RenderFlag;
    float Alpha;
    float BlendMeshTexCoordU;
    float BlendMeshTexCoordV;
    float BlendMeshLight;
};

// make UBO with VAO
GLuint uboMeshState;
glGenBuffers(1, &uboMeshState);
glBindBuffer(GL_UNIFORM_BUFFER, uboMeshState);
glBufferData(GL_UNIFORM_BUFFER, sizeof(MeshRenderState), NULL, GL_DYNAMIC_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, uboMeshState);


void UpdateMeshUBO(int RenderFlag, float Alpha, float BlendMeshTexCoordU, float BlendMeshTexCoordV, float BlendMeshLight) {
    MeshRenderState state = { RenderFlag, Alpha, BlendMeshTexCoordU, BlendMeshTexCoordV, BlendMeshLight };
    glBindBuffer(GL_UNIFORM_BUFFER, uboMeshState);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(MeshRenderState), &state);
    glBindBuffer(GL_UNIFORM_BUFFER, 0);
}

void BMD::RenderMesh(int i, int RenderFlag, float Alpha, float BlendMeshTexCoordU, float BlendMeshTexCoordV, float BlendMeshLight, int MeshTexture)
{
    if (i >= 0 && i < NumMeshs)
    {
        Mesh_t* m = &Meshs;
        if (m->NumTriangles == 0)
            return;

        int Texture = IndexTexture[m->Texture];
        if (MeshTexture != -1)
            Texture = MeshTexture;
        if (Texture == -1)
            return;

        // Update UBO before drawing
        UpdateMeshUBO(RenderFlag, Alpha, BlendMeshTexCoordU, BlendMeshTexCoordV, BlendMeshLight);


        glUseProgram(shaderProgram);

        GLfloat modelView[16];
        glGetFloatv(GL_MODELVIEW_MATRIX, modelView);
        glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "uModelView"), 1, GL_FALSE, modelView);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, Texture);
        glUniform1i(glGetUniformLocation(shaderProgram, "uTexture"), 0);

        glBindVertexArray(VAO);
        glDrawElements(GL_TRIANGLES, m->NumTriangles * 3, GL_UNSIGNED_INT, 0);
        glBindVertexArray(0);

        glUseProgram(0);
    }
}

Gracias:


Offline EuHein #25 Posteado: March 10, 2025, 09:06:47 PM | Modificado: March 10, 2025, 10:07:11 PM by EuHein

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 1
  • Gracias recibida: 1
  • is
void BMD::RenderVertexBuffer(int i, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
   GLuint shader_id = gShaderGL->GetShaderId();
   glUseProgram(shader_id);
    glm::mat4 model;
    for (int j = 0; j < m->NumVertices; j++)
   {
        Vertex_t* v = &m->Vertices[j];

        float* vp = VertexTransform[j];
        VectorTransform(v->Position, BoneMatrix[v->Node], vp);
       VectorRotate(v->Position, BoneMatrix[v->Node], vp);
      vp[0] = vp[0] * BoneScale + BoneMatrix[v->Node][0][3];
      vp[1] = vp[1] * BoneScale + BoneMatrix[v->Node][1][3];
      vp[2] = vp[2] * BoneScale + BoneMatrix[v->Node][2][3];
        model = glm::translate(glm::mat4(1.0f), vp);
               
    }

   glm::mat4 view = glm::lookAt(glm::vec3(-CameraPosition[0], -CameraPosition[1], -CameraPosition[2]), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
   glm::mat4 projection = glm::perspective(glm::radians(CameraFOV), (float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

   glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

   // Enviar la matriz de vista
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));

   // Enviar la matriz de modelo
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));


   glBindVertexArray(m->VAO);
   glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);
   glBindVertexArray(0);
   glUseProgram(0);
}

it will look like this
How to implement in the renderMesh and other renders?


Eu hein ? O_O Rafael Dias pedindo ajuda na TuServerMU ? Eu estou vendo isso mesmo ? Aqui não era a Cracolandia do MU e você não precisava de nada de forum ?
Mundo gira hem..., porque não usa seu nome verdadeiro.... vergonha... retaliação ...

Falta humildade..... EU HEINNNN !



What the hell? O_O Rafael Dias asking for help on TuServerMU? Am I really seeing this? Wasn't this the MU's Crackland and you didn't need any forums?

Fra mundo huh..., why don't you use your real name.... shame... retaliation...

Lack of humility..... WHAT THE HELL!!


Gracias:


Offline mavine #26 Posteado: March 11, 2025, 02:05:15 AM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 11
  • Gracias recibida: 2
  • br
it will look like this
shader.vs
#version 330 core

layout(std140, binding = 0) uniform MeshState {
    int RenderFlag;
    float Alpha;
    float BlendMeshTexCoordU;
    float BlendMeshTexCoordV;
    float BlendMeshLight;
};

uniform mat4 uModelView;
uniform mat4 uProjection;

layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec2 aTexCoord;
layout(location = 2) in vec3 aNormal;

out vec2 TexCoord;
out vec3 LightEffect;

void main() {
    gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);

    TexCoord = aTexCoord;
    if (RenderFlag == 1) {  // RENDER_TEXTURE
        TexCoord.x += BlendMeshTexCoordU;
        TexCoord.y += BlendMeshTexCoordV;
    }

    LightEffect = vec3(BlendMeshLight);
}

struct MeshRenderState {
    int RenderFlag;
    float Alpha;
    float BlendMeshTexCoordU;
    float BlendMeshTexCoordV;
    float BlendMeshLight;
};

// make UBO with VAO
GLuint uboMeshState;
glGenBuffers(1, &uboMeshState);
glBindBuffer(GL_UNIFORM_BUFFER, uboMeshState);
glBufferData(GL_UNIFORM_BUFFER, sizeof(MeshRenderState), NULL, GL_DYNAMIC_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, uboMeshState);


void UpdateMeshUBO(int RenderFlag, float Alpha, float BlendMeshTexCoordU, float BlendMeshTexCoordV, float BlendMeshLight) {
    MeshRenderState state = { RenderFlag, Alpha, BlendMeshTexCoordU, BlendMeshTexCoordV, BlendMeshLight };
    glBindBuffer(GL_UNIFORM_BUFFER, uboMeshState);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(MeshRenderState), &state);
    glBindBuffer(GL_UNIFORM_BUFFER, 0);
}

void BMD::RenderMesh(int i, int RenderFlag, float Alpha, float BlendMeshTexCoordU, float BlendMeshTexCoordV, float BlendMeshLight, int MeshTexture)
{
    if (i >= 0 && i < NumMeshs)
    {
        Mesh_t* m = &Meshs;
        if (m->NumTriangles == 0)
            return;

        int Texture = IndexTexture[m->Texture];
        if (MeshTexture != -1)
            Texture = MeshTexture;
        if (Texture == -1)
            return;

        // Update UBO before drawing
        UpdateMeshUBO(RenderFlag, Alpha, BlendMeshTexCoordU, BlendMeshTexCoordV, BlendMeshLight);


        glUseProgram(shaderProgram);

        GLfloat modelView[16];
        glGetFloatv(GL_MODELVIEW_MATRIX, modelView);
        glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "uModelView"), 1, GL_FALSE, modelView);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, Texture);
        glUniform1i(glGetUniformLocation(shaderProgram, "uTexture"), 0);

        glBindVertexArray(VAO);
        glDrawElements(GL_TRIANGLES, m->NumTriangles * 3, GL_UNSIGNED_INT, 0);
        glBindVertexArray(0);

        glUseProgram(0);
    }
}



Hi... Can you help me? Do I need to change something in (createOpemGlWindow) or in any render?



Offline hardcoremd #27 Posteado: March 14, 2025, 02:44:04 PM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 9
  • Gracias recibida: 7
  • md
it will look like this
shader.vs
#version 330 core

layout(std140, binding = 0) uniform MeshState {
    int RenderFlag;
    float Alpha;
    float BlendMeshTexCoordU;
    float BlendMeshTexCoordV;
    float BlendMeshLight;
};

uniform mat4 uModelView;
uniform mat4 uProjection;

layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec2 aTexCoord;
layout(location = 2) in vec3 aNormal;

out vec2 TexCoord;
out vec3 LightEffect;

void main() {
    gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);

    TexCoord = aTexCoord;
    if (RenderFlag == 1) {  // RENDER_TEXTURE
        TexCoord.x += BlendMeshTexCoordU;
        TexCoord.y += BlendMeshTexCoordV;
    }

    LightEffect = vec3(BlendMeshLight);
}

struct MeshRenderState {
    int RenderFlag;
    float Alpha;
    float BlendMeshTexCoordU;
    float BlendMeshTexCoordV;
    float BlendMeshLight;
};

// make UBO with VAO
GLuint uboMeshState;
glGenBuffers(1, &uboMeshState);
glBindBuffer(GL_UNIFORM_BUFFER, uboMeshState);
glBufferData(GL_UNIFORM_BUFFER, sizeof(MeshRenderState), NULL, GL_DYNAMIC_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, uboMeshState);


void UpdateMeshUBO(int RenderFlag, float Alpha, float BlendMeshTexCoordU, float BlendMeshTexCoordV, float BlendMeshLight) {
    MeshRenderState state = { RenderFlag, Alpha, BlendMeshTexCoordU, BlendMeshTexCoordV, BlendMeshLight };
    glBindBuffer(GL_UNIFORM_BUFFER, uboMeshState);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(MeshRenderState), &state);
    glBindBuffer(GL_UNIFORM_BUFFER, 0);
}

void BMD::RenderMesh(int i, int RenderFlag, float Alpha, float BlendMeshTexCoordU, float BlendMeshTexCoordV, float BlendMeshLight, int MeshTexture)
{
    if (i >= 0 && i < NumMeshs)
    {
        Mesh_t* m = &Meshs;
        if (m->NumTriangles == 0)
            return;

        int Texture = IndexTexture[m->Texture];
        if (MeshTexture != -1)
            Texture = MeshTexture;
        if (Texture == -1)
            return;

        // Update UBO before drawing
        UpdateMeshUBO(RenderFlag, Alpha, BlendMeshTexCoordU, BlendMeshTexCoordV, BlendMeshLight);


        glUseProgram(shaderProgram);

        GLfloat modelView[16];
        glGetFloatv(GL_MODELVIEW_MATRIX, modelView);
        glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "uModelView"), 1, GL_FALSE, modelView);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, Texture);
        glUniform1i(glGetUniformLocation(shaderProgram, "uTexture"), 0);

        glBindVertexArray(VAO);
        glDrawElements(GL_TRIANGLES, m->NumTriangles * 3, GL_UNSIGNED_INT, 0);
        glBindVertexArray(0);

        glUseProgram(0);
    }
}



Hi... Can you help me? Do I need to change something in (createOpemGlWindow) or in any render?
Same problem


Offline z0lik #28 Posteado: March 28, 2025, 11:37:35 AM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 6
  • Gracias recibida: 3
  • it
You're missing the important part that was already mentioned earlier:

"The problem remains how to load the shader and correctly position the transformation values ​​for the camera, view, and model." – takumi12 angryy2

If your model doesn’t appear, it's not the shader itself — it's likely that your camera/view/projection setup is wrong, and the object is rendered outside the visible space.

Code: [Select]
void BMD::RenderVertexBuffer(int textureIndex, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
const auto texture = Bitmaps.GetTexture(textureIndex);
if (!texture) return;

GLuint textureID = texture->TextureNumber;
if (!glIsTexture(textureID)) return;

glm::mat4 model = glm::mat4(1.0f);

float distanceBehind = -1.0f;
float heightAbove = 0.9f;
float yaw = -0.8;// glm::radians(CameraAngle[0])* glm::radians(CameraFOV);

glm::vec3 characterPosition = glm::vec3(CameraPosition[0], CameraPosition[1], CameraPosition[2]);

glm::vec3 behindOffset = glm::vec3(
cosf(yaw) * -distanceBehind,
sinf(yaw) * -distanceBehind,
0.0f
);

glm::vec3 cameraPosition = characterPosition + behindOffset;
cameraPosition.z += heightAbove;

glm::mat4 view = glm::lookAt(
cameraPosition,
characterPosition,
glm::vec3(0.0f, 0.0f, 1.0f)
);

glm::mat4 projection = glm::perspective(glm::radians(CameraFOV),
(float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

GLuint shader_id = gShaderGL->GetShaderId();
glUseProgram(shader_id);

// Matrici al vertex shader
glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

// Texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
glUniform1i(glGetUniformLocation(shader_id, "texture1"), 0);

glBindVertexArray(m->VAO);

// Vertex
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_Vertices);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec3_t), vertices);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(0);

// Texture Coord
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_TexCoords);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec2_t), textCoords);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);

// Draw call
glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);

glBindVertexArray(0);
glUseProgram(0);
}

Use this hardcoded snippet to test and adjust until your object becomes visible.


Discord: z0lik

Gracias:


Offline Smudevelop #29 Posteado: March 28, 2025, 10:48:06 PM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 12
  • Gracias recibida: 131
  • np
You're missing the important part that was already mentioned earlier:

"The problem remains how to load the shader and correctly position the transformation values ​​for the camera, view, and model." – takumi12 angryy2

If your model doesn’t appear, it's not the shader itself — it's likely that your camera/view/projection setup is wrong, and the object is rendered outside the visible space.

Code: [Select]
void BMD::RenderVertexBuffer(int textureIndex, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
const auto texture = Bitmaps.GetTexture(textureIndex);
if (!texture) return;

GLuint textureID = texture->TextureNumber;
if (!glIsTexture(textureID)) return;

glm::mat4 model = glm::mat4(1.0f);

float distanceBehind = -1.0f;
float heightAbove = 0.9f;
float yaw = -0.8;// glm::radians(CameraAngle[0])* glm::radians(CameraFOV);

glm::vec3 characterPosition = glm::vec3(CameraPosition[0], CameraPosition[1], CameraPosition[2]);

glm::vec3 behindOffset = glm::vec3(
cosf(yaw) * -distanceBehind,
sinf(yaw) * -distanceBehind,
0.0f
);

glm::vec3 cameraPosition = characterPosition + behindOffset;
cameraPosition.z += heightAbove;

glm::mat4 view = glm::lookAt(
cameraPosition,
characterPosition,
glm::vec3(0.0f, 0.0f, 1.0f)
);

glm::mat4 projection = glm::perspective(glm::radians(CameraFOV),
(float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

GLuint shader_id = gShaderGL->GetShaderId();
glUseProgram(shader_id);

// Matrici al vertex shader
glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

// Texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
glUniform1i(glGetUniformLocation(shader_id, "texture1"), 0);

glBindVertexArray(m->VAO);

// Vertex
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_Vertices);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec3_t), vertices);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(0);

// Texture Coord
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_TexCoords);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec2_t), textCoords);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);

// Draw call
glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);

glBindVertexArray(0);
glUseProgram(0);
}

Use this hardcoded snippet to test and adjust until your object becomes visible.



exactly like that , the transfom from camera pos is taken from the character's position and it is always returned to BodyOrigin

Gracias:


Offline mavine #30 Posteado: March 28, 2025, 11:25:21 PM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 11
  • Gracias recibida: 2
  • br
You're missing the important part that was already mentioned earlier:

"The problem remains how to load the shader and correctly position the transformation values ​​for the camera, view, and model." – takumi12 angryy2

If your model doesn’t appear, it's not the shader itself — it's likely that your camera/view/projection setup is wrong, and the object is rendered outside the visible space.

Code: [Select]
void BMD::RenderVertexBuffer(int textureIndex, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
const auto texture = Bitmaps.GetTexture(textureIndex);
if (!texture) return;

GLuint textureID = texture->TextureNumber;
if (!glIsTexture(textureID)) return;

glm::mat4 model = glm::mat4(1.0f);

float distanceBehind = -1.0f;
float heightAbove = 0.9f;
float yaw = -0.8;// glm::radians(CameraAngle[0])* glm::radians(CameraFOV);

glm::vec3 characterPosition = glm::vec3(CameraPosition[0], CameraPosition[1], CameraPosition[2]);

glm::vec3 behindOffset = glm::vec3(
cosf(yaw) * -distanceBehind,
sinf(yaw) * -distanceBehind,
0.0f
);

glm::vec3 cameraPosition = characterPosition + behindOffset;
cameraPosition.z += heightAbove;

glm::mat4 view = glm::lookAt(
cameraPosition,
characterPosition,
glm::vec3(0.0f, 0.0f, 1.0f)
);

glm::mat4 projection = glm::perspective(glm::radians(CameraFOV),
(float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

GLuint shader_id = gShaderGL->GetShaderId();
glUseProgram(shader_id);

// Matrici al vertex shader
glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

// Texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
glUniform1i(glGetUniformLocation(shader_id, "texture1"), 0);

glBindVertexArray(m->VAO);

// Vertex
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_Vertices);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec3_t), vertices);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(0);

// Texture Coord
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_TexCoords);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec2_t), textCoords);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);

// Draw call
glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);

glBindVertexArray(0);
glUseProgram(0);
}

Use this hardcoded snippet to test and adjust until your object becomes visible.



exactly like that , the transfom from camera pos is taken from the character's position and it is always returned to BodyOrigin

Samuel 
Where do I call this function?   void BMD::RenderVertexBuffer(int textureIndex, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)


Offline z0lik #31 Posteado: March 29, 2025, 02:56:08 AM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 6
  • Gracias recibida: 3
  • it
You're missing the important part that was already mentioned earlier:

"The problem remains how to load the shader and correctly position the transformation values ​​for the camera, view, and model." – takumi12 angryy2

If your model doesn’t appear, it's not the shader itself — it's likely that your camera/view/projection setup is wrong, and the object is rendered outside the visible space.

Code: [Select]
void BMD::RenderVertexBuffer(int textureIndex, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
const auto texture = Bitmaps.GetTexture(textureIndex);
if (!texture) return;

GLuint textureID = texture->TextureNumber;
if (!glIsTexture(textureID)) return;

glm::mat4 model = glm::mat4(1.0f);

float distanceBehind = -1.0f;
float heightAbove = 0.9f;
float yaw = -0.8;// glm::radians(CameraAngle[0])* glm::radians(CameraFOV);

glm::vec3 characterPosition = glm::vec3(CameraPosition[0], CameraPosition[1], CameraPosition[2]);

glm::vec3 behindOffset = glm::vec3(
cosf(yaw) * -distanceBehind,
sinf(yaw) * -distanceBehind,
0.0f
);

glm::vec3 cameraPosition = characterPosition + behindOffset;
cameraPosition.z += heightAbove;

glm::mat4 view = glm::lookAt(
cameraPosition,
characterPosition,
glm::vec3(0.0f, 0.0f, 1.0f)
);

glm::mat4 projection = glm::perspective(glm::radians(CameraFOV),
(float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

GLuint shader_id = gShaderGL->GetShaderId();
glUseProgram(shader_id);

// Matrici al vertex shader
glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

// Texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
glUniform1i(glGetUniformLocation(shader_id, "texture1"), 0);

glBindVertexArray(m->VAO);

// Vertex
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_Vertices);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec3_t), vertices);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(0);

// Texture Coord
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_TexCoords);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec2_t), textCoords);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);

// Draw call
glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);

glBindVertexArray(0);
glUseProgram(0);
}

Use this hardcoded snippet to test and adjust until your object becomes visible.



exactly like that , the transfom from camera pos is taken from the character's position and it is always returned to BodyOrigin

Samuel 
Where do I call this function?   void BMD::RenderVertexBuffer(int textureIndex, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)

zzzBMD.cpp
Code: [Select]
void BMD::RenderMesh(int meshIndex, int renderFlags, float alpha, int blendMeshIndex, float blendMeshAlpha, float blendMeshTextureCoordU, float blendMeshTextureCoordV, int explicitTextureIndex)

sven-n/MuMain part of code
Code: [Select]
void BMD::RenderMesh(int meshIndex, int renderFlags, float alpha, int blendMeshIndex, float blendMeshAlpha, float blendMeshTextureCoordU, float blendMeshTextureCoordV, int explicitTextureIndex)
{
    if (meshIndex >= NumMeshs || meshIndex < 0) return;

    Mesh_t* m = &Meshs[meshIndex];
    if (m->NumTriangles == 0) return;

    float wave = static_cast<long>(WorldTime) % 10000 * 0.0001f;

    int textureIndex = IndexTexture[m->Texture];
    if (textureIndex == BITMAP_HIDE)
    {
        return;
    }

    if (textureIndex == BITMAP_WATER)
    {
        textureIndex = BITMAP_WATER + WaterTextureNumber;
    }

    if (explicitTextureIndex != -1)
    {
        textureIndex = explicitTextureIndex;
    }

    const auto texture = Bitmaps.GetTexture(textureIndex);
    if (texture->IsSkin && HideSkin)
    {
        return;
    }

    if (texture->IsHair && HideSkin)
    {
        return;
    }

    bool EnableWave = false;
    int streamMesh = static_cast<u_char>(this->StreamMesh);
    if (m->m_csTScript != nullptr)
    {
        if (m->m_csTScript->getStreamMesh())
        {
            streamMesh = meshIndex;
        }
    }

    if ((meshIndex == blendMeshIndex || meshIndex == streamMesh)
        && (blendMeshTextureCoordU != 0.f || blendMeshTextureCoordV != 0.f))
    {
        EnableWave = true;
    }

    bool enableLight = LightEnable;
    if (meshIndex == StreamMesh)
    {
        glColor3fv(BodyLight);
        enableLight = false;
    }
    else if (enableLight)
    {
        for (int j = 0; j < m->NumNormals; j++)
        {
            VectorScale(BodyLight, IntensityTransform[meshIndex][j], LightTransform[meshIndex][j]);
        }
    }

    int finalRenderFlags = renderFlags;
    if ((renderFlags & RENDER_COLOR) == RENDER_COLOR)
    {
        finalRenderFlags = RENDER_COLOR;
        if ((renderFlags & RENDER_BRIGHT) == RENDER_BRIGHT)
        {
            EnableAlphaBlend();
        }
        else if ((renderFlags & RENDER_DARK) == RENDER_DARK)
        {
            EnableAlphaBlendMinus();
        }
        else
        {
            DisableAlphaBlend();
        }

        if ((renderFlags & RENDER_NODEPTH) == RENDER_NODEPTH)
        {
            DisableDepthTest();
        }

        DisableTexture();
        if (alpha >= 0.99f)
        {
            glColor3fv(BodyLight);
        }
        else
        {
            EnableAlphaTest();
            glColor4f(BodyLight[0], BodyLight[1], BodyLight[2], alpha);
        }
    }
    else if ((renderFlags & RENDER_CHROME) == RENDER_CHROME ||
        (renderFlags & RENDER_CHROME2) == RENDER_CHROME2 ||
        (renderFlags & RENDER_CHROME3) == RENDER_CHROME3 ||
        (renderFlags & RENDER_CHROME4) == RENDER_CHROME4 ||
        (renderFlags & RENDER_CHROME5) == RENDER_CHROME5 ||
        (renderFlags & RENDER_CHROME6) == RENDER_CHROME6 ||
        (renderFlags & RENDER_CHROME7) == RENDER_CHROME7 ||
        (renderFlags & RENDER_METAL) == RENDER_METAL ||
        (renderFlags & RENDER_OIL) == RENDER_OIL
        )
    {
        if (m->m_csTScript != nullptr)
        {
            if (m->m_csTScript->getNoneBlendMesh()) return;
        }

        if (m->NoneBlendMesh)
            return;

        finalRenderFlags = RENDER_CHROME;
        if ((renderFlags & RENDER_CHROME4) == RENDER_CHROME4)
        {
            finalRenderFlags = RENDER_CHROME4;
        }
        if ((renderFlags & RENDER_OIL) == RENDER_OIL)
        {
            finalRenderFlags = RENDER_OIL;
        }

        float Wave2 = (int)WorldTime % 5000 * 0.00024f - 0.4f;

        vec3_t L = { (float)(cos(WorldTime * 0.001f)), (float)(sin(WorldTime * 0.002f)), 1.f };
        for (int j = 0; j < m->NumNormals; j++)
        {
            if (j > MAX_VERTICES) break;
            const auto normal = NormalTransform[meshIndex][j];

            if ((renderFlags & RENDER_CHROME2) == RENDER_CHROME2)
            {
                g_chrome[j][0] = (normal[2] + normal[0]) * 0.8f + Wave2 * 2.f;
                g_chrome[j][1] = (normal[1] + normal[0]) * 1.0f + Wave2 * 3.f;
            }
            else if ((renderFlags & RENDER_CHROME3) == RENDER_CHROME3)
            {
                g_chrome[j][0] = DotProduct(normal, LightVector);
                g_chrome[j][1] = 1.f - DotProduct(normal, LightVector);
            }
            else if ((renderFlags & RENDER_CHROME4) == RENDER_CHROME4)
            {
                g_chrome[j][0] = DotProduct(normal, L);
                g_chrome[j][1] = 1.f - DotProduct(normal, L);
                g_chrome[j][1] -= normal[2] * 0.5f + wave * 3.f;
                g_chrome[j][0] += normal[1] * 0.5f + L[1] * 3.f;
            }
            else if ((renderFlags & RENDER_CHROME5) == RENDER_CHROME5)
            {
                g_chrome[j][0] = DotProduct(normal, L);
                g_chrome[j][1] = 1.f - DotProduct(normal, L);
                g_chrome[j][1] -= normal[2] * 2.5f + wave * 1.f;
                g_chrome[j][0] += normal[1] * 3.f + L[1] * 5.f;
            }
            else if ((renderFlags & RENDER_CHROME6) == RENDER_CHROME6)
            {
                g_chrome[j][0] = (normal[2] + normal[0]) * 0.8f + Wave2 * 2.f;
                g_chrome[j][1] = (normal[2] + normal[0]) * 0.8f + Wave2 * 2.f;
            }
            else if ((renderFlags & RENDER_CHROME7) == RENDER_CHROME7)
            {
                g_chrome[j][0] = (normal[2] + normal[0]) * 0.8f + static_cast<float>(WorldTime) * 0.00006f;
                g_chrome[j][1] = (normal[2] + normal[0]) * 0.8f + static_cast<float>(WorldTime) * 0.00006f;
            }
            else if ((renderFlags & RENDER_OIL) == RENDER_OIL)
            {
                g_chrome[j][0] = normal[0];
                g_chrome[j][1] = normal[1];
            }
            else if ((renderFlags & RENDER_CHROME) == RENDER_CHROME)
            {
                g_chrome[j][0] = normal[2] * 0.5f + wave;
                g_chrome[j][1] = normal[1] * 0.5f + wave * 2.f;
            }
            else
            {
                g_chrome[j][0] = normal[2] * 0.5f + 0.2f;
                g_chrome[j][1] = normal[1] * 0.5f + 0.5f;
            }
        }

        if ((renderFlags & RENDER_CHROME3) == RENDER_CHROME3
            || (renderFlags & RENDER_CHROME4) == RENDER_CHROME4
            || (renderFlags & RENDER_CHROME5) == RENDER_CHROME5
            || (renderFlags & RENDER_CHROME7) == RENDER_CHROME7
            || (renderFlags & RENDER_BRIGHT) == RENDER_BRIGHT
            )
        {
            if (alpha < 0.99f)
            {
                BodyLight[0] *= alpha;
                BodyLight[1] *= alpha;
                BodyLight[2] *= alpha;
            }

            EnableAlphaBlend();
        }
        else if ((renderFlags & RENDER_DARK) == RENDER_DARK)
            EnableAlphaBlendMinus();
        else if ((renderFlags & RENDER_LIGHTMAP) == RENDER_LIGHTMAP)
            EnableLightMap();
        else if (alpha >= 0.99f)
        {
            DisableAlphaBlend();
        }
        else
        {
            EnableAlphaTest();
        }

        if ((renderFlags & RENDER_NODEPTH) == RENDER_NODEPTH)
        {
            DisableDepthTest();
        }

        if (explicitTextureIndex == -1)
        {
            if ((renderFlags & RENDER_CHROME2) == RENDER_CHROME2)
            {
                BindTexture(BITMAP_CHROME2);
            }
            else if ((renderFlags & RENDER_CHROME3) == RENDER_CHROME3)
            {
                BindTexture(BITMAP_CHROME2);
            }
            else if ((renderFlags & RENDER_CHROME4) == RENDER_CHROME4)
            {
                BindTexture(BITMAP_CHROME2);
            }
            else if ((renderFlags & RENDER_CHROME6) == RENDER_CHROME6)
            {
                BindTexture(BITMAP_CHROME6);
            }
            else if ((renderFlags & RENDER_CHROME) == RENDER_CHROME)
            {
                BindTexture(BITMAP_CHROME);
            }
            else if ((renderFlags & RENDER_METAL) == RENDER_METAL)
            {
                BindTexture(BITMAP_SHINY);
            }
        }
        else
        {
            BindTexture(textureIndex);
        }
    }
    else if (blendMeshIndex <= -2 || m->Texture == blendMeshIndex)
    {
        finalRenderFlags = RENDER_TEXTURE;
        BindTexture(textureIndex);
        if ((renderFlags & RENDER_DARK) == RENDER_DARK)
            EnableAlphaBlendMinus();
        else
            EnableAlphaBlend();

        if ((renderFlags & RENDER_NODEPTH) == RENDER_NODEPTH)
        {
            DisableDepthTest();
        }

        glColor3f(BodyLight[0] * blendMeshAlpha,
            BodyLight[1] * blendMeshAlpha,
            BodyLight[2] * blendMeshAlpha);
        //glColor3f(BlendMeshLight,BlendMeshLight,BlendMeshLight);
        enableLight = false;
    }
    else if ((renderFlags & RENDER_TEXTURE) == RENDER_TEXTURE)
    {
        finalRenderFlags = RENDER_TEXTURE;
        BindTexture(textureIndex);
        if ((renderFlags & RENDER_BRIGHT) == RENDER_BRIGHT)
        {
            EnableAlphaBlend();
        }
        else if ((renderFlags & RENDER_DARK) == RENDER_DARK)
        {
            EnableAlphaBlendMinus();
        }
        else if (alpha < 0.99f || texture->Components == 4)
        {
            EnableAlphaTest();
        }
        else
        {
            DisableAlphaBlend();
        }

        if ((renderFlags & RENDER_NODEPTH) == RENDER_NODEPTH)
        {
            DisableDepthTest();
        }
    }
    else if ((renderFlags & RENDER_BRIGHT) == RENDER_BRIGHT)
    {
        if (texture->Components == 4 || m->Texture == blendMeshIndex)
        {
            return;
        }

        finalRenderFlags = RENDER_BRIGHT;
        EnableAlphaBlend();
        DisableTexture();
        DisableDepthMask();

        if ((renderFlags & RENDER_NODEPTH) == RENDER_NODEPTH)
        {
            DisableDepthTest();
        }
    }
    else
    {
        finalRenderFlags = RENDER_TEXTURE;
    }
    if (renderFlags & RENDER_DOPPELGANGER)
    {
        if (texture->Components != 4)
        {
            EnableCullFace();
            EnableDepthMask();
        }
    }

    bool enableColor = (enableLight && finalRenderFlags == RENDER_TEXTURE)
        || finalRenderFlags == RENDER_CHROME
        || finalRenderFlags == RENDER_CHROME4
        || finalRenderFlags == RENDER_OIL;

    glEnableClientState(GL_VERTEX_ARRAY);
    if (enableColor) glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    auto vertices = RenderArrayVertices;
    auto colors = RenderArrayColors;
    auto texCoords = RenderArrayTexCoords;

    int target_vertex_index = -1;
    for (int j = 0; j < m->NumTriangles; j++)
    {
        const auto triangle = &m->Triangles[j];
        for (int k = 0; k < triangle->Polygon; k++)
        {
            const int source_vertex_index = triangle->VertexIndex[k];
            target_vertex_index++;

            VectorCopy(VertexTransform[meshIndex][source_vertex_index], vertices[target_vertex_index]);

            Vector4(BodyLight[0], BodyLight[1], BodyLight[2], alpha, colors[target_vertex_index]);

            auto texco = m->TexCoords[triangle->TexCoordIndex[k]];
            texCoords[target_vertex_index][0] = texco.TexCoordU;
            texCoords[target_vertex_index][1] = texco.TexCoordV;

            int normalIndex = triangle->NormalIndex[k];
            switch (finalRenderFlags)
            {
                case RENDER_TEXTURE:
                {
                    if (EnableWave)
                    {
                        texCoords[target_vertex_index][0] += blendMeshTextureCoordU;
                        texCoords[target_vertex_index][1] += blendMeshTextureCoordV;
                    }

                    if (enableLight)
                    {
                        auto light = LightTransform[meshIndex][normalIndex];
                        Vector4(light[0], light[1], light[2], alpha, colors[target_vertex_index]);
                    }

                    break;
                }
                case RENDER_CHROME:
                {
                    texCoords[target_vertex_index][0] = g_chrome[normalIndex][0];
                    texCoords[target_vertex_index][1] = g_chrome[normalIndex][1];
                    break;
                }
                case RENDER_CHROME4:
                {
                    texCoords[target_vertex_index][0] = g_chrome[normalIndex][0] + blendMeshTextureCoordU;
                    texCoords[target_vertex_index][1] = g_chrome[normalIndex][1] + blendMeshTextureCoordV;
                    break;
                }
                case RENDER_OIL:
                {
                    texCoords[target_vertex_index][0] = g_chrome[normalIndex][0] * texCoords[target_vertex_index][0] + blendMeshTextureCoordU;
                    texCoords[target_vertex_index][1] = g_chrome[normalIndex][1] * texCoords[target_vertex_index][1] + blendMeshTextureCoordV;
                    break;
                }
            }

            if ((renderFlags & RENDER_SHADOWMAP) == RENDER_SHADOWMAP)
            {
                vec3_t pos;
                VectorSubtract(vertices[target_vertex_index], BodyOrigin, pos);

                pos[0] += pos[2] * (pos[0] + 2000.f) / (pos[2] - 4000.f);
                pos[2] = 5.f;

                VectorAdd(pos, BodyOrigin, pos);
            }
            else if ((renderFlags & RENDER_WAVE) == RENDER_WAVE)
            {
                float time_sin = sinf((float)((int)WorldTime + source_vertex_index * 931) * 0.007f) * 28.0f;
                float* normal = NormalTransform[meshIndex][normalIndex];
                for (int iCoord = 0; iCoord < 3; ++iCoord)
                {
                    vertices[target_vertex_index][iCoord] += normal[iCoord] * time_sin;
                }
            }
        }
    }

    glVertexPointer(3, GL_FLOAT, 0, vertices);
    if (enableColor) glColorPointer(4, GL_FLOAT, 0, colors);
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);

    glDrawArrays(GL_TRIANGLES, 0, m->NumTriangles * 3);

    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    if (enableColor) glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
}
Code: [Select]
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    if (enableColor) glColorPointer(4, GL_FLOAT, 0, colors);
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);

    glDrawArrays(GL_TRIANGLES, 0, m->NumTriangles * 3);

    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    if (enableColor) glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);

delete or replace this part with

Code: [Select]
BMD::RenderVertexBuffer(textureIndex, m, target_vertex_index, vertices, texCoords);

Discord: z0lik

Offline hoanmaster #32 Posteado: July 21, 2025, 03:07:15 AM | Modificado: July 21, 2025, 03:19:39 AM by hoanmaster

  • 0 puntos por ventas
  • *
  • Rank: Dedicado
  • Posts: 31
  • Gracias recibida: 29
  • vn
void BMD::RenderVertexBuffer(int i, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
   GLuint shader_id = gShaderGL->GetShaderId();
   glUseProgram(shader_id);
    glm::mat4 model;
    for (int j = 0; j < m->NumVertices; j++)
   {
        Vertex_t* v = &m->Vertices[j];

        float* vp = VertexTransform[j];
        VectorTransform(v->Position, BoneMatrix[v->Node], vp);
       VectorRotate(v->Position, BoneMatrix[v->Node], vp);
      vp[0] = vp[0] * BoneScale + BoneMatrix[v->Node][0][3];
      vp[1] = vp[1] * BoneScale + BoneMatrix[v->Node][1][3];
      vp[2] = vp[2] * BoneScale + BoneMatrix[v->Node][2][3];
        model = glm::translate(glm::mat4(1.0f), vp);
               
    }

   glm::mat4 view = glm::lookAt(glm::vec3(-CameraPosition[0], -CameraPosition[1], -CameraPosition[2]), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
   glm::mat4 projection = glm::perspective(glm::radians(CameraFOV), (float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

   glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

   // Enviar la matriz de vista
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));

   // Enviar la matriz de modelo
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));


   glBindVertexArray(m->VAO);
   glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);
   glBindVertexArray(0);
   glUseProgram(0);
}

it will look like this


So good


Offline z0lik #33 Posteado: July 22, 2025, 03:17:26 AM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 6
  • Gracias recibida: 3
  • it
void BMD::RenderVertexBuffer(int i, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
   GLuint shader_id = gShaderGL->GetShaderId();
   glUseProgram(shader_id);
    glm::mat4 model;
    for (int j = 0; j < m->NumVertices; j++)
   {
        Vertex_t* v = &m->Vertices[j];

        float* vp = VertexTransform[j];
        VectorTransform(v->Position, BoneMatrix[v->Node], vp);
       VectorRotate(v->Position, BoneMatrix[v->Node], vp);
      vp[0] = vp[0] * BoneScale + BoneMatrix[v->Node][0][3];
      vp[1] = vp[1] * BoneScale + BoneMatrix[v->Node][1][3];
      vp[2] = vp[2] * BoneScale + BoneMatrix[v->Node][2][3];
        model = glm::translate(glm::mat4(1.0f), vp);
               
    }

   glm::mat4 view = glm::lookAt(glm::vec3(-CameraPosition[0], -CameraPosition[1], -CameraPosition[2]), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
   glm::mat4 projection = glm::perspective(glm::radians(CameraFOV), (float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

   glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

   // Enviar la matriz de vista
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));

   // Enviar la matriz de modelo
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));


   glBindVertexArray(m->VAO);
   glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);
   glBindVertexArray(0);
   glUseProgram(0);
}

it will look like this


So good


Do you share to help advance the development of this technology, or just to show off?

Discord: z0lik

Offline hoanmaster #34 Posteado: July 22, 2025, 03:37:18 AM

  • 0 puntos por ventas
  • *
  • Rank: Dedicado
  • Posts: 31
  • Gracias recibida: 29
  • vn
void BMD::RenderVertexBuffer(int i, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
   GLuint shader_id = gShaderGL->GetShaderId();
   glUseProgram(shader_id);
    glm::mat4 model;
    for (int j = 0; j < m->NumVertices; j++)
   {
        Vertex_t* v = &m->Vertices[j];

        float* vp = VertexTransform[j];
        VectorTransform(v->Position, BoneMatrix[v->Node], vp);
       VectorRotate(v->Position, BoneMatrix[v->Node], vp);
      vp[0] = vp[0] * BoneScale + BoneMatrix[v->Node][0][3];
      vp[1] = vp[1] * BoneScale + BoneMatrix[v->Node][1][3];
      vp[2] = vp[2] * BoneScale + BoneMatrix[v->Node][2][3];
        model = glm::translate(glm::mat4(1.0f), vp);
               
    }

   glm::mat4 view = glm::lookAt(glm::vec3(-CameraPosition[0], -CameraPosition[1], -CameraPosition[2]), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
   glm::mat4 projection = glm::perspective(glm::radians(CameraFOV), (float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);

   glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

   // Enviar la matriz de vista
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));

   // Enviar la matriz de modelo
   glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));


   glBindVertexArray(m->VAO);
   glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);
   glBindVertexArray(0);
   glUseProgram(0);
}

it will look like this



Do you share to help advance the development of this technology, or just to show off?
I thank my friend because looking at his code helped me do it (although it didn't work for me much), the code you shared itself can't render like the image you posted.


Offline xufqing #35 Posteado: July 27, 2025, 01:01:50 AM

  • 0 puntos por ventas
  • *
  • Rank: Dedicado
  • Posts: 32
  • Gracias recibida: 70
  • cn
After a period of research, I successfully passed the vertex data from OpenGL to the GPU. However, there is still some data in the main function that cannot be uploaded. My idea is to partially render on the CPU and partially on the GPU—for example, using TLS to determine whether the current frame should be processed by the CPU or GPU. Can someone give me some guidance?


Offline pnicacio #36 Posteado: August 03, 2025, 08:27:41 PM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 7
  • Gracias recibida: 0
  • br
After a period of research, I successfully passed the vertex data from OpenGL to the GPU. However, there is still some data in the main function that cannot be uploaded. My idea is to partially render on the CPU and partially on the GPU—for example, using TLS to determine whether the current frame should be processed by the CPU or GPU. Can someone give me some guidance?

Realmente pensei no Mesmo, até conseguir replicar o que foi Repassado pelo Takumi e por z0lik, consegui fazer os Ajustes da camera, mais eu não tive um grande desempenho consideravel em CPU's mais antigas.

Até comecei a Conversão total do Cliente usando o Glew32 para usar o OpenGL moderno nas Chamadas Gerais do Cliente.

Percebi que mesmo implementando, seria Nescessário Mudar completamente todas as Chamadas do RenderMesh, RenderBody, RenderBodyShadow.

Para funcionar é Nescessário Iniciar o CPP novo citado pelo Takumi, recriar os Arquivos .vs e .fs, Chamar na Função Open2 e em Seguida, alterar o Final do RenderMesh.


Offline xufqing #37 Posteado: August 03, 2025, 10:32:58 PM

  • 0 puntos por ventas
  • *
  • Rank: Dedicado
  • Posts: 32
  • Gracias recibida: 70
  • cn
After a period of research, I successfully passed the vertex data from OpenGL to the GPU. However, there is still some data in the main function that cannot be uploaded. My idea is to partially render on the CPU and partially on the GPU—for example, using TLS to determine whether the current frame should be processed by the CPU or GPU. Can someone give me some guidance?

Realmente pensei no Mesmo, até conseguir replicar o que foi Repassado pelo Takumi e por z0lik, consegui fazer os Ajustes da camera, mais eu não tive um grande desempenho consideravel em CPU's mais antigas.

Até comecei a Conversão total do Cliente usando o Glew32 para usar o OpenGL moderno nas Chamadas Gerais do Cliente.

Percebi que mesmo implementando, seria Nescessário Mudar completamente todas as Chamadas do RenderMesh, RenderBody, RenderBodyShadow.

Para funcionar é Nescessário Iniciar o CPP novo citado pelo Takumi, recriar os Arquivos .vs e .fs, Chamar na Função Open2 e em Seguida, alterar o Final do RenderMesh.
Now the entire RenderMesh is being passed to the GPU, without distinguishing between CPU and GPU. We've implemented effective optimization techniques such as VAO, VBO, EBO, and UBO. Unfortunately, as you mentioned, while this yields good performance on high-end graphics cards, the improvement is not significant on older GPUs, and there hasn't been much progress so far.



Online Feche #38 Posteado: August 08, 2025, 01:15:58 PM

  • C++ Coder
  • 0 puntos por ventas
  • *
  • Rank: Dedicado
  • Posts: 50
  • Gracias recibida: 1506
  • ar
After a period of research, I successfully passed the vertex data from OpenGL to the GPU. However, there is still some data in the main function that cannot be uploaded. My idea is to partially render on the CPU and partially on the GPU—for example, using TLS to determine whether the current frame should be processed by the CPU or GPU. Can someone give me some guidance?

Realmente pensei no Mesmo, até conseguir replicar o que foi Repassado pelo Takumi e por z0lik, consegui fazer os Ajustes da camera, mais eu não tive um grande desempenho consideravel em CPU's mais antigas.

Até comecei a Conversão total do Cliente usando o Glew32 para usar o OpenGL moderno nas Chamadas Gerais do Cliente.

Percebi que mesmo implementando, seria Nescessário Mudar completamente todas as Chamadas do RenderMesh, RenderBody, RenderBodyShadow.

Para funcionar é Nescessário Iniciar o CPP novo citado pelo Takumi, recriar os Arquivos .vs e .fs, Chamar na Função Open2 e em Seguida, alterar o Final do RenderMesh.
Now the entire RenderMesh is being passed to the GPU, without distinguishing between CPU and GPU. We've implemented effective optimization techniques such as VAO, VBO, EBO, and UBO. Unfortunately, as you mentioned, while this yields good performance on high-end graphics cards, the improvement is not significant on older GPUs, and there hasn't been much progress so far.

The issue with this implementation is that all objects must be on a SINGLE VAO, right now it is binding -> rendering -> unbinding (this can be skipped) -> setting OGL program to 0 (this can be skipped too) - the right solution would be to use the single VAO, save all OGL states and render each object by using glDrawElementsBaseVertex.

If anyone is trying to make the shaders, I can share the one I made for OpenGL 2.0 - bone matrix, chrome effects and lighting is done on GPU.

Vertex shader


Fragment shader:


You then would need to send the data to the GPU:



Offline z0lik #39 Posteado: August 23, 2025, 03:28:09 AM

  • 0 puntos por ventas
  • *
  • Rank: Principiante
  • Posts: 6
  • Gracias recibida: 3
  • it
// This function is from 0.97d - so adjust according to your game version


AI?

Discord: z0lik

Solo usuarios registrados pueden comentar y agradecer, Logueate o Registrate


 

Related Topics

  Subject / Started by Replies Last post
4 Replies
5404 Views
Last post March 03, 2020, 05:27:28 PM
by jorginhuz
4 Replies
1931 Views
Last post March 02, 2025, 08:12:33 PM
by czrdiamond
33 Replies
8013 Views
Last post November 14, 2021, 03:43:48 PM
by jorge2016
27 Replies
11795 Views
Last post April 06, 2025, 06:00:54 AM
by Xingaw
8 Replies
5798 Views
Last post June 03, 2024, 11:47:23 PM
by Kosh