mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-06 11:28:17 +00:00
add missing shaders
This commit is contained in:
65
examples/models/resources/shaders/glsl100/voxel_lighting.fs
Normal file
65
examples/models/resources/shaders/glsl100/voxel_lighting.fs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#ifdef GL_ES
|
||||||
|
precision mediump float;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Input from vertex shader
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
// Uniforms
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
uniform vec4 ambient;
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
|
||||||
|
#define MAX_LIGHTS 4
|
||||||
|
#define LIGHT_DIRECTIONAL 0
|
||||||
|
#define LIGHT_POINT 1
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
int enabled;
|
||||||
|
int type;
|
||||||
|
vec3 position;
|
||||||
|
vec3 target;
|
||||||
|
vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform Light lights[MAX_LIGHTS];
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 lightDot = vec3(0.0);
|
||||||
|
vec3 normal = normalize(fragNormal);
|
||||||
|
vec3 viewD = normalize(viewPos - fragPosition);
|
||||||
|
vec3 specular = vec3(0.0);
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||||
|
{
|
||||||
|
if (lights[i].enabled == 1)
|
||||||
|
{
|
||||||
|
vec3 light = vec3(0.0);
|
||||||
|
|
||||||
|
if (lights[i].type == LIGHT_DIRECTIONAL)
|
||||||
|
light = -normalize(lights[i].target - lights[i].position);
|
||||||
|
|
||||||
|
if (lights[i].type == LIGHT_POINT)
|
||||||
|
light = normalize(lights[i].position - fragPosition);
|
||||||
|
|
||||||
|
float NdotL = max(dot(normal, light), 0.0);
|
||||||
|
lightDot += lights[i].color.rgb * NdotL;
|
||||||
|
|
||||||
|
if (NdotL > 0.0)
|
||||||
|
{
|
||||||
|
float specCo = pow(max(0.0, dot(viewD, reflect(-light, normal))), 16.0);
|
||||||
|
specular += specCo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 finalColor = (fragColor * ((colDiffuse + vec4(specular, 1.0)) * vec4(lightDot, 1.0)));
|
||||||
|
finalColor += fragColor * (ambient / 10.0) * colDiffuse;
|
||||||
|
|
||||||
|
finalColor = pow(finalColor, vec4(1.0/2.2)); // gamma correction
|
||||||
|
|
||||||
|
gl_FragColor = finalColor;
|
||||||
|
}
|
28
examples/models/resources/shaders/glsl100/voxel_lighting.vs
Normal file
28
examples/models/resources/shaders/glsl100/voxel_lighting.vs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#ifdef GL_ES
|
||||||
|
precision mediump float;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Input vertex attributes
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
attribute vec3 vertexNormal;
|
||||||
|
attribute vec4 vertexColor;
|
||||||
|
// attribute vec2 vertexTexCoord;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 matModel;
|
||||||
|
uniform mat4 matNormal;
|
||||||
|
|
||||||
|
// Output to fragment shader
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
|
||||||
|
fragColor = vertexColor;
|
||||||
|
fragNormal = normalize(vec3(matNormal * vec4(vertexNormal, 1.0)));
|
||||||
|
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
61
examples/models/resources/shaders/glsl120/voxel_lighting.fs
Normal file
61
examples/models/resources/shaders/glsl120/voxel_lighting.fs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
// Input from vertex shader
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
// Uniforms
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
uniform vec4 ambient;
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
|
||||||
|
#define MAX_LIGHTS 4
|
||||||
|
#define LIGHT_DIRECTIONAL 0
|
||||||
|
#define LIGHT_POINT 1
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
int enabled;
|
||||||
|
int type;
|
||||||
|
vec3 position;
|
||||||
|
vec3 target;
|
||||||
|
vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform Light lights[MAX_LIGHTS];
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 lightDot = vec3(0.0);
|
||||||
|
vec3 normal = normalize(fragNormal);
|
||||||
|
vec3 viewD = normalize(viewPos - fragPosition);
|
||||||
|
vec3 specular = vec3(0.0);
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||||
|
{
|
||||||
|
if (lights[i].enabled == 1)
|
||||||
|
{
|
||||||
|
vec3 light = vec3(0.0);
|
||||||
|
|
||||||
|
if (lights[i].type == LIGHT_DIRECTIONAL)
|
||||||
|
light = -normalize(lights[i].target - lights[i].position);
|
||||||
|
|
||||||
|
if (lights[i].type == LIGHT_POINT)
|
||||||
|
light = normalize(lights[i].position - fragPosition);
|
||||||
|
|
||||||
|
float NdotL = max(dot(normal, light), 0.0);
|
||||||
|
lightDot += lights[i].color.rgb * NdotL;
|
||||||
|
|
||||||
|
if (NdotL > 0.0)
|
||||||
|
{
|
||||||
|
float specCo = pow(max(0.0, dot(viewD, reflect(-light, normal))), 16.0);
|
||||||
|
specular += specCo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 finalColor = (fragColor * ((colDiffuse + vec4(specular, 1.0)) * vec4(lightDot, 1.0)));
|
||||||
|
finalColor += fragColor * (ambient / 10.0) * colDiffuse;
|
||||||
|
|
||||||
|
finalColor = pow(finalColor, vec4(1.0/2.2)); // gamma correction
|
||||||
|
|
||||||
|
gl_FragColor = finalColor;
|
||||||
|
}
|
23
examples/models/resources/shaders/glsl120/voxel_lighting.vs
Normal file
23
examples/models/resources/shaders/glsl120/voxel_lighting.vs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// Input vertex attributes
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
attribute vec3 vertexNormal;
|
||||||
|
attribute vec4 vertexColor;
|
||||||
|
|
||||||
|
// Uniforms
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 matModel;
|
||||||
|
uniform mat4 matNormal;
|
||||||
|
|
||||||
|
// Output to fragment shader
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
|
||||||
|
fragColor = vertexColor;
|
||||||
|
fragNormal = normalize(vec3(matNormal * vec4(vertexNormal, 1.0)));
|
||||||
|
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
Reference in New Issue
Block a user