prbTexture+ammo_count #10

Merged
s473616 merged 7 commits from prbTexture+ammo_count into master 2024-02-02 22:15:40 +01:00
18 changed files with 61437 additions and 15 deletions
Showing only changes of commit 67fa38035c - Show all commits

View File

@ -57,7 +57,7 @@ public:
0.,0.,0.,1., 0.,0.,0.,1.,
}); });
return glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f)); return glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.02f));
} }
void setPerticlesParameters(float speed, float generationInterval) { void setPerticlesParameters(float speed, float generationInterval) {

View File

@ -62,6 +62,8 @@
<None Include="shaders\shader_skybox.vert" /> <None Include="shaders\shader_skybox.vert" />
<None Include="shaders\shader_sprite.frag" /> <None Include="shaders\shader_sprite.frag" />
<None Include="shaders\shader_sprite.vert" /> <None Include="shaders\shader_sprite.vert" />
<None Include="shaders\shader_tex.frag" />
<None Include="shaders\shader_tex.vert" />
<None Include="shaders\test.frag" /> <None Include="shaders\test.frag" />
<None Include="shaders\test.vert" /> <None Include="shaders\test.vert" />
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,14 @@
# Blender 3.4.1 MTL File: 'StarShip2.blend'
# www.blender.org
newmtl Material.003
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ni 1.450000
d 1.000000
illum 2
map_Kd C:/Users/dovgo/OneDrive/Desktop/3D/Texture/StarShip2/Material.001_Base_color.jpg
map_Ns C:/Users/dovgo/OneDrive/Desktop/3D/Texture/StarShip2/Material.001_Roughness.jpg
map_refl C:/Users/dovgo/OneDrive/Desktop/3D/Texture/StarShip2/Material.001_Metallic.jpg
map_Ke C:/Users/dovgo/OneDrive/Desktop/3D/Texture/StarShip2/Material.001_Emissive.jpg
map_Bump -bm 1.000000 C:/Users/dovgo/OneDrive/Desktop/3D/Texture/StarShip2/Material.001_Normal_DirectX.jpg

File diff suppressed because it is too large Load Diff

View File

@ -9,8 +9,8 @@ uniform vec3 cameraPos;
uniform vec3 color; uniform vec3 color;
uniform vec3 lightPositions[100]; uniform vec3 lightPositions[8];
uniform vec3 lightColors[100]; uniform vec3 lightColors[8];
uniform vec3 spotlightPos; uniform vec3 spotlightPos;
uniform vec3 spotlightColor; uniform vec3 spotlightColor;
@ -103,7 +103,7 @@ void main()
vec3 ambient = AMBIENT * color; vec3 ambient = AMBIENT * color;
vec3 ilumination = ambient; vec3 ilumination = ambient;
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 8; ++i) {
lightDirs[i] = normalize(lightPositions[i] - worldPos); lightDirs[i] = normalize(lightPositions[i] - worldPos);
vec3 attenuatedlightColor = lightColors[i] / pow(length(lightPositions[i] - worldPos), 2); vec3 attenuatedlightColor = lightColors[i] / pow(length(lightPositions[i] - worldPos), 2);
ilumination = ilumination+PBRLight(lightDirs[i], attenuatedlightColor * 300, normal, viewDir); ilumination = ilumination+PBRLight(lightDirs[i], attenuatedlightColor * 300, normal, viewDir);

View File

@ -12,12 +12,12 @@ uniform mat4 modelMatrix;
out vec3 vecNormal; out vec3 vecNormal;
out vec3 worldPos; out vec3 worldPos;
uniform vec3 lightsPositions[100]; uniform vec3 lightsPositions[8];
uniform vec3 spotlightPos; uniform vec3 spotlightPos;
uniform vec3 cameraPos; uniform vec3 cameraPos;
out vec3 viewDirTS; out vec3 viewDirTS;
out vec3 lightDirTS[100]; out vec3 lightDirTS[8];
out vec3 spotlightDirTS; out vec3 spotlightDirTS;
void main() void main()
@ -33,7 +33,7 @@ void main()
vec3 V = normalize(cameraPos-worldPos); vec3 V = normalize(cameraPos-worldPos);
viewDirTS = TBN*V; viewDirTS = TBN*V;
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 8; ++i) {
vec3 L = normalize(lightsPositions[i]-worldPos); vec3 L = normalize(lightsPositions[i]-worldPos);
lightDirTS[i] = TBN*L; lightDirTS[i] = TBN*L;
} }

