Move Light struct to example
This commit is contained in:
parent
3113a20390
commit
d0ff78e7f4
4 changed files with 27 additions and 3 deletions
|
@ -7,7 +7,9 @@ in vec3 vertexNormal;
|
||||||
|
|
||||||
// Projection and model data
|
// Projection and model data
|
||||||
uniform mat4 mvpMatrix;
|
uniform mat4 mvpMatrix;
|
||||||
|
|
||||||
uniform mat4 modelMatrix;
|
uniform mat4 modelMatrix;
|
||||||
|
//uniform mat4 viewMatrix; // Not used
|
||||||
|
|
||||||
// Attributes to fragment shader
|
// Attributes to fragment shader
|
||||||
out vec2 fragTexCoord;
|
out vec2 fragTexCoord;
|
||||||
|
|
|
@ -14,6 +14,17 @@
|
||||||
#define SHININESS_SPEED 1.0f
|
#define SHININESS_SPEED 1.0f
|
||||||
#define LIGHT_SPEED 0.25f
|
#define LIGHT_SPEED 0.25f
|
||||||
|
|
||||||
|
// Light type
|
||||||
|
typedef struct Light {
|
||||||
|
Vector3 position;
|
||||||
|
Vector3 direction;
|
||||||
|
float intensity;
|
||||||
|
float specIntensity;
|
||||||
|
Color diffuse;
|
||||||
|
Color ambient;
|
||||||
|
Color specular;
|
||||||
|
} Light;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
|
@ -48,6 +59,10 @@ int main()
|
||||||
int cameraLoc = GetShaderLocation(shader, "cameraPos");
|
int cameraLoc = GetShaderLocation(shader, "cameraPos");
|
||||||
int lightLoc = GetShaderLocation(shader, "lightPos");
|
int lightLoc = GetShaderLocation(shader, "lightPos");
|
||||||
|
|
||||||
|
// Model and View matrix locations (required for lighting)
|
||||||
|
int modelLoc = GetShaderLocation(shader, "modelMatrix");
|
||||||
|
//int viewLoc = GetShaderLocation(shader, "viewMatrix"); // Not used
|
||||||
|
|
||||||
// Light and material definitions
|
// Light and material definitions
|
||||||
Light light;
|
Light light;
|
||||||
Material matBlinn;
|
Material matBlinn;
|
||||||
|
@ -82,6 +97,10 @@ int main()
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update camera position
|
UpdateCamera(&camera); // Update camera position
|
||||||
|
|
||||||
|
// NOTE: Model transform can be set in model.transform or directly with params at draw... WATCH OUT!
|
||||||
|
SetShaderValueMatrix(shader, modelLoc, model.transform); // Send model matrix to shader
|
||||||
|
//SetShaderValueMatrix(shader, viewLoc, GetCameraMatrix(camera)); // Not used
|
||||||
|
|
||||||
// Glossiness input control
|
// Glossiness input control
|
||||||
if(IsKeyDown(KEY_UP)) matBlinn.glossiness += SHININESS_SPEED;
|
if(IsKeyDown(KEY_UP)) matBlinn.glossiness += SHININESS_SPEED;
|
||||||
else if(IsKeyDown(KEY_DOWN))
|
else if(IsKeyDown(KEY_DOWN))
|
||||||
|
|
|
@ -938,6 +938,12 @@ Vector2 WorldToScreen(Vector3 position, Camera camera)
|
||||||
return screenPosition;
|
return screenPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get transform matrix for camera
|
||||||
|
Matrix GetCameraMatrix(Camera camera)
|
||||||
|
{
|
||||||
|
return MatrixLookAt(camera.position, camera.target, camera.up);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Definition - Input (Keyboard, Mouse, Gamepad) Functions
|
// Module Functions Definition - Input (Keyboard, Mouse, Gamepad) Functions
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -167,9 +167,6 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
|
||||||
|
|
||||||
// Uniforms
|
// Uniforms
|
||||||
int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
|
int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
|
||||||
|
|
||||||
int modelLoc; // Model transformation matrix uniform location point (vertex shader)
|
|
||||||
int viewLoc; // View transformation matrix uniform location point (vertex shader)
|
|
||||||
int tintColorLoc; // Color uniform location point (fragment shader)
|
int tintColorLoc; // Color uniform location point (fragment shader)
|
||||||
|
|
||||||
int mapDiffuseLoc; // Diffuse map texture uniform location point (fragment shader)
|
int mapDiffuseLoc; // Diffuse map texture uniform location point (fragment shader)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue