mirror of
				https://github.com/raysan5/raylib.git
				synced 2025-10-26 12:27:01 +00:00 
			
		
		
		
	Reviewed shaders and added comments
This commit is contained in:
		| @@ -1,43 +0,0 @@ | ||||
| #version 330 | ||||
|  | ||||
| in vec2 fragTexCoord; | ||||
| in vec4 fragTintColor; | ||||
|  | ||||
| out vec4 fragColor; | ||||
|  | ||||
| uniform sampler2D texture0; | ||||
| //uniform vec4 fragTintColor; | ||||
|  | ||||
| // NOTE: Add here your custom variables | ||||
|  | ||||
| void main() | ||||
| { | ||||
|     vec4 sum = vec4(0); | ||||
|     vec4 tc = vec4(0); | ||||
|  | ||||
|     for (int i = -4; i < 4; i++) | ||||
|     { | ||||
|         for (int j = -3; j < 3; j++) | ||||
|         { | ||||
|             sum += texture2D(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25; | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     if (texture2D(texture0, fragTexCoord).r < 0.3) | ||||
|     { | ||||
|         tc = sum*sum*0.012 + texture2D(texture0, fragTexCoord); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         if (texture2D(texture0, fragTexCoord).r < 0.5) | ||||
|         { | ||||
|             tc = sum*sum*0.009 + texture2D(texture0, fragTexCoord); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             tc = sum*sum*0.0075 + texture2D(texture0, fragTexCoord); | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     fragColor = tc; | ||||
| } | ||||
							
								
								
									
										26
									
								
								examples/resources/shaders/glsl100/base.vs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								examples/resources/shaders/glsl100/base.vs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| #version 100 | ||||
|  | ||||
| // Input vertex attributes | ||||
| attribute vec3 vertexPosition; | ||||
| attribute vec2 vertexTexCoord; | ||||
| attribute vec3 vertexNormal; | ||||
| attribute vec4 vertexColor; | ||||
|  | ||||
| // Input uniform values | ||||
| uniform mat4 mvpMatrix; | ||||
|  | ||||
| // Output vertex attributes (to fragment shader) | ||||
| varying vec2 fragTexCoord; | ||||
| varying vec4 fragColor; | ||||
|  | ||||
| // NOTE: Add here your custom variables  | ||||
|  | ||||
| void main() | ||||
| { | ||||
|     // Send vertex attributes to fragment shader | ||||
|     fragTexCoord = vertexTexCoord; | ||||
|     fragColor = vertexColor; | ||||
|      | ||||
|     // Calculate final vertex position | ||||
|     gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); | ||||
| } | ||||
							
								
								
									
										37
									
								
								examples/resources/shaders/glsl100/bloom.fs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								examples/resources/shaders/glsl100/bloom.fs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| #version 100 | ||||
|  | ||||
| precision mediump float; | ||||
|  | ||||
| // Input vertex attributes (from vertex shader) | ||||
| varying vec2 fragTexCoord; | ||||
| varying vec4 fragColor; | ||||
|  | ||||
| // Input uniform values | ||||
| uniform sampler2D texture0; | ||||
| uniform vec4 fragTintColor; | ||||
|  | ||||
| // NOTE: Add here your custom variables | ||||
|  | ||||
| void main() | ||||
| { | ||||
|     vec4 sum = vec4(0); | ||||
|     vec4 tc = vec4(0); | ||||
|  | ||||
|     for (int i = -4; i < 4; i++) | ||||
|     { | ||||
|         for (int j = -3; j < 3; j++) | ||||
|         { | ||||
|             sum += texture2D(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25; | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     // Texel color fetching from texture sampler | ||||
|     vec4 texelColor = texture(texture0, fragTexCoord); | ||||
|      | ||||
|     // Calculate final fragment color | ||||
|     if (texelColor.r < 0.3) tc = sum*sum*0.012 + texelColor; | ||||
|     else if (texelColor.r < 0.5) tc = sum*sum*0.009 + texelColor; | ||||
|     else tc = sum*sum*0.0075 + texelColor; | ||||
|      | ||||
|     finalColor = tc; | ||||
| } | ||||
							
								
								
									
										25
									
								
								examples/resources/shaders/glsl100/grayscale.fs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								examples/resources/shaders/glsl100/grayscale.fs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| #version 100 | ||||
|  | ||||
| precision mediump float; | ||||
|  | ||||
| // Input vertex attributes (from vertex shader) | ||||
| varying vec2 fragTexCoord; | ||||
| varying vec4 fragColor; | ||||
|  | ||||
| // Input uniform values | ||||
| uniform sampler2D texture0; | ||||
| uniform vec4 fragTintColor; | ||||
|  | ||||
| // NOTE: Add here your custom variables | ||||
|  | ||||
| void main() | ||||
| { | ||||
|     // Texel color fetching from texture sampler | ||||
|     vec4 texelColor = texture(texture0, fragTexCoord)*fragTintColor*fragColor; | ||||
|      | ||||
|     // Convert texel color to grayscale using NTSC conversion weights | ||||
|     float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); | ||||
|      | ||||
|     // Calculate final fragment color | ||||
|     gl_FragColor = vec4(gray, gray, gray, texelColor.a); | ||||
| } | ||||
							
								
								
									
										45
									
								
								examples/resources/shaders/glsl100/swirl.fs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								examples/resources/shaders/glsl100/swirl.fs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| #version 100 | ||||
|  | ||||
| precision mediump float; | ||||
|  | ||||
| // Input vertex attributes (from vertex shader) | ||||
| varying vec2 fragTexCoord; | ||||
| varying vec4 fragColor; | ||||
|  | ||||
| // Input uniform values | ||||
| uniform sampler2D texture0; | ||||
| uniform vec4 fragTintColor; | ||||
|  | ||||
| // NOTE: Add here your custom variables | ||||
|  | ||||
| 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.0, 200.0); | ||||
|  | ||||
| void main (void) | ||||
| { | ||||
|     vec2 texSize = vec2(renderWidth, renderHeight); | ||||
|     vec2 tc = fragTexCoord*texSize; | ||||
|     tc -= center; | ||||
|      | ||||
|     float dist = length(tc); | ||||
|  | ||||
|     if (dist < radius)  | ||||
|     { | ||||
|         float percent = (radius - dist)/radius; | ||||
|         float theta = percent*percent*angle*8.0; | ||||
|         float s = sin(theta); | ||||
|         float c = cos(theta); | ||||
|          | ||||
|         tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c))); | ||||
|     } | ||||
|  | ||||
|     tc += center; | ||||
|     vec3 color = texture2D(texture0, tc/texSize).rgb; | ||||
|  | ||||
|     gl_FragColor = vec4(color, 1.0);; | ||||
| } | ||||
| @@ -1,21 +1,26 @@ | ||||
| #version 330 | ||||
| 
 | ||||
| // Input vertex attributes | ||||
| in vec3 vertexPosition; | ||||
| in vec2 vertexTexCoord; | ||||
| in vec3 vertexNormal; | ||||
| in vec4 vertexColor; | ||||
| 
 | ||||
| out vec2 fragTexCoord; | ||||
| out vec4 fragTintColor; | ||||
| 
 | ||||
| // Input uniform values | ||||
| uniform mat4 mvpMatrix; | ||||
| 
 | ||||
| // Output vertex attributes (to fragment shader) | ||||
| out vec2 fragTexCoord; | ||||
| out vec4 fragColor; | ||||
| 
 | ||||
| // NOTE: Add here your custom variables  | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     // Send vertex attributes to fragment shader | ||||
|     fragTexCoord = vertexTexCoord; | ||||
|     fragTintColor = vertexColor; | ||||
|     fragColor = vertexColor; | ||||
|      | ||||
|     // Calculate final vertex position | ||||
|     gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); | ||||
| } | ||||
							
								
								
									
										38
									
								
								examples/resources/shaders/glsl330/bloom.fs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								examples/resources/shaders/glsl330/bloom.fs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| #version 330 | ||||
