shtuff
This commit is contained in:
parent
af98c41a6f
commit
41a09cc8f3
@ -11,7 +11,7 @@ local new_rotation = 0
|
|||||||
-- Variables for bobbing effect
|
-- Variables for bobbing effect
|
||||||
local initial_position = {x = 0, y = 0, z = 0} -- To store the gun's initial position
|
local initial_position = {x = 0, y = 0, z = 0} -- To store the gun's initial position
|
||||||
local bobAmplitude = 0.5 -- Amplitude of the bobbing (units)
|
local bobAmplitude = 0.5 -- Amplitude of the bobbing (units)
|
||||||
local bobFrequency = 0.1 -- Frequency of the bobbing (oscillations per second)
|
local bobFrequency = 0.5 -- Frequency of the bobbing (oscillations per second)
|
||||||
|
|
||||||
-- Reference to the Gun GameObject and its Transform component
|
-- Reference to the Gun GameObject and its Transform component
|
||||||
local gun = nil
|
local gun = nil
|
||||||
|
@ -11,38 +11,19 @@ uniform int uNumDiffuseTextures; // Number of active diffuse textures
|
|||||||
|
|
||||||
// Input variables from the vertex shader
|
// Input variables from the vertex shader
|
||||||
in vec2 TexCoords; // Texture coordinates
|
in vec2 TexCoords; // Texture coordinates
|
||||||
|
flat in int TextureIndex; // Texture index for this fragment
|
||||||
|
|
||||||
// Output fragment color
|
// Output fragment color
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Define grid dimensions
|
// Clamp the texture index to prevent out-of-bounds access
|
||||||
const int gridCols = 8; // Number of columns in the grid
|
int texIndex = clamp(TextureIndex, 0, uNumDiffuseTextures - 1);
|
||||||
const int gridRows = 4; // Number of rows in the grid
|
|
||||||
const float gridWidth = 1.0 / float(gridCols);
|
|
||||||
const float gridHeight = 1.0 / float(gridRows);
|
|
||||||
|
|
||||||
// Calculate grid cell indices based on TexCoords
|
// Sample the texture using the provided index and texture coordinates
|
||||||
int col = int(floor(TexCoords.x / gridWidth));
|
vec4 sampledColor = texture(uTextures.texture_diffuse[texIndex], TexCoords);
|
||||||
int row = int(floor(TexCoords.y / gridHeight));
|
|
||||||
|
|
||||||
// Clamp indices to grid boundaries to prevent out-of-range access
|
|
||||||
col = clamp(col, 0, gridCols - 1);
|
|
||||||
row = clamp(row, 0, gridRows - 1);
|
|
||||||
|
|
||||||
// Calculate texture index based on row and column
|
|
||||||
int texIndex = row * gridCols + col;
|
|
||||||
|
|
||||||
// Clamp texture index to the number of active textures
|
|
||||||
texIndex = clamp(texIndex, 0, uNumDiffuseTextures - 1);
|
|
||||||
|
|
||||||
// Calculate local texture coordinates within the grid cell
|
|
||||||
vec2 localTexCoords = fract(TexCoords / vec2(gridWidth, gridHeight));
|
|
||||||
|
|
||||||
// Sample the selected texture using localTexCoords
|
|
||||||
vec4 color = texture(uTextures.texture_diffuse[texIndex], localTexCoords);
|
|
||||||
|
|
||||||
// Set the final fragment color
|
// Set the final fragment color
|
||||||
FragColor = color;
|
FragColor = sampledColor;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
layout(location = 0) in vec3 aPos; // Vertex position
|
layout(location = 0) in vec3 aPos; // Vertex position
|
||||||
layout(location = 1) in vec3 aNormal; // Vertex normal
|
layout(location = 1) in vec3 aNormal; // Vertex normal
|
||||||
layout(location = 2) in vec2 aTexCoords; // Vertex texture coordinates
|
layout(location = 2) in vec2 aTexCoords; // Vertex texture coordinates
|
||||||
|
layout(location = 3) in int aTexIndex; // Texture index (integer)
|
||||||
|
|
||||||
// Uniforms
|
// Uniforms
|
||||||
uniform mat4 uMVP; // Model-View-Projection matrix
|
uniform mat4 uMVP; // Model-View-Projection matrix
|
||||||
@ -11,20 +12,22 @@ uniform mat4 uModel; // Model matrix
|
|||||||
|
|
||||||
// Output variables to the fragment shader
|
// Output variables to the fragment shader
|
||||||
out vec2 TexCoords; // Passed texture coordinates
|
out vec2 TexCoords; // Passed texture coordinates
|
||||||
out vec3 Normal; // Passed normal vector
|
flat out int TextureIndex; // Passed texture index
|
||||||
out vec3 FragPos; // Passed fragment position
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Calculate the position of the vertex in clip space
|
// Transform vertex position to clip space
|
||||||
gl_Position = uMVP * vec4(aPos, 1.0);
|
gl_Position = uMVP * vec4(aPos, 1.0);
|
||||||
|
|
||||||
// Calculate the position of the vertex in world space
|
// Transform vertex position to world space
|
||||||
FragPos = vec3(uModel * vec4(aPos, 1.0));
|
vec3 FragPos = vec3(uModel * vec4(aPos, 1.0));
|
||||||
|
|
||||||
// Calculate the normal vector in world space
|
// Transform normal to world space
|
||||||
Normal = mat3(transpose(inverse(uModel))) * aNormal;
|
vec3 Normal = mat3(transpose(inverse(uModel))) * aNormal;
|
||||||
|
|
||||||
// Pass through the texture coordinates
|
// Pass through texture coordinates
|
||||||
TexCoords = aTexCoords;
|
TexCoords = aTexCoords;
|
||||||
|
|
||||||
|
// Pass through the texture index
|
||||||
|
TextureIndex = aTexIndex;
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,27 Size=1904
|
|||||||
DockNode ID=0x00000017 Parent=0x0000000D SizeRef=1303,751 CentralNode=1 HiddenTabBar=1 Selected=0xDFF75B3F
|
DockNode ID=0x00000017 Parent=0x0000000D SizeRef=1303,751 CentralNode=1 HiddenTabBar=1 Selected=0xDFF75B3F
|
||||||
DockNode ID=0x00000018 Parent=0x0000000D SizeRef=1303,389 Split=X Selected=0x9B5D3198
|
DockNode ID=0x00000018 Parent=0x0000000D SizeRef=1303,389 Split=X Selected=0x9B5D3198
|
||||||
DockNode ID=0x0000001B Parent=0x00000018 SizeRef=612,680 HiddenTabBar=1 Selected=0x1C0788A1
|
DockNode ID=0x0000001B Parent=0x00000018 SizeRef=612,680 HiddenTabBar=1 Selected=0x1C0788A1
|
||||||
DockNode ID=0x0000001C Parent=0x00000018 SizeRef=645,680 Selected=0x9B5D3198
|
DockNode ID=0x0000001C Parent=0x00000018 SizeRef=645,680 Selected=0x7D9E6BA2
|
||||||
DockNode ID=0x0000000E Parent=0x00000003 SizeRef=1202,569 Selected=0xE98146C5
|
DockNode ID=0x0000000E Parent=0x00000003 SizeRef=1202,569 Selected=0xE98146C5
|
||||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=1202,291 Selected=0x9DD4E196
|
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=1202,291 Selected=0x9DD4E196
|
||||||
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=334,1142 HiddenTabBar=1 Selected=0x36DC96AB
|
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=334,1142 HiddenTabBar=1 Selected=0x36DC96AB
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
Entities:
|
Entities:
|
||||||
- ID: 0
|
- ID: 0
|
||||||
Name: Gun
|
Name: Bacround
|
||||||
Components:
|
Components:
|
||||||
Transform:
|
Transform:
|
||||||
Position: [-0.200000003, 14.618, 0.699999988]
|
Position: [-0.200000003, 244.5, -220.699997]
|
||||||
Rotation: [0, -88, 0]
|
Rotation: [0, -88, 0]
|
||||||
Scale: [0.0500000007, 0.0500000007, 0.0500000007]
|
Scale: [1, 1, 1]
|
||||||
Mesh:
|
Mesh:
|
||||||
vao: 7
|
vao: 4
|
||||||
indexCount: 786801
|
indexCount: 786801
|
||||||
textures:
|
textures:
|
||||||
- id: 11
|
- id: 34
|
||||||
type: texture_diffuse
|
type: texture_diffuse
|
||||||
path: textures/lion.tga
|
path: textures/lion.tga
|
||||||
- id: 12
|
- id: 12
|
||||||
@ -83,5 +83,19 @@ Entities:
|
|||||||
type: texture_diffuse
|
type: texture_diffuse
|
||||||
path: textures/vase_round.tga
|
path: textures/vase_round.tga
|
||||||
MeshPath: assets/models/sponza.obj
|
MeshPath: assets/models/sponza.obj
|
||||||
|
ScriptComponent:
|
||||||
|
ScriptPath: ""
|
||||||
|
- ID: 1
|
||||||
|
Name: Gun
|
||||||
|
Components:
|
||||||
ScriptComponent:
|
ScriptComponent:
|
||||||
ScriptPath: assets/scripts/BouncingItem.lua
|
ScriptPath: assets/scripts/BouncingItem.lua
|
||||||
|
Mesh:
|
||||||
|
vao: 5
|
||||||
|
indexCount: 116445
|
||||||
|
textures: ~
|
||||||
|
MeshPath: assets/models/AK-47.obj
|
||||||
|
Transform:
|
||||||
|
Position: [0, 9.54316807, -50]
|
||||||
|
Rotation: [0, 253.495804, 0]
|
||||||
|
Scale: [0.100000001, 0.100000001, 0.100000001]
|
@ -18,7 +18,7 @@ extern std::vector<std::shared_ptr<GameObject>> g_GameObjects;
|
|||||||
|
|
||||||
#define CAM_FOV 45.0f
|
#define CAM_FOV 45.0f
|
||||||
#define CAM_NEAR_PLAIN 0.1f
|
#define CAM_NEAR_PLAIN 0.1f
|
||||||
#define CAM_FAR_PLAIN 1000.0f
|
#define CAM_FAR_PLAIN 2048.0f
|
||||||
|
|
||||||
// Include your AssetManager & Shader headers
|
// Include your AssetManager & Shader headers
|
||||||
#include "Engine/AssetManager.h"
|
#include "Engine/AssetManager.h"
|
||||||
@ -400,7 +400,7 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning)
|
|||||||
// Use our loaded shader
|
// Use our loaded shader
|
||||||
if (!m_ShaderPtr)
|
if (!m_ShaderPtr)
|
||||||
{
|
{
|
||||||
std::cerr << "[RenderWindow] Shader pointer is null. Cannot render." << std::endl;
|
DEBUG_PRINT("[RenderWindow] Shader pointer is null. Cannot render.");
|
||||||
m_FBO.Unbind();
|
m_FBO.Unbind();
|
||||||
return; // Can't render without a shader
|
return; // Can't render without a shader
|
||||||
}
|
}
|
||||||
@ -447,7 +447,7 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning)
|
|||||||
// Validate VAO
|
// Validate VAO
|
||||||
if (mesh->vao == 0)
|
if (mesh->vao == 0)
|
||||||
{
|
{
|
||||||
std::cerr << "[RenderWindow] Warning: Mesh VAO is not initialized." << std::endl;
|
DEBUG_PRINT("[RenderWindow] Warning: Mesh VAO is not initialized.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,7 +472,7 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "[RenderWindow] Warning: Uniform 'uMVP' not found in shader." << std::endl;
|
DEBUG_PRINT("[RenderWindow] Warning: Uniform 'uMVP' not found in shader.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass Model matrix to the shader
|
// Pass Model matrix to the shader
|
||||||
@ -483,7 +483,7 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "[RenderWindow] Warning: Uniform 'uModel' not found in shader." << std::endl;
|
DEBUG_PRINT("[RenderWindow] Warning: Uniform 'uModel' not found in shader.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
@ -507,7 +507,6 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning)
|
|||||||
// Activate the appropriate texture unit
|
// Activate the appropriate texture unit
|
||||||
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture.id);
|
glBindTexture(GL_TEXTURE_2D, texture.id);
|
||||||
CheckOpenGLError("After glBindTexture");
|
|
||||||
|
|
||||||
// Construct the uniform name dynamically (e.g., "uTextures.texture_diffuse[0]")
|
// Construct the uniform name dynamically (e.g., "uTextures.texture_diffuse[0]")
|
||||||
std::string uniformName = "uTextures.texture_diffuse[" + std::to_string(textureUnit) + "]";
|
std::string uniformName = "uTextures.texture_diffuse[" + std::to_string(textureUnit) + "]";
|
||||||
@ -516,12 +515,6 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning)
|
|||||||
if (texLoc != -1)
|
if (texLoc != -1)
|
||||||
{
|
{
|
||||||
glUniform1i(texLoc, textureUnit);
|
glUniform1i(texLoc, textureUnit);
|
||||||
CheckOpenGLError("After glUniform1i for texture");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << "[RenderWindow] Warning: Uniform '" << uniformName
|
|
||||||
<< "' not found in shader." << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
textureUnit++;
|
textureUnit++;
|
||||||
@ -549,7 +542,7 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "[RenderWindow] Warning: Uniform 'uNumDiffuseTextures' not found in shader." << std::endl;
|
DEBUG_PRINT("[RenderWindow] Warning: Uniform 'uNumDiffuseTextures' not found in shader.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user