Watch
2
0
Fork
You've already forked raylib-cs
0
raylib-cs/Examples/resources/shaders/glsl100/voxel_lighting.fs
Dennis Steffen 21d83c60a9
Upgrade Raylib to 6.0 (#337)
* Updated target to Raylib 6 + synced invoke called with the changes in C. [WARNING: Breaking changes!]

* Added severial examples. Corrected towards the correct return type and add utilities to prevent working with pointers

* Additional resources from the Raylib repo.

* Fixed additional pinvokes to match with the new raylib bindings. [Warning breaking changes!]

* Fixing the QOL utils

* Fixing the Mesh struct

* Applying changes after review. Merged resources.LICENSE + raylib-cs.Native.csproj only targets dotnet8

* Updated README to reflect .NET 10 and Raylib 6 compatibility changes.

* Updated shader colors, adjusted car model scale, disabled HDR in SkyboxDemo, and fixed camera mode assignment. Removed unused `Capacity` field in FilePathList struct.

* Improved XML comments for consistency, fixed spacing and formatting across examples, added new resources to `resources.LICENSE`.

* Updated XML comment for `GetDirectoryFileCountEx` to clarify behavior and filtering options.

* Updated and clarified XML comments for methods and parameters, improved naming consistency, and refined shader-related functions. Renamed enums in `Shader.cs` for so it is inline with the upstream.

* Improved XML comments for clarity and consistency in `Model.cs` and `Mesh.cs`, updated method and variable names for better readability, and adjusted logic in span creation methods.

* Corrected XML comment capitalization in `Model.cs`.

---------

Co-authored-by: Meatcorps <info@meatcorps.nl>
2026-05-24 07:21:12 +01:00

65 lines
1.5 KiB
GLSL

#version 100
precision mediump float;
// 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;
}