From 1bcb5ddd505e5c4bdac6f254e931e9c3145be88d Mon Sep 17 00:00:00 2001 From: victorfisac Date: Mon, 21 Dec 2015 17:25:22 +0100 Subject: Added lighting engine module - New lighting engine module which contains new data types Light and Material. These data types and functions facilitates making a basic 3D iluminated program with a light and a model. - Added lighting engine module example (currently included in raylib.h; it might be compiled by separate and include lighting.h in game source C file). - Corrected some opengl defines control structures and added some TODO to fix raylib-opengl 1.1 source build (note: now source can be compiled without errors, but rlglReadPixels() won't work properly). Note: most of functions of phong version 330 shader are not in v100 shaders, so I couldn't write a version 100 phong shader. These functions are included from version 150. --- examples/resources/shaders/phong.fs | 76 +++++++++++++++++++++++++++++++++++++ examples/resources/shaders/phong.vs | 28 ++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 examples/resources/shaders/phong.fs create mode 100644 examples/resources/shaders/phong.vs (limited to 'examples/resources/shaders') diff --git a/examples/resources/shaders/phong.fs b/examples/resources/shaders/phong.fs new file mode 100644 index 00000000..bb8826f4 --- /dev/null +++ b/examples/resources/shaders/phong.fs @@ -0,0 +1,76 @@ +#version 330 + +// Vertex shader input data +in vec2 fragTexCoord; +in vec3 fragNormal; + +// Diffuse data +uniform sampler2D texture0; +uniform vec4 tintColor; + +// Light attributes +uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0); +uniform vec3 light_diffuseColor = vec3(1, 0.5, 0); +uniform vec3 light_specularColor = vec3(0, 1, 0); +uniform float light_intensity = 1; +uniform float light_specIntensity = 1; + +// Material attributes +uniform vec3 mat_ambientColor = vec3(1, 1, 1); +uniform vec3 mat_specularColor = vec3(1, 1, 1); +uniform float mat_glossiness = 50; + +// World attributes +uniform vec3 lightPos; +uniform vec3 cameraPos; + +// Fragment shader output data +out vec4 fragColor; + +vec3 AmbientLighting() +{ + return mat_ambientColor * light_ambientColor; +} + +vec3 DiffuseLighting(in vec3 N, in vec3 L) +{ + // Lambertian reflection calculation + float diffuse = clamp(dot(N, L), 0, 1); + + return tintColor.xyz * light_diffuseColor * light_intensity * diffuse; +} + +vec3 SpecularLighting(in vec3 N, in vec3 L, in vec3 V) +{ + float specular = 0; + + // Calculate specular reflection only if the surface is oriented to the light source + if(dot(N, L) > 0) + { + // Calculate half vector + vec3 H = normalize(L + V); + + // Calculate specular intensity + specular = pow(dot(N, H), 3 + mat_glossiness); + } + + return mat_specularColor * light_specularColor * light_specIntensity * specular; +} + +void main() +{ + // Normalize input vectors + vec3 L = normalize(lightPos); + vec3 V = normalize(cameraPos); + vec3 N = normalize(fragNormal); + + vec3 ambient = AmbientLighting(); + vec3 diffuse = DiffuseLighting(N, L); + vec3 specular = SpecularLighting(N, L, V); + + // Get base color from texture + vec4 textureColor = texture(texture0, fragTexCoord); + vec3 finalColor = textureColor.rgb; + + fragColor = vec4(finalColor * (ambient + diffuse + specular), textureColor.a); +} \ No newline at end of file diff --git a/examples/resources/shaders/phong.vs b/examples/resources/shaders/phong.vs new file mode 100644 index 00000000..25163902 --- /dev/null +++ b/examples/resources/shaders/phong.vs @@ -0,0 +1,28 @@ +#version 330 + +// Vertex input data +in vec3 vertexPosition; +in vec2 vertexTexCoord; +in vec3 vertexNormal; + +// Projection and model data +uniform mat4 projectionMatrix; +uniform mat4 modelviewMatrix; +uniform mat4 modelMatrix; + +// Attributes to fragment shader +out vec2 fragTexCoord; +out vec3 fragNormal; + +void main() +{ + // Send texture coord to fragment shader + fragTexCoord = vertexTexCoord; + + // Calculate view vector normal from model + mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); + fragNormal = normalize(normalMatrix * vertexNormal); + + // Calculate final vertex position + gl_Position = projectionMatrix * modelviewMatrix * vec4(vertexPosition, 1.0); +} \ No newline at end of file -- cgit v1.2.3 From fb6ef2c2f4fe22552908d339cda541453e43faec Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 13 Jan 2016 17:13:28 +0100 Subject: Vertex shaders optimization --- examples/resources/shaders/base.vs | 5 +-- examples/resources/shaders/bloom.fs | 2 +- examples/resources/shaders/grayscale.fs | 6 +-- examples/resources/shaders/phong.fs | 2 +- examples/resources/shaders/phong.vs | 4 +- examples/resources/shaders/shapes_base.vs | 9 ++--- examples/resources/shaders/shapes_grayscale.fs | 4 +- examples/resources/shaders/swirl.fs | 2 +- shaders/gl330/base.vs | 5 +-- shaders/gl330/bloom.fs | 2 +- shaders/gl330/blur.fs | 2 +- shaders/gl330/cross_hatching.fs | 2 +- shaders/gl330/cross_stitching.fs | 2 +- shaders/gl330/dream_vision.fs | 2 +- shaders/gl330/fisheye.fs | 2 +- shaders/gl330/grayscale.fs | 6 +-- shaders/gl330/phong.fs | 2 +- shaders/gl330/phong.vs | 7 ++-- shaders/gl330/pixel.fs | 2 +- shaders/gl330/posterization.fs | 2 +- shaders/gl330/predator.fs | 2 +- shaders/gl330/scanlines.fs | 2 +- shaders/gl330/swirl.fs | 2 +- shaders/gl330/template.fs | 4 +- shaders/gles100/base.vs | 5 +-- shaders/gles100/bloom.fs | 2 +- shaders/gles100/blur.fs | 2 +- shaders/gles100/cross_hatching.fs | 2 +- shaders/gles100/cross_stitching.fs | 2 +- shaders/gles100/dream_vision.fs | 2 +- shaders/gles100/fisheye.fs | 2 +- shaders/gles100/grayscale.fs | 6 +-- shaders/gles100/pixel.fs | 2 +- shaders/gles100/posterization.fs | 2 +- shaders/gles100/predator.fs | 2 +- shaders/gles100/scanlines.fs | 2 +- shaders/gles100/swirl.fs | 2 +- shaders/gles100/template.fs | 4 +- src/raylib.h | 4 +- src/rlgl.c | 53 +++++++++++++------------- src/rlgl.h | 4 +- 41 files changed, 86 insertions(+), 92 deletions(-) (limited to 'examples/resources/shaders') diff --git a/examples/resources/shaders/base.vs b/examples/resources/shaders/base.vs index 59eae0a0..b0f930b7 100644 --- a/examples/resources/shaders/base.vs +++ b/examples/resources/shaders/base.vs @@ -6,8 +6,7 @@ in vec3 vertexNormal; out vec2 fragTexCoord; -uniform mat4 projectionMatrix; -uniform mat4 modelviewMatrix; +uniform mat4 mvpMatrix; // NOTE: Add here your custom variables @@ -15,5 +14,5 @@ void main() { fragTexCoord = vertexTexCoord; - gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); + gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); } \ No newline at end of file diff --git a/examples/resources/shaders/bloom.fs b/examples/resources/shaders/bloom.fs index f9cebe18..2833ce33 100644 --- a/examples/resources/shaders/bloom.fs +++ b/examples/resources/shaders/bloom.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/examples/resources/shaders/grayscale.fs b/examples/resources/shaders/grayscale.fs index 38337e00..af50b8c1 100644 --- a/examples/resources/shaders/grayscale.fs +++ b/examples/resources/shaders/grayscale.fs @@ -5,16 +5,16 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables void main() { - vec4 base = texture2D(texture0, fragTexCoord)*tintColor; + vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor; // Convert to grayscale using NTSC conversion weights float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114)); - fragColor = vec4(gray, gray, gray, tintColor.a); + fragColor = vec4(gray, gray, gray, fragTintColor.a); } \ No newline at end of file diff --git a/examples/resources/shaders/phong.fs b/examples/resources/shaders/phong.fs index bb8826f4..75b7e6d7 100644 --- a/examples/resources/shaders/phong.fs +++ b/examples/resources/shaders/phong.fs @@ -6,7 +6,7 @@ in vec3 fragNormal; // Diffuse data uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // Light attributes uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0); diff --git a/examples/resources/shaders/phong.vs b/examples/resources/shaders/phong.vs index 25163902..c6ef77de 100644 --- a/examples/resources/shaders/phong.vs +++ b/examples/resources/shaders/phong.vs @@ -6,8 +6,8 @@ in vec2 vertexTexCoord; in vec3 vertexNormal; // Projection and model data -uniform mat4 projectionMatrix; -uniform mat4 modelviewMatrix; +uniform mat4 mvpMatrix; + uniform mat4 modelMatrix; // Attributes to fragment shader diff --git a/examples/resources/shaders/shapes_base.vs b/examples/resources/shaders/shapes_base.vs index 78e543b7..1fd686be 100644 --- a/examples/resources/shaders/shapes_base.vs +++ b/examples/resources/shaders/shapes_base.vs @@ -4,16 +4,15 @@ attribute vec3 vertexPosition; attribute vec2 vertexTexCoord; attribute vec4 vertexColor; -uniform mat4 projectionMatrix; -uniform mat4 modelviewMatrix; +uniform mat4 mvpMatrix; varying vec2 fragTexCoord; -varying vec4 fragColor; +varying vec4 fragTintColor; void main() { fragTexCoord = vertexTexCoord; - fragColor = vertexColor; + fragTintColor = vertexColor; - gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); + gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); } \ No newline at end of file diff --git a/examples/resources/shaders/shapes_grayscale.fs b/examples/resources/shaders/shapes_grayscale.fs index 1b778871..23ba9153 100644 --- a/examples/resources/shaders/shapes_grayscale.fs +++ b/examples/resources/shaders/shapes_grayscale.fs @@ -2,11 +2,11 @@ uniform sampler2D texture0; varying vec2 fragTexCoord; -varying vec4 fragColor; +varying vec4 fragTintColor; void main() { - vec4 base = texture2D(texture0, fragTexCoord)*fragColor; + vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor; // Convert to grayscale using NTSC conversion weights float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114)); diff --git a/examples/resources/shaders/swirl.fs b/examples/resources/shaders/swirl.fs index ba26cc05..ace6e79d 100644 --- a/examples/resources/shaders/swirl.fs +++ b/examples/resources/shaders/swirl.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gl330/base.vs b/shaders/gl330/base.vs index 59eae0a0..b0f930b7 100644 --- a/shaders/gl330/base.vs +++ b/shaders/gl330/base.vs @@ -6,8 +6,7 @@ in vec3 vertexNormal; out vec2 fragTexCoord; -uniform mat4 projectionMatrix; -uniform mat4 modelviewMatrix; +uniform mat4 mvpMatrix; // NOTE: Add here your custom variables @@ -15,5 +14,5 @@ void main() { fragTexCoord = vertexTexCoord; - gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); + gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); } \ No newline at end of file diff --git a/shaders/gl330/bloom.fs b/shaders/gl330/bloom.fs index f9cebe18..2833ce33 100644 --- a/shaders/gl330/bloom.fs +++ b/shaders/gl330/bloom.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gl330/blur.fs b/shaders/gl330/blur.fs index b4e5bd2b..bd2b521f 100644 --- a/shaders/gl330/blur.fs +++ b/shaders/gl330/blur.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gl330/cross_hatching.fs b/shaders/gl330/cross_hatching.fs index e2362212..7e25b25b 100644 --- a/shaders/gl330/cross_hatching.fs +++ b/shaders/gl330/cross_hatching.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gl330/cross_stitching.fs b/shaders/gl330/cross_stitching.fs index 041bf1dc..73f867b6 100644 --- a/shaders/gl330/cross_stitching.fs +++ b/shaders/gl330/cross_stitching.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gl330/dream_vision.fs b/shaders/gl330/dream_vision.fs index de9c04eb..f9316342 100644 --- a/shaders/gl330/dream_vision.fs +++ b/shaders/gl330/dream_vision.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gl330/fisheye.fs b/shaders/gl330/fisheye.fs index d0e42cca..bbbff65c 100644 --- a/shaders/gl330/fisheye.fs +++ b/shaders/gl330/fisheye.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gl330/grayscale.fs b/shaders/gl330/grayscale.fs index 38337e00..af50b8c1 100644 --- a/shaders/gl330/grayscale.fs +++ b/shaders/gl330/grayscale.fs @@ -5,16 +5,16 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables void main() { - vec4 base = texture2D(texture0, fragTexCoord)*tintColor; + vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor; // Convert to grayscale using NTSC conversion weights float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114)); - fragColor = vec4(gray, gray, gray, tintColor.a); + fragColor = vec4(gray, gray, gray, fragTintColor.a); } \ No newline at end of file diff --git a/shaders/gl330/phong.fs b/shaders/gl330/phong.fs index bb8826f4..75b7e6d7 100644 --- a/shaders/gl330/phong.fs +++ b/shaders/gl330/phong.fs @@ -6,7 +6,7 @@ in vec3 fragNormal; // Diffuse data uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // Light attributes uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0); diff --git a/shaders/gl330/phong.vs b/shaders/gl330/phong.vs index 25163902..ee6d34bf 100644 --- a/shaders/gl330/phong.vs +++ b/shaders/gl330/phong.vs @@ -6,8 +6,7 @@ in vec2 vertexTexCoord; in vec3 vertexNormal; // Projection and model data -uniform mat4 projectionMatrix; -uniform mat4 modelviewMatrix; +uniform mat4 mvpMatrix; uniform mat4 modelMatrix; // Attributes to fragment shader @@ -21,8 +20,8 @@ void main() // Calculate view vector normal from model mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); - fragNormal = normalize(normalMatrix * vertexNormal); + fragNormal = normalize(normalMatrix*vertexNormal); // Calculate final vertex position - gl_Position = projectionMatrix * modelviewMatrix * vec4(vertexPosition, 1.0); + gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); } \ No newline at end of file diff --git a/shaders/gl330/pixel.fs b/shaders/gl330/pixel.fs index ec9e13d7..feee1423 100644 --- a/shaders/gl330/pixel.fs +++ b/shaders/gl330/pixel.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gl330/posterization.fs b/shaders/gl330/posterization.fs index 652cf609..a4e49466 100644 --- a/shaders/gl330/posterization.fs +++ b/shaders/gl330/posterization.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gl330/predator.fs b/shaders/gl330/predator.fs index 77882917..2295d01b 100644 --- a/shaders/gl330/predator.fs +++ b/shaders/gl330/predator.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gl330/scanlines.fs b/shaders/gl330/scanlines.fs index 7f33f882..57297299 100644 --- a/shaders/gl330/scanlines.fs +++ b/shaders/gl330/scanlines.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gl330/swirl.fs b/shaders/gl330/swirl.fs index 18a47cec..e88b59c9 100644 --- a/shaders/gl330/swirl.fs +++ b/shaders/gl330/swirl.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gl330/template.fs b/shaders/gl330/template.fs index 92221959..660e8484 100644 --- a/shaders/gl330/template.fs +++ b/shaders/gl330/template.fs @@ -5,7 +5,7 @@ in vec2 fragTexCoord; out vec4 fragColor; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables @@ -15,5 +15,5 @@ void main() // NOTE: Implement here your fragment shader code - fragColor = texelColor*tintColor; + fragColor = texelColor*fragTintColor; } diff --git a/shaders/gles100/base.vs b/shaders/gles100/base.vs index eff89c56..9f339382 100644 --- a/shaders/gles100/base.vs +++ b/shaders/gles100/base.vs @@ -6,8 +6,7 @@ attribute vec3 vertexNormal; varying vec2 fragTexCoord; -uniform mat4 projectionMatrix; -uniform mat4 modelviewMatrix; +uniform mat4 mvpMatrix; // NOTE: Add here your custom variables @@ -17,5 +16,5 @@ void main() fragTexCoord = vertexTexCoord; - gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); + gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); } \ No newline at end of file diff --git a/shaders/gles100/bloom.fs b/shaders/gles100/bloom.fs index eba44d41..33754c7e 100644 --- a/shaders/gles100/bloom.fs +++ b/shaders/gles100/bloom.fs @@ -5,7 +5,7 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gles100/blur.fs b/shaders/gles100/blur.fs index 3c865ca0..a1069c6f 100644 --- a/shaders/gles100/blur.fs +++ b/shaders/gles100/blur.fs @@ -4,7 +4,7 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gles100/cross_hatching.fs b/shaders/gles100/cross_hatching.fs index c308acb6..cf01b65e 100644 --- a/shaders/gles100/cross_hatching.fs +++ b/shaders/gles100/cross_hatching.fs @@ -5,7 +5,7 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gles100/cross_stitching.fs b/shaders/gles100/cross_stitching.fs index 09b3ad4a..f1afef04 100644 --- a/shaders/gles100/cross_stitching.fs +++ b/shaders/gles100/cross_stitching.fs @@ -5,7 +5,7 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gles100/dream_vision.fs b/shaders/gles100/dream_vision.fs index 6cbdfcd6..bb828970 100644 --- a/shaders/gles100/dream_vision.fs +++ b/shaders/gles100/dream_vision.fs @@ -5,7 +5,7 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gles100/fisheye.fs b/shaders/gles100/fisheye.fs index a21257c7..e7a4485c 100644 --- a/shaders/gles100/fisheye.fs +++ b/shaders/gles100/fisheye.fs @@ -5,7 +5,7 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gles100/grayscale.fs b/shaders/gles100/grayscale.fs index 07e79614..e55545e2 100644 --- a/shaders/gles100/grayscale.fs +++ b/shaders/gles100/grayscale.fs @@ -5,16 +5,16 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables void main() { - vec4 base = texture2D(texture0, fragTexCoord)*tintColor; + vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor; // Convert to grayscale using NTSC conversion weights float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114)); - gl_FragColor = vec4(gray, gray, gray, tintColor.a); + gl_FragColor = vec4(gray, gray, gray, fragTintColor.a); } \ No newline at end of file diff --git a/shaders/gles100/pixel.fs b/shaders/gles100/pixel.fs index eceff6e3..552e8900 100644 --- a/shaders/gles100/pixel.fs +++ b/shaders/gles100/pixel.fs @@ -5,7 +5,7 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gles100/posterization.fs b/shaders/gles100/posterization.fs index f635305e..4f4c4b93 100644 --- a/shaders/gles100/posterization.fs +++ b/shaders/gles100/posterization.fs @@ -5,7 +5,7 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gles100/predator.fs b/shaders/gles100/predator.fs index c85048a6..2fbdc7af 100644 --- a/shaders/gles100/predator.fs +++ b/shaders/gles100/predator.fs @@ -5,7 +5,7 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gles100/scanlines.fs b/shaders/gles100/scanlines.fs index 56a6f694..85de158d 100644 --- a/shaders/gles100/scanlines.fs +++ b/shaders/gles100/scanlines.fs @@ -5,7 +5,7 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gles100/swirl.fs b/shaders/gles100/swirl.fs index b50ed39e..b0d54b23 100644 --- a/shaders/gles100/swirl.fs +++ b/shaders/gles100/swirl.fs @@ -5,7 +5,7 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables diff --git a/shaders/gles100/template.fs b/shaders/gles100/template.fs index 9d9499f3..1f4b8ccf 100644 --- a/shaders/gles100/template.fs +++ b/shaders/gles100/template.fs @@ -5,7 +5,7 @@ precision mediump float; varying vec2 fragTexCoord; uniform sampler2D texture0; -uniform vec4 tintColor; +uniform vec4 fragTintColor; // NOTE: Add here your custom variables @@ -15,5 +15,5 @@ void main() // NOTE: Implement here your fragment shader code - gl_FragColor = texelColor*tintColor; + gl_FragColor = texelColor*fragTintColor; } \ No newline at end of file diff --git a/src/raylib.h b/src/raylib.h index d6b28e53..1a99f007 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -336,8 +336,8 @@ typedef struct Shader { int colorLoc; // Color attibute location point (vertex shader) // Uniforms - int projectionLoc; // Projection matrix uniform location point (vertex shader) - int modelviewLoc; // ModelView 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) diff --git a/src/rlgl.c b/src/rlgl.c index 2f525f47..e3c763be 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1295,9 +1295,10 @@ void rlglDraw(void) if ((lines.vCounter > 0) || (triangles.vCounter > 0) || (quads.vCounter > 0)) { glUseProgram(currentShader.id); + + Matrix matMVP = MatrixMultiply(modelview, projection); // Create modelview-projection matrix - glUniformMatrix4fv(currentShader.projectionLoc, 1, false, MatrixToFloat(projection)); - glUniformMatrix4fv(currentShader.modelviewLoc, 1, false, MatrixToFloat(modelview)); + glUniformMatrix4fv(currentShader.mvpLoc, 1, false, MatrixToFloat(matMVP)); glUniform1i(currentShader.mapDiffuseLoc, 0); } @@ -1520,14 +1521,14 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r Matrix matModelView = MatrixMultiply(matModel, matView); // Transform to camera-space coordinates // Calculate model-view-projection matrix (MVP) - //Matrix matMVP = MatrixMultiply(matModelView, matProjection); // Transform to screen-space coordinates + Matrix matMVP = MatrixMultiply(matModelView, matProjection); // Transform to screen-space coordinates // NOTE: Drawing in OpenGL 3.3+, matrices are passed to shader // TODO: Reduce number of matrices passed to shaders, use only matMVP glUniformMatrix4fv(model.shader.modelLoc, 1, false, MatrixToFloat(matModel)); glUniformMatrix4fv(model.shader.viewLoc, 1, false, MatrixToFloat(matView)); - glUniformMatrix4fv(model.shader.projectionLoc, 1, false, MatrixToFloat(matProjection)); - glUniformMatrix4fv(model.shader.modelviewLoc, 1, false, MatrixToFloat(matModelView)); + + glUniformMatrix4fv(model.shader.mvpLoc, 1, false, MatrixToFloat(matMVP)); // Apply color tinting to model // NOTE: Just update one uniform on fragment shader @@ -2247,13 +2248,13 @@ Shader LoadShader(char *vsFileName, char *fsFileName) shader.colorLoc = -1; // Get handles to GLSL uniform locations (vertex shader) - shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix"); + shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix"); + shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix"); shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix"); - shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix"); // Get handles to GLSL uniform locations (fragment shader) - shader.tintColorLoc = glGetUniformLocation(shader.id, "tintColor"); + shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor"); shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0"); shader.mapNormalLoc = -1; // It can be set later shader.mapSpecularLoc = -1; // It can be set later @@ -2738,40 +2739,39 @@ static Shader LoadDefaultShader(void) "in vec2 vertexTexCoord; \n" "in vec4 vertexColor; \n" "out vec2 fragTexCoord; \n" - "out vec4 tintColor; \n" + "out vec4 fragTintColor; \n" #elif defined(GRAPHICS_API_OPENGL_ES2) char vShaderStr[] = "#version 100 \n" "attribute vec3 vertexPosition; \n" "attribute vec2 vertexTexCoord; \n" "attribute vec4 vertexColor; \n" "varying vec2 fragTexCoord; \n" - "varying vec4 tintColor; \n" + "varying vec4 fragTintColor; \n" #endif - "uniform mat4 projectionMatrix; \n" - "uniform mat4 modelviewMatrix; \n" + "uniform mat4 mvpMatrix; \n" "void main() \n" "{ \n" " fragTexCoord = vertexTexCoord; \n" - " tintColor = vertexColor; \n" - " gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); \n" + " fragTintColor = vertexColor; \n" + " gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); \n" "} \n"; // Fragment shader directly defined, no external file required #if defined(GRAPHICS_API_OPENGL_33) char fShaderStr[] = "#version 330 \n" "in vec2 fragTexCoord; \n" - "in vec4 tintColor; \n" + "in vec4 fragTintColor; \n" #elif defined(GRAPHICS_API_OPENGL_ES2) char fShaderStr[] = "#version 100 \n" "precision mediump float; \n" // precision required for OpenGL ES2 (WebGL) "varying vec2 fragTexCoord; \n" - "varying vec4 tintColor; \n" + "varying vec4 fragTintColor; \n" #endif "uniform sampler2D texture0; \n" "void main() \n" "{ \n" " vec4 texelColor = texture2D(texture0, fragTexCoord); \n" // NOTE: texture2D() is deprecated on OpenGL 3.3 and ES 3.0, use texture() instead - " gl_FragColor = texelColor*tintColor; \n" + " gl_FragColor = texelColor*fragTintColor; \n" "} \n"; shader.id = LoadShaderProgram(vShaderStr, fShaderStr); @@ -2788,10 +2788,10 @@ static Shader LoadDefaultShader(void) shader.normalLoc = -1; // Get handles to GLSL uniform locations (vertex shader) - shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix"); + shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix"); + shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix"); shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix"); - shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix"); // Get handles to GLSL uniform locations (fragment shader) shader.tintColorLoc = -1; @@ -2831,12 +2831,11 @@ static Shader LoadSimpleShader(void) "attribute vec3 vertexNormal; \n" "varying vec2 fragTexCoord; \n" #endif - "uniform mat4 projectionMatrix; \n" - "uniform mat4 modelviewMatrix; \n" + "uniform mat4 mvpMatrix; \n" "void main() \n" "{ \n" " fragTexCoord = vertexTexCoord; \n" - " gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); \n" + " gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); \n" "} \n"; // Fragment shader directly defined, no external file required @@ -2849,11 +2848,11 @@ static Shader LoadSimpleShader(void) "varying vec2 fragTexCoord; \n" #endif "uniform sampler2D texture0; \n" - "uniform vec4 tintColor; \n" + "uniform vec4 fragTintColor; \n" "void main() \n" "{ \n" " vec4 texelColor = texture2D(texture0, fragTexCoord); \n" // NOTE: texture2D() is deprecated on OpenGL 3.3 and ES 3.0, use texture() instead - " gl_FragColor = texelColor*tintColor; \n" + " gl_FragColor = texelColor*fragTintColor; \n" "} \n"; shader.id = LoadShaderProgram(vShaderStr, fShaderStr); @@ -2870,13 +2869,13 @@ static Shader LoadSimpleShader(void) shader.colorLoc = -1; // Get handles to GLSL uniform locations (vertex shader) - shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix"); + shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix"); + shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix"); shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix"); - shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix"); // Get handles to GLSL uniform locations (fragment shader) - shader.tintColorLoc = glGetUniformLocation(shader.id, "tintColor"); + shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor"); shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0"); shader.mapNormalLoc = -1; // It can be set later shader.mapSpecularLoc = -1; // It can be set later diff --git a/src/rlgl.h b/src/rlgl.h index 93b56bb2..d33844ce 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -159,8 +159,8 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion; int colorLoc; // Color attibute location point (vertex shader) // Uniforms - int projectionLoc; // Projection matrix uniform location point (vertex shader) - int modelviewLoc; // ModelView 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) -- cgit v1.2.3 From 183795b8aa78fdf0b8064d72d77eaea8e7b6397b Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 16 Jan 2016 12:52:55 +0100 Subject: Review literals type --- examples/audio_music_stream.c | 2 +- examples/audio_sound_loading.c | 2 ++ examples/core_3d_camera_first_person.c | 16 ++++++++-------- examples/core_3d_camera_free.c | 13 ++++++++----- examples/core_3d_mode.c | 14 +++++++------- examples/core_3d_picking.c | 14 +++++++------- examples/core_basic_window.c | 2 ++ examples/core_input_gamepad.c | 8 ++++---- examples/core_input_keys.c | 10 +++++----- examples/core_input_mouse.c | 11 ++++------- examples/core_random_values.c | 4 ++-- examples/core_world_screen.c | 10 +++++----- examples/lighting_blinn_phong.c | 14 ++++++++------ examples/models_billboard.c | 8 ++++---- examples/models_box_collisions.c | 14 +++++++------- examples/models_cubicmap.c | 4 ++-- examples/models_geometric_shapes.c | 24 ++++++++++++------------ examples/models_heightmap.c | 4 ++-- examples/models_obj_loading.c | 8 ++++---- examples/resources/shaders/phong.fs | 26 +++++++++++++------------- examples/resources/shaders/phong.vs | 5 ++--- examples/resources/shaders/swirl.fs | 6 +++--- examples/shaders_custom_uniform.c | 8 ++++---- examples/shaders_model_shader.c | 6 +++--- examples/shaders_postprocessing.c | 6 +++--- examples/shapes_basic_shapes.c | 2 ++ examples/shapes_colors_palette.c | 2 ++ examples/shapes_logo_raylib.c | 2 ++ examples/shapes_logo_raylib_anim.c | 4 +--- examples/textures_logo_raylib.c | 3 +-- examples/textures_particles_trail_blending.c | 6 +++--- 31 files changed, 133 insertions(+), 125 deletions(-) (limited to 'examples/resources/shaders') diff --git a/examples/audio_music_stream.c b/examples/audio_music_stream.c index e61d4839..8c668cce 100644 --- a/examples/audio_music_stream.c +++ b/examples/audio_music_stream.c @@ -27,7 +27,7 @@ int main() PlayMusicStream("resources/audio/guitar_noodling.ogg"); // Play music stream int framesCounter = 0; - float timePlayed = 0; + float timePlayed = 0.0f; //float volume = 1.0; SetTargetFPS(60); // Set our game to run at 60 frames-per-second diff --git a/examples/audio_sound_loading.c b/examples/audio_sound_loading.c index 1376a27d..8819aad1 100644 --- a/examples/audio_sound_loading.c +++ b/examples/audio_sound_loading.c @@ -26,6 +26,8 @@ int main() Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop diff --git a/examples/core_3d_camera_first_person.c b/examples/core_3d_camera_first_person.c index aa947c3c..8a092275 100644 --- a/examples/core_3d_camera_first_person.c +++ b/examples/core_3d_camera_first_person.c @@ -23,7 +23,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person"); // Define the camera to look into our 3d world - Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; // Generates some random columns float heights[MAX_COLUMNS]; @@ -37,7 +37,7 @@ int main() colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 }; } - Vector3 playerPosition = { 4, 2, 4 }; // Define player position + Vector3 playerPosition = { 4.0f, 2.0f, 4.0f }; // Define player position SetCameraMode(CAMERA_FIRST_PERSON); // Set a first person camera mode @@ -60,16 +60,16 @@ int main() Begin3dMode(camera); - DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 32, 32 }, LIGHTGRAY); // Draw ground - DrawCube((Vector3){ -16, 2.5, 0 }, 1, 5, 32, BLUE); // Draw a blue wall - DrawCube((Vector3){ 16, 2.5, 0 }, 1, 5, 32, LIME); // Draw a green wall - DrawCube((Vector3){ 0, 2.5, 16 }, 32, 5, 1, GOLD); // Draw a yellow wall + DrawPlane((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector2){ 32.0f, 32.0f }, LIGHTGRAY); // Draw ground + DrawCube((Vector3){ -16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall + DrawCube((Vector3){ 16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, LIME); // Draw a green wall + DrawCube((Vector3){ 0.0f, 2.5f, 16.0f }, 32.0f, 5.0f, 1.0f, GOLD); // Draw a yellow wall // Draw some cubes around for (int i = 0; i < MAX_COLUMNS; i++) { - DrawCube(positions[i], 2, heights[i], 2, colors[i]); - DrawCubeWires(positions[i], 2, heights[i], 2, MAROON); + DrawCube(positions[i], 2.0f, heights[i], 2.0f, colors[i]); + DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, MAROON); } End3dMode(); diff --git a/examples/core_3d_camera_free.c b/examples/core_3d_camera_free.c index be44ed2a..df1b480c 100644 --- a/examples/core_3d_camera_free.c +++ b/examples/core_3d_camera_free.c @@ -21,9 +21,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); // Define the camera to look into our 3d world - Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera; + camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; + camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; - Vector3 cubePosition = { 0.0, 0.0, 0.0 }; + Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; SetCameraMode(CAMERA_FREE); // Set a free camera mode SetCameraPosition(camera.position); // Set internal camera position to match our camera position @@ -48,10 +51,10 @@ int main() Begin3dMode(camera); - DrawCube(cubePosition, 2, 2, 2, RED); - DrawCubeWires(cubePosition, 2, 2, 2, MAROON); + DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); + DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); - DrawGrid(10.0, 1.0); + DrawGrid(10, 1.0f); End3dMode(); diff --git a/examples/core_3d_mode.c b/examples/core_3d_mode.c index 3a5fae13..40415fea 100644 --- a/examples/core_3d_mode.c +++ b/examples/core_3d_mode.c @@ -22,11 +22,11 @@ int main() // Define the camera to look into our 3d world Camera camera; - camera.position = (Vector3){ 0.0, 10.0, 10.0 }; - camera.target = (Vector3){ 0.0, 0.0, 0.0 }; - camera.up = (Vector3){ 0.0, 1.0, 0.0 }; + camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; + camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; - Vector3 cubePosition = { 0.0, 0.0, 0.0 }; + Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -47,10 +47,10 @@ int main() Begin3dMode(camera); - DrawCube(cubePosition, 2.0, 2.0, 2.0, RED); - DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON); + DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); + DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); - DrawGrid(10.0, 1.0); + DrawGrid(10, 1.0f); End3dMode(); diff --git a/examples/core_3d_picking.c b/examples/core_3d_picking.c index 0d6f4ac7..9a6cc138 100644 --- a/examples/core_3d_picking.c +++ b/examples/core_3d_picking.c @@ -21,10 +21,10 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking"); // Define the camera to look into our 3d world - Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; - Vector3 cubePosition = { 0.0, 1.0, 0.0 }; - Vector3 cubeSize = { 2.0, 2.0, 2.0 }; + Vector3 cubePosition = { 0.0f, 1.0f, 0.0f }; + Vector3 cubeSize = { 2.0f, 2.0f, 2.0f }; Ray ray; // Picking line ray @@ -50,8 +50,8 @@ int main() // Check collision between ray and box collision = CheckCollisionRayBox(ray, - (Vector3){cubePosition.x - cubeSize.x / 2,cubePosition.y - cubeSize.y / 2,cubePosition.z - cubeSize.z / 2}, - (Vector3){cubePosition.x + cubeSize.x / 2,cubePosition.y + cubeSize.y / 2,cubePosition.z + cubeSize.z / 2}); + (Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 }, + (Vector3){ cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 }); } //---------------------------------------------------------------------------------- @@ -65,10 +65,10 @@ int main() DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY); DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY); - - DrawGrid(10.0, 1.0); DrawRay(ray, MAROON); + + DrawGrid(10, 1.0f); End3dMode(); diff --git a/examples/core_basic_window.c b/examples/core_basic_window.c index b039e53f..fb83400a 100644 --- a/examples/core_basic_window.c +++ b/examples/core_basic_window.c @@ -29,6 +29,8 @@ int main() int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop diff --git a/examples/core_input_gamepad.c b/examples/core_input_gamepad.c index 64be4cd8..1de2d424 100644 --- a/examples/core_input_gamepad.c +++ b/examples/core_input_gamepad.c @@ -23,8 +23,8 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input"); - Vector2 ballPosition = { screenWidth/2, screenHeight/2 }; - Vector2 gamepadMovement = { 0, 0 }; + Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 }; + Vector2 gamepadMovement = { 0.0f, 0.0f }; SetTargetFPS(60); // Set target frames-per-second //-------------------------------------------------------------------------------------- @@ -43,8 +43,8 @@ int main() if (IsGamepadButtonPressed(GAMEPAD_PLAYER1, GAMEPAD_BUTTON_A)) { - ballPosition.x = screenWidth/2; - ballPosition.y = screenHeight/2; + ballPosition.x = (float)screenWidth/2; + ballPosition.y = (float)screenHeight/2; } } //---------------------------------------------------------------------------------- diff --git a/examples/core_input_keys.c b/examples/core_input_keys.c index 99d5e516..b2305246 100644 --- a/examples/core_input_keys.c +++ b/examples/core_input_keys.c @@ -20,7 +20,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input"); - Vector2 ballPosition = { screenWidth/2, screenHeight/2 }; + Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 }; SetTargetFPS(60); // Set target frames-per-second //-------------------------------------------------------------------------------------- @@ -30,10 +30,10 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 0.8; - if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 0.8; - if (IsKeyDown(KEY_UP)) ballPosition.y -= 0.8; - if (IsKeyDown(KEY_DOWN)) ballPosition.y += 0.8; + if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 0.8f; + if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 0.8f; + if (IsKeyDown(KEY_UP)) ballPosition.y -= 0.8f; + if (IsKeyDown(KEY_DOWN)) ballPosition.y += 0.8f; //---------------------------------------------------------------------------------- // Draw diff --git a/examples/core_input_mouse.c b/examples/core_input_mouse.c index c64b421e..358b5fd6 100644 --- a/examples/core_input_mouse.c +++ b/examples/core_input_mouse.c @@ -20,8 +20,9 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input"); - int mouseX, mouseY; - Vector2 ballPosition = { -100.0, -100.0 }; + Vector2 ballPosition = { -100.0f, -100.0f }; + + SetTargetFPS(60); //--------------------------------------------------------------------------------------- // Main game loop @@ -31,11 +32,7 @@ int main() //---------------------------------------------------------------------------------- if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { - mouseX = GetMouseX(); - mouseY = GetMouseY(); - - ballPosition.x = (float)mouseX; - ballPosition.y = (float)mouseY; + ballPosition = GetMousePosition(); } //---------------------------------------------------------------------------------- diff --git a/examples/core_random_values.c b/examples/core_random_values.c index 98e0e91e..06e550dd 100644 --- a/examples/core_random_values.c +++ b/examples/core_random_values.c @@ -22,7 +22,7 @@ int main() int framesCounter = 0; // Variable used to count frames - int randValue = GetRandomValue(-8,5); // Get a random integer number between -8 and 5 (both included) + int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included) SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -37,7 +37,7 @@ int main() // Every two seconds (120 frames) a new random value is generated if (((framesCounter/120)%2) == 1) { - randValue = GetRandomValue(-8,5); + randValue = GetRandomValue(-8, 5); framesCounter = 0; } //---------------------------------------------------------------------------------- diff --git a/examples/core_world_screen.c b/examples/core_world_screen.c index eac5fbdc..b70b40dd 100644 --- a/examples/core_world_screen.c +++ b/examples/core_world_screen.c @@ -21,9 +21,9 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); // Define the camera to look into our 3d world - Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; - Vector3 cubePosition = { 0.0, 0.0, 0.0 }; + Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; Vector2 cubeScreenPosition; @@ -53,10 +53,10 @@ int main() Begin3dMode(camera); - DrawCube(cubePosition, 2, 2, 2, RED); - DrawCubeWires(cubePosition, 2, 2, 2, MAROON); + DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); + DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); - DrawGrid(10.0, 1.0); + DrawGrid(10, 1.0f); End3dMode(); diff --git a/examples/lighting_blinn_phong.c b/examples/lighting_blinn_phong.c index 65dbb4f2..d7683648 100644 --- a/examples/lighting_blinn_phong.c +++ b/examples/lighting_blinn_phong.c @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raylib [lighting] example - Basic Phong lighting +* raylib [shaders] example - Blinn-Phong lighting * * This example has been created using raylib 1.3 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) @@ -22,14 +22,14 @@ int main() const int screenHeight = 450; SetConfigFlags(FLAG_MSAA_4X_HINT); - InitWindow(screenWidth, screenHeight, "raylib [lighting] example - blinn phong lighting"); + InitWindow(screenWidth, screenHeight, "raylib [shaders] example - blinn-phong lighting"); SetTargetFPS(60); // Camera initialization - Camera camera = {{ 10.0, 8.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 8.0f, 8.0f, 8.0f }, { 0.0f, 3.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; // Model initialization - Vector3 position = { 0.0, 0.0, 0.0 }; + Vector3 position = { 0.0f, 0.0f, 0.0f }; Model model = LoadModel("resources/model/dwarf.obj"); Shader shader = LoadShader("resources/shaders/phong.vs", "resources/shaders/phong.fs"); SetModelShader(&model, shader); @@ -54,7 +54,7 @@ int main() Material matBlinn; // Light initialization - light.position = (Vector3){ 5.0f, 1.0f, 1.0f }; + light.position = (Vector3){ 4.0f, 2.0f, 0.0f }; light.direction = (Vector3){ 5.0f, 1.0f, 1.0f }; light.intensity = 1.0f; light.diffuse = WHITE; @@ -129,7 +129,9 @@ int main() Begin3dMode(camera); DrawModel(model, position, 4.0f, matBlinn.diffuse); - DrawSphere(light.position, 1.0f, YELLOW); + DrawSphere(light.position, 0.5f, GOLD); + + DrawGrid(20, 1.0f); End3dMode(); diff --git a/examples/models_billboard.c b/examples/models_billboard.c index e5f6489f..bac42d35 100644 --- a/examples/models_billboard.c +++ b/examples/models_billboard.c @@ -21,10 +21,10 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards"); // Define the camera to look into our 3d world - Camera camera = {{ 5.0, 4.0, 5.0 }, { 0.0, 2.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 5.0f, 4.0f, 5.0f }, { 0.0f, 2.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard - Vector3 billPosition = { 0.0, 2.0, 0.0 }; // Position where draw billboard + Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode SetCameraPosition(camera.position); // Set internal camera position to match our camera position @@ -49,9 +49,9 @@ int main() Begin3dMode(camera); - DrawGrid(10.0, 1.0); // Draw a grid - DrawBillboard(camera, bill, billPosition, 2.0f, WHITE); + + DrawGrid(10, 1.0f); // Draw a grid End3dMode(); diff --git a/examples/models_box_collisions.c b/examples/models_box_collisions.c index 18fca091..3751041f 100644 --- a/examples/models_box_collisions.c +++ b/examples/models_box_collisions.c @@ -21,16 +21,16 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions"); // Define the camera to look into our 3d world - Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; - Vector3 playerPosition = { 0, 1, 2 }; - Vector3 playerSize = { 1, 2, 1 }; + Vector3 playerPosition = { 0.0f, 1.0f, 2.0f }; + Vector3 playerSize = { 1.0f, 2.0f, 1.0f }; Color playerColor = GREEN; - Vector3 enemyBoxPos = { -4, 1, 0 }; - Vector3 enemyBoxSize = { 2, 2, 2 }; + Vector3 enemyBoxPos = { -4.0f, 1.0f, 0.0f }; + Vector3 enemyBoxSize = { 2.0f, 2.0f, 2.0f }; - Vector3 enemySpherePos = { 4, 0, 0 }; + Vector3 enemySpherePos = { 4.0f, 0.0f, 0.0f }; float enemySphereSize = 1.5f; bool collision = false; @@ -98,7 +98,7 @@ int main() // Draw player DrawCubeV(playerPosition, playerSize, playerColor); - DrawGrid(10.0, 1.0); // Draw a grid + DrawGrid(10, 1.0f); // Draw a grid End3dMode(); diff --git a/examples/models_cubicmap.c b/examples/models_cubicmap.c index 98fc54af..e2a902ef 100644 --- a/examples/models_cubicmap.c +++ b/examples/models_cubicmap.c @@ -21,7 +21,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing"); // Define the camera to look into our 3d world - Camera camera = {{ 16.0, 14.0, 16.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM) @@ -31,7 +31,7 @@ int main() Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture SetModelTexture(&map, texture); // Bind texture to map model - Vector3 mapPosition = { -16, 0.0, -8 }; // Set model position + Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM diff --git a/examples/models_geometric_shapes.c b/examples/models_geometric_shapes.c index e2d41dcd..9ea5b423 100644 --- a/examples/models_geometric_shapes.c +++ b/examples/models_geometric_shapes.c @@ -21,7 +21,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes"); // Define the camera to look into our 3d world - Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -42,21 +42,21 @@ int main() Begin3dMode(camera); - DrawCube((Vector3){-4, 0, 2}, 2, 5, 2, RED); - DrawCubeWires((Vector3){-4, 0, 2}, 2, 5, 2, GOLD); - DrawCubeWires((Vector3){-4, 0, -2}, 3, 6, 2, MAROON); + DrawCube((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, RED); + DrawCubeWires((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, GOLD); + DrawCubeWires((Vector3){-4.0f, 0.0f, -2.0f}, 3.0f, 6.0f, 2.0f, MAROON); - DrawSphere((Vector3){-1, 0, -2}, 1, GREEN); - DrawSphereWires((Vector3){1, 0, 2}, 2, 16, 16, LIME); + DrawSphere((Vector3){-1.0f, 0.0f, -2.0f}, 1.0f, GREEN); + DrawSphereWires((Vector3){1.0f, 0.0f, 2.0f}, 2.0f, 16, 16, LIME); - DrawCylinder((Vector3){4, 0, -2}, 1, 2, 3, 4, SKYBLUE); - DrawCylinderWires((Vector3){4, 0, -2}, 1, 2, 3, 4, DARKBLUE); - DrawCylinderWires((Vector3){4.5, -1, 2}, 1, 1, 2, 6, BROWN); + DrawCylinder((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, SKYBLUE); + DrawCylinderWires((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, DARKBLUE); + DrawCylinderWires((Vector3){4.5f, -1.0f, 2.0f}, 1.0f, 1.0f, 2.0f, 6, BROWN); - DrawCylinder((Vector3){1, 0, -4}, 0, 1.5, 3, 8, GOLD); - DrawCylinderWires((Vector3){1, 0, -4}, 0, 1.5, 3, 8, PINK); + DrawCylinder((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, GOLD); + DrawCylinderWires((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, PINK); - DrawGrid(10.0, 1.0); // Draw a grid + DrawGrid(10, 1.0f); // Draw a grid End3dMode(); diff --git a/examples/models_heightmap.c b/examples/models_heightmap.c index fec3f5e6..ac578c61 100644 --- a/examples/models_heightmap.c +++ b/examples/models_heightmap.c @@ -21,13 +21,13 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing"); // Define our custom camera to look into our 3d world - Camera camera = {{ 24.0, 18.0, 24.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 24.0f, 18.0f, 24.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM) Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM) Model map = LoadHeightmap(image, 32); // Load heightmap model SetModelTexture(&map, texture); // Bind texture to model - Vector3 mapPosition = { -16, 0.0, -16 }; // Set model position (depends on model scaling!) + Vector3 mapPosition = { -16.0f, 0.0f, -16.0f }; // Set model position (depends on model scaling!) UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM diff --git a/examples/models_obj_loading.c b/examples/models_obj_loading.c index dc302f99..41f4569a 100644 --- a/examples/models_obj_loading.c +++ b/examples/models_obj_loading.c @@ -21,12 +21,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading"); // Define the camera to look into our 3d world - Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture - SetModelTexture(&dwarf, texture); // Bind texture to model - Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position + SetModelTexture(&dwarf, texture); // Bind texture to model + Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -49,7 +49,7 @@ int main() DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture - DrawGrid(10.0, 1.0); // Draw a grid + DrawGrid(10, 1.0f); // Draw a grid DrawGizmo(position); // Draw gizmo diff --git a/examples/resources/shaders/phong.fs b/examples/resources/shaders/phong.fs index 75b7e6d7..f79413d9 100644 --- a/examples/resources/shaders/phong.fs +++ b/examples/resources/shaders/phong.fs @@ -9,16 +9,16 @@ uniform sampler2D texture0; uniform vec4 fragTintColor; // Light attributes -uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0); -uniform vec3 light_diffuseColor = vec3(1, 0.5, 0); -uniform vec3 light_specularColor = vec3(0, 1, 0); -uniform float light_intensity = 1; -uniform float light_specIntensity = 1; +uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0.0); +uniform vec3 light_diffuseColor = vec3(1.0, 0.5, 0.0); +uniform vec3 light_specularColor = vec3(0.0, 1.0, 0.0); +uniform float light_intensity = 1.0; +uniform float light_specIntensity = 1.0; // Material attributes -uniform vec3 mat_ambientColor = vec3(1, 1, 1); -uniform vec3 mat_specularColor = vec3(1, 1, 1); -uniform float mat_glossiness = 50; +uniform vec3 mat_ambientColor = vec3(1.0, 1.0, 1.0); +uniform vec3 mat_specularColor = vec3(1.0, 1.0, 1.0); +uniform float mat_glossiness = 50.0; // World attributes uniform vec3 lightPos; @@ -29,7 +29,7 @@ out vec4 fragColor; vec3 AmbientLighting() { - return mat_ambientColor * light_ambientColor; + return (mat_ambientColor*light_ambientColor); } vec3 DiffuseLighting(in vec3 N, in vec3 L) @@ -37,15 +37,15 @@ vec3 DiffuseLighting(in vec3 N, in vec3 L) // Lambertian reflection calculation float diffuse = clamp(dot(N, L), 0, 1); - return tintColor.xyz * light_diffuseColor * light_intensity * diffuse; + return (fragTintColor.xyz*light_diffuseColor*light_intensity*diffuse); } vec3 SpecularLighting(in vec3 N, in vec3 L, in vec3 V) { - float specular = 0; + float specular = 0.0; // Calculate specular reflection only if the surface is oriented to the light source - if(dot(N, L) > 0) + if (dot(N, L) > 0) { // Calculate half vector vec3 H = normalize(L + V); @@ -54,7 +54,7 @@ vec3 SpecularLighting(in vec3 N, in vec3 L, in vec3 V) specular = pow(dot(N, H), 3 + mat_glossiness); } - return mat_specularColor * light_specularColor * light_specIntensity * specular; + return (mat_specularColor*light_specularColor*light_specIntensity*specular); } void main() diff --git a/examples/resources/shaders/phong.vs b/examples/resources/shaders/phong.vs index c6ef77de..ee6d34bf 100644 --- a/examples/resources/shaders/phong.vs +++ b/examples/resources/shaders/phong.vs @@ -7,7 +7,6 @@ in vec3 vertexNormal; // Projection and model data uniform mat4 mvpMatrix; - uniform mat4 modelMatrix; // Attributes to fragment shader @@ -21,8 +20,8 @@ void main() // Calculate view vector normal from model mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); - fragNormal = normalize(normalMatrix * vertexNormal); + fragNormal = normalize(normalMatrix*vertexNormal); // Calculate final vertex position - gl_Position = projectionMatrix * modelviewMatrix * vec4(vertexPosition, 1.0); + gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); } \ No newline at end of file diff --git a/examples/resources/shaders/swirl.fs b/examples/resources/shaders/swirl.fs index ace6e79d..f89ef406 100644 --- a/examples/resources/shaders/swirl.fs +++ b/examples/resources/shaders/swirl.fs @@ -9,13 +9,13 @@ uniform vec4 fragTintColor; // NOTE: Add here your custom variables -const float renderWidth = 800; // HARDCODED for example! -const float renderHeight = 480; // Use uniforms instead... +const float renderWidth = 800.0; // HARDCODED for example! +const float renderHeight = 480.0; // Use uniforms instead... float radius = 250.0; float angle = 0.8; -uniform vec2 center = vec2(200, 200); +uniform vec2 center = vec2(200.0, 200.0); void main (void) { diff --git a/examples/shaders_custom_uniform.c b/examples/shaders_custom_uniform.c index 59350d35..0377cfff 100644 --- a/examples/shaders_custom_uniform.c +++ b/examples/shaders_custom_uniform.c @@ -30,13 +30,13 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable"); // Define the camera to look into our 3d world - Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture SetModelTexture(&dwarf, texture); // Bind texture to model - Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position + Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position Shader shader = LoadShader("resources/shaders/base.vs", "resources/shaders/swirl.fs"); // Load postpro shader @@ -45,7 +45,7 @@ int main() // NOTE: If uniform variable could not be found in the shader, function returns -1 int swirlCenterLoc = GetShaderLocation(shader, "center"); - float swirlCenter[2] = { screenWidth/2, screenHeight/2 }; + float swirlCenter[2] = { (float)screenWidth/2, (float)screenHeight/2 }; SetPostproShader(shader); // Set fullscreen postprocessing shader @@ -83,7 +83,7 @@ int main() DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture - DrawGrid(10.0, 1.0); // Draw a grid + DrawGrid(10, 1.0f); // Draw a grid End3dMode(); diff --git a/examples/shaders_model_shader.c b/examples/shaders_model_shader.c index 8ea390e5..5d8c3711 100644 --- a/examples/shaders_model_shader.c +++ b/examples/shaders_model_shader.c @@ -30,7 +30,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader"); // Define the camera to look into our 3d world - Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture @@ -40,7 +40,7 @@ int main() SetModelShader(&dwarf, shader); // Set shader effect to 3d model SetModelTexture(&dwarf, texture); // Bind texture to model - Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position + Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position // Setup orbital camera SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode @@ -68,7 +68,7 @@ int main() DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture - DrawGrid(10.0, 1.0); // Draw a grid + DrawGrid(10, 1.0f); // Draw a grid End3dMode(); diff --git a/examples/shaders_postprocessing.c b/examples/shaders_postprocessing.c index 5d7c1f61..0f851658 100644 --- a/examples/shaders_postprocessing.c +++ b/examples/shaders_postprocessing.c @@ -30,13 +30,13 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader"); // Define the camera to look into our 3d world - Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture SetModelTexture(&dwarf, texture); // Bind texture to model - Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position + Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position Shader shader = LoadShader("resources/shaders/base.vs", "resources/shaders/bloom.fs"); // Load postpro shader @@ -69,7 +69,7 @@ int main() DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture - DrawGrid(10.0, 1.0); // Draw a grid + DrawGrid(10, 1.0f); // Draw a grid End3dMode(); diff --git a/examples/shapes_basic_shapes.c b/examples/shapes_basic_shapes.c index 4b14af89..6b2719fc 100644 --- a/examples/shapes_basic_shapes.c +++ b/examples/shapes_basic_shapes.c @@ -19,6 +19,8 @@ int main() int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing"); + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop diff --git a/examples/shapes_colors_palette.c b/examples/shapes_colors_palette.c index 3e161114..dcab862e 100644 --- a/examples/shapes_colors_palette.c +++ b/examples/shapes_colors_palette.c @@ -19,6 +19,8 @@ int main() int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette"); + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop diff --git a/examples/shapes_logo_raylib.c b/examples/shapes_logo_raylib.c index 3dd8fbf3..be94988c 100644 --- a/examples/shapes_logo_raylib.c +++ b/examples/shapes_logo_raylib.c @@ -19,6 +19,8 @@ int main() int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes"); + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop diff --git a/examples/shapes_logo_raylib_anim.c b/examples/shapes_logo_raylib_anim.c index d0831378..b1bdc3a8 100644 --- a/examples/shapes_logo_raylib_anim.c +++ b/examples/shapes_logo_raylib_anim.c @@ -35,9 +35,7 @@ int main() char raylib[8] = " \0"; // raylib text array, max 8 letters int state = 0; // Tracking animation states (State Machine) - - float alpha = 1.0; // Useful for fading - + float alpha = 1.0f; // Useful for fading SetTargetFPS(60); //-------------------------------------------------------------------------------------- diff --git a/examples/textures_logo_raylib.c b/examples/textures_logo_raylib.c index 2ebf0867..f2f93128 100644 --- a/examples/textures_logo_raylib.c +++ b/examples/textures_logo_raylib.c @@ -38,8 +38,7 @@ int main() ClearBackground(RAYWHITE); - DrawTexture(texture, screenWidth/2 - texture.width/2, - screenHeight/2 - texture.height/2, WHITE); + DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); DrawText("this IS a texture!", 360, 370, 10, GRAY); diff --git a/examples/textures_particles_trail_blending.c b/examples/textures_particles_trail_blending.c index da01f863..76cd0423 100644 --- a/examples/textures_particles_trail_blending.c +++ b/examples/textures_particles_trail_blending.c @@ -41,12 +41,12 @@ int main() mouseTail[i].position = (Vector2){ 0, 0 }; mouseTail[i].color = (Color){ GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 }; mouseTail[i].alpha = 1.0f; - mouseTail[i].size = (float)GetRandomValue(1, 30)/20; + mouseTail[i].size = (float)GetRandomValue(1, 30)/20.0f; mouseTail[i].rotation = GetRandomValue(0, 360); mouseTail[i].active = false; } - float gravity = 3; + float gravity = 3.0f; Texture2D smoke = LoadTexture("resources/smoke.png"); @@ -85,7 +85,7 @@ int main() if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false; - mouseTail[i].rotation += 5; + mouseTail[i].rotation += 5.0f; } } -- cgit v1.2.3 From d0ff78e7f41be9884e786026ddd22ed53fc0943f Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 25 Jan 2016 13:39:23 +0100 Subject: Move Light struct to example --- examples/resources/shaders/phong.vs | 2 ++ examples/shaders_basic_lighting.c | 19 +++++++++++++++++++ src/core.c | 6 ++++++ src/rlgl.h | 3 --- 4 files changed, 27 insertions(+), 3 deletions(-) (limited to 'examples/resources/shaders') 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)) diff --git a/src/core.c b/src/core.c index 811f082a..df380552 100644 --- a/src/core.c +++ b/src/core.c @@ -938,6 +938,12 @@ Vector2 WorldToScreen(Vector3 position, Camera camera) 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 //---------------------------------------------------------------------------------- diff --git a/src/rlgl.h b/src/rlgl.h index 76cae987..64581db8 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -167,9 +167,6 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion; // Uniforms 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 mapDiffuseLoc; // Diffuse map texture uniform location point (fragment shader) -- cgit v1.2.3 From db5493b783fbdfd95813bc0c9ab253e3fd421e02 Mon Sep 17 00:00:00 2001 From: Constantine Tarasenkov Date: Fri, 29 Jan 2016 03:47:43 +0300 Subject: Fix shader versions --- examples/resources/shaders/shapes_base.vs | 2 +- examples/resources/shaders/shapes_grayscale.fs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/resources/shaders') diff --git a/examples/resources/shaders/shapes_base.vs b/examples/resources/shaders/shapes_base.vs index 1fd686be..ad272dc1 100644 --- a/examples/resources/shaders/shapes_base.vs +++ b/examples/resources/shaders/shapes_base.vs @@ -1,4 +1,4 @@ -#version 110 +#version 330 attribute vec3 vertexPosition; attribute vec2 vertexTexCoord; diff --git a/examples/resources/shaders/shapes_grayscale.fs b/examples/resources/shaders/shapes_grayscale.fs index 23ba9153..0698e1bf 100644 --- a/examples/resources/shaders/shapes_grayscale.fs +++ b/examples/resources/shaders/shapes_grayscale.fs @@ -1,4 +1,4 @@ -#version 110 +#version 330 uniform sampler2D texture0; varying vec2 fragTexCoord; -- cgit v1.2.3