Watch
2
0
Fork
You've already forked raylib-cs
0
raylib-cs/Examples/resources/shaders/glsl120/normalmap.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

62 lines
1.7 KiB
GLSL

#version 120
// Input vertex attributes (from vertex shader)
varying vec3 fragPosition;
varying vec2 fragTexCoord;
varying vec3 fragNormal; //used for when normal mapping is toggled off
varying vec4 fragColor;
varying mat3 TBN;
// Input uniform values
uniform sampler2D texture0;
uniform sampler2D normalMap;
uniform vec4 colDiffuse;
uniform vec3 viewPos;
// NOTE: Add your custom variables here
uniform vec3 lightPos;
uniform bool useNormalMap;
uniform float specularExponent;
void main()
{
vec4 texelColor = texture(texture0, vec2(fragTexCoord.x, fragTexCoord.y));
vec3 specular = vec3(0.0);
vec3 viewDir = normalize(viewPos - fragPosition);
vec3 lightDir = normalize(lightPos - fragPosition);
vec3 normal;
if (useNormalMap)
{
normal = texture(normalMap, vec2(fragTexCoord.x, fragTexCoord.y)).rgb;
//Transform normal values to the range -1.0 ... 1.0
normal = normalize(normal*2.0 - 1.0);
//Transform the normal from tangent-space to world-space for lighting calculation
normal = normalize(normal*TBN);
}
else
{
normal = normalize(fragNormal);
}
vec4 tint = colDiffuse*fragColor;
vec3 lightColor = vec3(1.0, 1.0, 1.0);
float NdotL = max(dot(normal, lightDir), 0.0);
vec3 lightDot = lightColor*NdotL;
float specCo = 0.0;
if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewDir, reflect(-lightDir, normal))), specularExponent);
specular += specCo;
finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
finalColor += texelColor*(vec4(1.0, 1.0, 1.0, 1.0)/40.0)*tint;
// Gamma correction
gl_FragColor = pow(finalColor, vec4(1.0/2.2));
}