Some code tweaks
This commit is contained in:
parent
8724cf2ea5
commit
a6297a2be1
6 changed files with 16 additions and 20 deletions
|
@ -15,7 +15,7 @@ in vec3 fragPosition;
|
||||||
uniform samplerCube environmentMap;
|
uniform samplerCube environmentMap;
|
||||||
|
|
||||||
// Constant values
|
// Constant values
|
||||||
const float PI = 3.14159265359f;
|
const float PI = 3.14159265359;
|
||||||
|
|
||||||
// Output fragment color
|
// Output fragment color
|
||||||
out vec4 finalColor;
|
out vec4 finalColor;
|
||||||
|
@ -31,8 +31,8 @@ void main()
|
||||||
vec3 right = cross(up, normal);
|
vec3 right = cross(up, normal);
|
||||||
up = cross(normal, right);
|
up = cross(normal, right);
|
||||||
|
|
||||||
float sampleDelta = 0.025f;
|
float sampleDelta = 0.025;
|
||||||
float nrSamples = 0.0f;
|
float nrSamples = 0.0;
|
||||||
|
|
||||||
for (float phi = 0.0; phi < 2.0*PI; phi += sampleDelta)
|
for (float phi = 0.0; phi < 2.0*PI; phi += sampleDelta)
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,7 +34,7 @@ void main()
|
||||||
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||||
|
|
||||||
// Calculate fragment position based on model transformations
|
// Calculate fragment position based on model transformations
|
||||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0f));
|
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
|
||||||
|
|
||||||
// Send vertex attributes to fragment shader
|
// Send vertex attributes to fragment shader
|
||||||
fragTexCoord = vertexTexCoord;
|
fragTexCoord = vertexTexCoord;
|
||||||
|
|
|
@ -18,7 +18,7 @@ uniform samplerCube environmentMap;
|
||||||
uniform float roughness;
|
uniform float roughness;
|
||||||
|
|
||||||
// Constant values
|
// Constant values
|
||||||
const float PI = 3.14159265359f;
|
const float PI = 3.14159265359;
|
||||||
|
|
||||||
// Output fragment color
|
// Output fragment color
|
||||||
out vec4 finalColor;
|
out vec4 finalColor;
|
||||||
|
@ -35,7 +35,7 @@ float DistributionGGX(vec3 N, vec3 H, float roughness)
|
||||||
float NdotH = max(dot(N, H), 0.0);
|
float NdotH = max(dot(N, H), 0.0);
|
||||||
float NdotH2 = NdotH*NdotH;
|
float NdotH2 = NdotH*NdotH;
|
||||||
|
|
||||||
float nom = a2;
|
float nom = a2;
|
||||||
float denom = (NdotH2*(a2 - 1.0) + 1.0);
|
float denom = (NdotH2*(a2 - 1.0) + 1.0);
|
||||||
denom = PI*denom*denom;
|
denom = PI*denom*denom;
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ float RadicalInverse_VdC(uint bits)
|
||||||
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
|
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
|
||||||
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
|
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
|
||||||
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
|
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
|
||||||
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
|
return float(bits)*2.3283064365386963e-10; // / 0x100000000
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 Hammersley(uint i, uint N)
|
vec2 Hammersley(uint i, uint N)
|
||||||
|
@ -60,7 +60,7 @@ vec2 Hammersley(uint i, uint N)
|
||||||
vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
|
vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
|
||||||
{
|
{
|
||||||
float a = roughness*roughness;
|
float a = roughness*roughness;
|
||||||
float phi = 2.0 * PI * Xi.x;
|
float phi = 2.0*PI*Xi.x;
|
||||||
float cosTheta = sqrt((1.0 - Xi.y)/(1.0 + (a*a - 1.0)*Xi.y));
|
float cosTheta = sqrt((1.0 - Xi.y)/(1.0 + (a*a - 1.0)*Xi.y));
|
||||||
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);
|
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);
|
||||||
|
|
||||||
|
|
|
@ -68,17 +68,11 @@ typedef enum {
|
||||||
extern "C" { // Prevents name mangling of functions
|
extern "C" { // Prevents name mangling of functions
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
// Global Variables Definition
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
int lightsCount = 0; // Current amount of created lights
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Declaration
|
// Module Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
Light CreateLight(int type, Vector3 position, Vector3 target, Color color, Shader shader); // Create a light and get shader locations
|
Light CreateLight(int type, Vector3 position, Vector3 target, Color color, Shader shader); // Create a light and get shader locations
|
||||||
void UpdateLightValues(Shader shader, Light light); // Send light properties to shader
|
void UpdateLightValues(Shader shader, Light light); // Send light properties to shader
|
||||||
//void InitLightLocations(Shader shader, Light *light); // Init light shader locations
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -110,7 +104,7 @@ void UpdateLightValues(Shader shader, Light light); // Send light proper
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Global Variables Definition
|
// Global Variables Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// ...
|
static int lightsCount = 0; // Current amount of created lights
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Declaration
|
// Module specific Functions Declaration
|
||||||
|
@ -142,6 +136,8 @@ Light CreateLight(int type, Vector3 position, Vector3 target, Color color, Shade
|
||||||
char posName[32] = "lights[x].position\0";
|
char posName[32] = "lights[x].position\0";
|
||||||
char targetName[32] = "lights[x].target\0";
|
char targetName[32] = "lights[x].target\0";
|
||||||
char colorName[32] = "lights[x].color\0";
|
char colorName[32] = "lights[x].color\0";
|
||||||
|
|
||||||
|
// Set location name [x] depending on lights count
|
||||||
enabledName[7] = '0' + lightsCount;
|
enabledName[7] = '0' + lightsCount;
|
||||||
typeName[7] = '0' + lightsCount;
|
typeName[7] = '0' + lightsCount;
|
||||||
posName[7] = '0' + lightsCount;
|
posName[7] = '0' + lightsCount;
|
||||||
|
|
|
@ -112,7 +112,7 @@ int main(void)
|
||||||
UpdateCamera(&camera); // Update camera
|
UpdateCamera(&camera); // Update camera
|
||||||
|
|
||||||
// Make the lights do differing orbits
|
// Make the lights do differing orbits
|
||||||
angle -= 0.02;
|
angle -= 0.02f;
|
||||||
lights[0].position.x = cosf(angle)*4.0f;
|
lights[0].position.x = cosf(angle)*4.0f;
|
||||||
lights[0].position.z = sinf(angle)*4.0f;
|
lights[0].position.z = sinf(angle)*4.0f;
|
||||||
lights[1].position.x = cosf(-angle*0.6f)*4.0f;
|
lights[1].position.x = cosf(-angle*0.6f)*4.0f;
|
||||||
|
@ -128,8 +128,8 @@ int main(void)
|
||||||
UpdateLightValues(shader, lights[3]);
|
UpdateLightValues(shader, lights[3]);
|
||||||
|
|
||||||
// Rotate the torus
|
// Rotate the torus
|
||||||
modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025));
|
modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025f));
|
||||||
modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012));
|
modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012f));
|
||||||
|
|
||||||
// Update the light shader with the camera view position
|
// Update the light shader with the camera view position
|
||||||
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
||||||
|
@ -161,7 +161,7 @@ int main(void)
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
DrawText("Keys RGB & W toggle lights", 10, 30, 20, DARKGRAY);
|
DrawText("Use keys RGBW to toggle lights", 10, 30, 20, DARKGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3 or ES2
|
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3 or ES2
|
||||||
// Required for: rlLoadTexture() rlDeleteTextures(),
|
// Required for: rlLoadTexture() rlDeleteTextures(),
|
||||||
// rlGenerateMipmaps(), some funcs for DrawTexturePro()
|
// rlGenerateMipmaps(), some funcs for DrawTexturePro()
|
||||||
|
|
||||||
// Support only desired texture formats on stb_image
|
// Support only desired texture formats on stb_image
|
||||||
#if !defined(SUPPORT_FILEFORMAT_BMP)
|
#if !defined(SUPPORT_FILEFORMAT_BMP)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue