aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2016-01-25 13:39:23 +0100
committerraysan5 <raysan5@gmail.com>2016-01-25 13:39:23 +0100
commitd0ff78e7f41be9884e786026ddd22ed53fc0943f (patch)
tree9ff12dc5f0a7b28dcaca0e6072bb5012f32278e3 /examples
parent3113a20390a1e4d81e9f832e7aa1d022afdb56d1 (diff)
downloadraylib-d0ff78e7f41be9884e786026ddd22ed53fc0943f.tar.gz
raylib-d0ff78e7f41be9884e786026ddd22ed53fc0943f.zip
Move Light struct to example
Diffstat (limited to 'examples')
-rw-r--r--examples/resources/shaders/phong.vs2
-rw-r--r--examples/shaders_basic_lighting.c19
2 files changed, 21 insertions, 0 deletions
diff --git a/examples/resources/shaders/phong.vs b/examples/resources/shaders/phong.vs
index ee6d34bf..52cc2227 100644
--- a/examples/resources/shaders/phong.vs
+++ b/examples/resources/shaders/phong.vs
@@ -7,7 +7,9 @@ in vec3 vertexNormal;
// Projection and model data
uniform mat4 mvpMatrix;
+
uniform mat4 modelMatrix;
+//uniform mat4 viewMatrix; // Not used
// Attributes to fragment shader
out vec2 fragTexCoord;
diff --git a/examples/shaders_basic_lighting.c b/examples/shaders_basic_lighting.c
index ba779b94..649eab74 100644
--- a/examples/shaders_basic_lighting.c
+++ b/examples/shaders_basic_lighting.c
@@ -14,6 +14,17 @@
#define SHININESS_SPEED 1.0f
#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()
{
// Initialization
@@ -48,6 +59,10 @@ int main()
int cameraLoc = GetShaderLocation(shader, "cameraPos");
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 light;
Material matBlinn;
@@ -82,6 +97,10 @@ int main()
//----------------------------------------------------------------------------------
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
if(IsKeyDown(KEY_UP)) matBlinn.glossiness += SHININESS_SPEED;
else if(IsKeyDown(KEY_DOWN))