View File

@ -0,0 +1,128 @@
#version 430 core
float AMBIENT = 0.03;
float PI = 3.14;
uniform sampler2D depthMap;
uniform vec3 cameraPos;
uniform sampler2D textureSampler;
uniform vec3 lightPositions[100];
uniform vec3 lightColors[100];
uniform vec3 spotlightPos;
uniform vec3 spotlightColor;
uniform vec3 spotlightConeDir;
uniform vec3 spotlightPhi;
uniform float metallic;
uniform float roughness;
uniform float exposition;
in vec3 vecNormal;
in vec3 worldPos;
in vec2 TexCoords;
out vec4 outColor;
in vec3 viewDirTS;
in vec3 lightDirTS[4];
in vec3 spotlightDirTS;
in vec3 sunDirTS;
in vec3 test;
float DistributionGGX(vec3 normal, vec3 H, float roughness){
float a = roughness*roughness;
float a2 = a*a;
float NdotH = max(dot(normal, H), 0.0);
float NdotH2 = NdotH*NdotH;
float num = a2;
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
denom = PI * denom * denom;
return num / denom;
}
float GeometrySchlickGGX(float NdotV, float roughness){
float r = (roughness + 1.0);
float k = (r*r) / 8.0;
float num = NdotV;
float denom = NdotV * (1.0 - k) + k;
return num / denom;
}
float GeometrySmith(vec3 normal, vec3 V, vec3 lightDir, float roughness){
float NdotV = max(dot(normal, V), 0.0);
float NdotL = max(dot(normal, lightDir), 0.0);
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
return ggx1 * ggx2;
}
vec3 fresnelSchlick(float cosTheta, vec3 F0){
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
}
vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V, vec3 albedo){
float diffuse=max(0,dot(normal,lightDir));
vec3 F0 = vec3(0.04);
F0 = mix(F0, albedo , metallic);
vec3 H = normalize(V + lightDir);
float NDF = DistributionGGX(normal, H, roughness);
float G = GeometrySmith(normal, V, lightDir, roughness);
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
vec3 kS = F;
vec3 kD = vec3(1.0) - kS;
kD *= 1.0 - metallic;
vec3 numerator = NDF * G * F;
float denominator = 4.0 * max(dot(normal, V), 0.0) * max(dot(normal, lightDir), 0.0) + 0.0001;
vec3 specular = numerator / denominator;
float NdotL = max(dot(normal, lightDir), 0.0);
return (kD * albedo / PI + specular) * radiance * NdotL;
}
void main()
{
vec4 texColor = texture(textureSampler, TexCoords);
vec3 normal = normalize(vecNormal);
vec3 viewDir = normalize(cameraPos-worldPos);
vec3 lightDirs[4];
vec3 ambient = AMBIENT * texColor.rgb;
vec3 ilumination = ambient;
for (int i = 0; i < 100; ++i) {
lightDirs[i] = normalize(lightPositions[i] - worldPos);
vec3 attenuatedlightColor = lightColors[i] / pow(length(lightPositions[i] - worldPos), 2);
ilumination = ilumination+PBRLight(lightDirs[i], attenuatedlightColor * 300, normal, viewDir, texColor.rgb);
}
vec3 spotlightDir= normalize(spotlightPos-worldPos);
float angle_atenuation = clamp((dot(-normalize(spotlightPos-worldPos),spotlightConeDir)-0.5)*3,0,1);
vec3 attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2);
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir, texColor.rgb);
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
}