|  | ||||
| // Input vertex attributes (from vertex shader) | ||||
| in vec2 fragTexCoord; | ||||
| in vec4 fragColor; | ||||
|  | ||||
| // Input uniform values | ||||
| uniform sampler2D texture0; | ||||
| uniform vec4 fragTintColor; | ||||
|  | ||||
| // Output fragment color | ||||
| out vec4 finalColor; | ||||
|  | ||||
| // NOTE: Add here your custom variables | ||||
|  | ||||
| void main() | ||||
| { | ||||
|     vec4 sum = vec4(0); | ||||
|     vec4 tc = vec4(0); | ||||
|      | ||||
|     for (int i = -4; i < 4; i++) | ||||
|     { | ||||
|         for (int j = -3; j < 3; j++) | ||||
|         { | ||||
|             sum += texture2D(texture0, fragTexCoord + vec2(j, i)*0.004)*0.25; | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     // Texel color fetching from texture sampler | ||||
|     vec4 texelColor = texture(texture0, fragTexCoord); | ||||
|      | ||||
|     // Calculate final fragment color | ||||
|     if (texelColor.r < 0.3) tc = sum*sum*0.012 + texelColor; | ||||
|     else if (texelColor.r < 0.5) tc = sum*sum*0.009 + texelColor; | ||||
|     else tc = sum*sum*0.0075 + texelColor; | ||||
|  | ||||
|     finalColor = tc; | ||||
| } | ||||
							
								
								
									
										26
									
								
								examples/resources/shaders/glsl330/grayscale.fs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								examples/resources/shaders/glsl330/grayscale.fs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| #version 330 | ||||
|  | ||||
| // Input vertex attributes (from vertex shader) | ||||
| in vec2 fragTexCoord; | ||||
| in vec4 fragColor; | ||||
|  | ||||
| // Input uniform values | ||||
| uniform sampler2D texture0; | ||||
| uniform vec4 fragTintColor; | ||||
|  | ||||
| // Output fragment color | ||||
| out vec4 finalColor; | ||||
|  | ||||
| // NOTE: Add here your custom variables | ||||
|  | ||||
| void main() | ||||
| { | ||||
|     // Texel color fetching from texture sampler | ||||
|     vec4 texelColor = texture(texture0, fragTexCoord)*fragTintColor*fragColor; | ||||
|      | ||||
|     // Convert texel color to grayscale using NTSC conversion weights | ||||
|     float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); | ||||
|      | ||||
|     // Calculate final fragment color | ||||
|     finalColor = vec4(gray, gray, gray, texelColor.a); | ||||
| } | ||||
| @@ -1,6 +1,6 @@ | ||||
| #version 330 | ||||
| 
 | ||||
| // Vertex shader input data | ||||
| // Input vertex attributes (from vertex shader) | ||||
| in vec2 fragTexCoord; | ||||
| in vec3 fragNormal; | ||||
| 
 | ||||
| @@ -1,25 +1,25 @@ | ||||
| #version 330 | ||||
| 
 | ||||
| // Vertex input data | ||||
| // Input vertex attributes | ||||
| in vec3 vertexPosition; | ||||
| in vec2 vertexTexCoord; | ||||
| in vec3 vertexNormal; | ||||
| 
 | ||||
| // Projection and model data | ||||
| // Input uniform values | ||||
| uniform mat4 mvpMatrix; | ||||
| 
 | ||||
| uniform mat4 modelMatrix; | ||||
| //uniform mat4 viewMatrix;  // Not used | ||||
| 
 | ||||
| // Attributes to fragment shader | ||||
| // Output vertex attributes (to fragment shader) | ||||
| out vec2 fragTexCoord; | ||||
| out vec3 fragNormal; | ||||
| 
 | ||||
| // NOTE: Add here your custom variables | ||||
| uniform mat4 modelMatrix; | ||||
| 
 | ||||
| void main() | ||||
| { | ||||
|     // Send texture coord to fragment shader | ||||
|     // Send vertex attributes to fragment shader | ||||
|     fragTexCoord = vertexTexCoord; | ||||
|      | ||||
| 
 | ||||
|     // Calculate view vector normal from model | ||||
|     mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); | ||||
|     fragNormal = normalize(normalMatrix*vertexNormal); | ||||
| @@ -1,12 +1,16 @@ | ||||
| #version 330 | ||||
| 
 | ||||
| // Input vertex attributes (from vertex shader) | ||||
| in vec2 fragTexCoord; | ||||
| in vec4 fragColor; | ||||
| 
 | ||||
| out vec4 fragColor; | ||||
| 
 | ||||
| // Input uniform values | ||||
| uniform sampler2D texture0; | ||||
| uniform vec4 fragTintColor; | ||||
| 
 | ||||
| // Output fragment color | ||||
| out vec4 finalColor; | ||||
| 
 | ||||
| // NOTE: Add here your custom variables | ||||
| 
 | ||||
| const float renderWidth = 800.0;      // HARDCODED for example! | ||||
| @@ -22,6 +26,7 @@ void main (void) | ||||
|     vec2 texSize = vec2(renderWidth, renderHeight); | ||||
|     vec2 tc = fragTexCoord*texSize; | ||||
|     tc -= center; | ||||
|      | ||||
|     float dist = length(tc); | ||||
| 
 | ||||
|     if (dist < radius)  | ||||
| @@ -37,5 +42,5 @@ void main (void) | ||||
|     tc += center; | ||||
|     vec3 color = texture2D(texture0, tc/texSize).rgb; | ||||
| 
 | ||||
|     fragColor = vec4(color, 1.0);; | ||||
|     finalColor = vec4(color, 1.0);; | ||||
| } | ||||
| @@ -1,20 +0,0 @@ | ||||
| #version 330 | ||||
|  | ||||
| in vec2 fragTexCoord; | ||||
|  | ||||
| out vec4 fragColor; | ||||
|  | ||||
| uniform sampler2D texture0; | ||||
| uniform vec4 fragTintColor; | ||||
|  | ||||
| // NOTE: Add here your custom variables | ||||
|  | ||||
| void main() | ||||
| { | ||||
|     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, fragTintColor.a); | ||||
| } | ||||
| @@ -1,18 +0,0 @@ | ||||
| #version 330 | ||||
|  | ||||
| attribute vec3 vertexPosition; | ||||
| attribute vec2 vertexTexCoord; | ||||
| attribute vec4 vertexColor; | ||||
|  | ||||
| uniform mat4 mvpMatrix; | ||||
|  | ||||
| varying vec2 fragTexCoord; | ||||
| varying vec4 fragTintColor; | ||||
|  | ||||
| void main() | ||||
| { | ||||
|     fragTexCoord = vertexTexCoord; | ||||
|     fragTintColor = vertexColor; | ||||
|      | ||||
|     gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); | ||||
| } | ||||
| @@ -1,15 +0,0 @@ | ||||
| #version 330 | ||||
|  | ||||
| uniform sampler2D texture0; | ||||
| varying vec2 fragTexCoord; | ||||
| varying vec4 fragTintColor; | ||||
|  | ||||
| void main() | ||||
| { | ||||
|     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, base.a); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 raysan5
					raysan5