View File

@ -0,0 +1,46 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord;
layout(location = 3) in vec3 vertexTangent;
layout(location = 4) in vec3 vertexBitangent;
uniform mat4 transformation;
uniform mat4 modelMatrix;
out vec3 vecNormal;
out vec3 worldPos;
out vec2 TexCoords;
uniform vec3 lightsPositions[10];
uniform vec3 spotlightPos;
uniform vec3 cameraPos;
out vec3 viewDirTS;
out vec3 lightDirTS[10];
out vec3 spotlightDirTS;
void main()
{
TexCoords = vertexTexCoord;
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz;
gl_Position = transformation * vec4(vertexPosition, 1.0);
vec3 w_tangent = normalize(mat3(modelMatrix)*vertexTangent);
vec3 w_bitangent = normalize(mat3(modelMatrix)*vertexBitangent);
mat3 TBN = transpose(mat3(w_tangent, w_bitangent, vecNormal));
vec3 V = normalize(cameraPos-worldPos);
viewDirTS = TBN*V;
for (int i = 0; i < 9; ++i) {
vec3 L = normalize(lightsPositions[i]-worldPos);
lightDirTS[i] = TBN*L;
}
vec3 SL = normalize(spotlightPos-worldPos);
spotlightDirTS = TBN*SL;
}

View File

@ -188,6 +188,46 @@ void Core::drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, gl
Core::DrawContext(context); Core::DrawContext(context);
} }
void Core::drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, float roughness, float metallic, GLuint program) {
Spaceship* spaceship = Spaceship::getInstance();
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniform1f(glGetUniformLocation(program, "exposition"), 1.f);
glUniform1f(glGetUniformLocation(program, "roughness"), roughness);
glUniform1f(glGetUniformLocation(program, "metallic"), metallic);
;
//glUniform3f(glGetUniformLocation(program, "color"), color.x, color.y, color.z);
glUniform1i(glGetUniformLocation(program, "textureSampler"), 0);
glUniform3f(glGetUniformLocation(program, "cameraPos"), spaceship->cameraPos.x, spaceship->cameraPos.y, spaceship->cameraPos.z);
std::list<Sun*>* suns = GameUtils::getInstance()->getSuns();
glm::vec3 lightsPositions[100];
glm::vec3 lightsColors[100];
int i = 0;
for (Sun* sun : *suns) {
lightsPositions[i] = sun->getPosition();
lightsColors[i] = sun->getColor();
++i;
}
glUniform3fv(glGetUniformLocation(program, "lightPositions"), 100, glm::value_ptr(lightsPositions[0]));
glUniform3fv(glGetUniformLocation(program, "lightColors"), 100, glm::value_ptr(lightsColors[0]));
glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), spaceship->spotlightConeDir.x, spaceship->spotlightConeDir.y, spaceship->spotlightConeDir.z);
glUniform3f(glGetUniformLocation(program, "spotlightPos"), spaceship->spotlightPos.x, spaceship->spotlightPos.y, spaceship->spotlightPos.z);
glUniform3f(glGetUniformLocation(program, "spotlightColor"), spaceship->spotlightColor.x, spaceship->spotlightColor.y, spaceship->spotlightColor.z);
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spaceship->spotlightPhi);
Core::DrawContext(context);
}
void Core::drawSkybox(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint program) { void Core::drawSkybox(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint program) {
Spaceship* spaceship = Spaceship::getInstance(); Spaceship* spaceship = Spaceship::getInstance();
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);

View File

@ -74,4 +74,5 @@ namespace Core
glm::mat4 createPerspectiveMatrix(); glm::mat4 createPerspectiveMatrix();
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic, GLuint program); void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic, GLuint program);
void loadModelToContext(std::string path, Core::RenderContext& context); void loadModelToContext(std::string path, Core::RenderContext& context);
void drawObjectPBRTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, float roughness, float metallic, GLuint program);
} }

View File

@ -19,11 +19,20 @@ GLuint Core::LoadTexture( const char * filepath )
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
int w, h; int w, h;
unsigned char* image = SOIL_load_image(filepath, &w, &h, 0, SOIL_LOAD_RGBA); unsigned char* image = SOIL_load_image(filepath, &w, &h, 0, SOIL_LOAD_RGBA);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D); if (image) {
SOIL_free_image_data(image); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D);
SOIL_free_image_data(image);
}
else {
std::cerr << "Texture loading failed for path: " << filepath << std::endl;
}
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
//glGenerateMipmap(GL_TEXTURE_2D);
//SOIL_free_image_data(image);
return id; return id;
} }

View File

@ -39,6 +39,7 @@ namespace models {
} }
namespace texture { namespace texture {
GLuint cubemapTexture; GLuint cubemapTexture;
GLuint spaceshipTexture;
GLuint spriteTexture; GLuint spriteTexture;
} }
@ -94,6 +95,7 @@ void renderShadowapSun() {
} }
void renderScene(GLFWwindow* window) void renderScene(GLFWwindow* window)
{ {
glClearColor(0.4f, 0.4f, 0.8f, 1.0f); glClearColor(0.4f, 0.4f, 0.8f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float time = glfwGetTime(); float time = glfwGetTime();
@ -123,10 +125,13 @@ void renderScene(GLFWwindow* window)
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)), glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)),
glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0, program); glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0, program);
drawObjectPBR(models::spaceshipContext, //Core::SetActiveTexture(texture::spaceshipTexture, "textureSampler", programTex, 0);
glUseProgram(programTex);
drawObjectPBRTexture(models::spaceshipContext,
spaceship->calculateModelMatrix(), spaceship->calculateModelMatrix(),
spaceship->color, texture::spaceshipTexture,
spaceship->roughness, spaceship->metallic, program spaceship->roughness, spaceship->metallic, programTex
); );
glUseProgram(programSprite); glUseProgram(programSprite);
@ -209,11 +214,14 @@ void init(GLFWwindow* window)
programTest = gameUtils->shaderLoader->CreateProgram("shaders/test.vert", "shaders/test.frag"); programTest = gameUtils->shaderLoader->CreateProgram("shaders/test.vert", "shaders/test.frag");
programSun = gameUtils->shaderLoader->CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag"); programSun = gameUtils->shaderLoader->CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
programCubemap = gameUtils->shaderLoader->CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag"); programCubemap = gameUtils->shaderLoader->CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
programTex = gameUtils->shaderLoader->CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
programSprite = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite.vert", "shaders/shader_sprite.frag"); programSprite = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite.vert", "shaders/shader_sprite.frag");
programParticle = gameUtils->shaderLoader->CreateProgram("shaders/particle.vert", "shaders/particle.frag"); programParticle = gameUtils->shaderLoader->CreateProgram("shaders/particle.vert", "shaders/particle.frag");
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext); loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
loadModelToContext("./models/spaceship.obj", models::spaceshipContext); loadModelToContext("./models/StarShip2.obj", models::spaceshipContext);
loadModelToContext("./models/sphere.obj", models::sphereContext); loadModelToContext("./models/sphere.obj", models::sphereContext);
loadModelToContext("./models/cube.obj", models::cubeContext); loadModelToContext("./models/cube.obj", models::cubeContext);
Core::loadModelToContext("./models/sphere.obj", GameUtils::getInstance()->sphereContext); Core::loadModelToContext("./models/sphere.obj", GameUtils::getInstance()->sphereContext);
@ -230,6 +238,8 @@ void init(GLFWwindow* window)
}; };
texture::cubemapTexture = Core::LoadCubemap(cubeFaces); texture::cubemapTexture = Core::LoadCubemap(cubeFaces);
texture::spaceshipTexture = Core::LoadTexture("./textures/spaceship/Material.001_Base_color.jpg");
spaceship->createParticles(); spaceship->createParticles();
createSuns(); createSuns();

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB