Additional resources from the Raylib repo.
This commit is contained in:
parent
6c94ffb0cc
commit
ce3a7da69b
150 changed files with 41499 additions and 0 deletions
80
Examples/resources/shaders/glsl100/ascii.fs
Normal file
80
Examples/resources/shaders/glsl100/ascii.fs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input from the vertex shader
|
||||
varying vec2 fragTexCoord;
|
||||
|
||||
// Output color for the screen
|
||||
varying vec4 finalColor;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
uniform vec2 resolution;
|
||||
|
||||
// Fontsize less then 9 may be not complete
|
||||
uniform float fontSize;
|
||||
|
||||
float GreyScale(in vec3 col)
|
||||
{
|
||||
return dot(col, vec3(0.2126, 0.7152, 0.0722));
|
||||
}
|
||||
|
||||
float GetCharacter(float n, vec2 p)
|
||||
{
|
||||
p = floor(p*vec2(-4.0, 4.0) + 2.5);
|
||||
|
||||
// Check if the calculated coordinate is inside the 5x5 grid (from 0.0 to 4.0)
|
||||
if (clamp(p.x, 0.0, 4.0) == p.x && clamp(p.y, 0.0, 4.0) == p.y)
|
||||
{
|
||||
float a = floor(p.x + 0.5) + 5.0*floor(p.y + 0.5);
|
||||
|
||||
// This checked if the 'a'-th bit of 'n' was set
|
||||
float shiftedN = floor(n/pow(2.0, a));
|
||||
|
||||
if (mod(shiftedN, 2.0) == 1.0)
|
||||
{
|
||||
return 1.0; // The bit is on
|
||||
}
|
||||
}
|
||||
|
||||
return 0.0; // The bit is off, or we are outside the grid
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Main shader logic
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 charPixelSize = vec2(fontSize, fontSize);
|
||||
vec2 uvCellSize = charPixelSize/resolution;
|
||||
|
||||
// The cell size is based on the fontSize set by application
|
||||
vec2 cellUV = floor(fragTexCoord/uvCellSize)*uvCellSize;
|
||||
|
||||
vec3 cellColor = texture2D(texture0, cellUV).rgb;
|
||||
|
||||
// Gray is used to define what character will be selected to draw
|
||||
float gray = GreyScale(cellColor);
|
||||
|
||||
float n = 4096.0;
|
||||
|
||||
// Character set from https://www.shadertoy.com/view/lssGDj
|
||||
// Create new bitmaps https://thrill-project.com/archiv/coding/bitmap/
|
||||
if (gray > 0.2) n = 65600.0; // :
|
||||
if (gray > 0.3) n = 18725316.0; // v
|
||||
if (gray > 0.4) n = 15255086.0; // o
|
||||
if (gray > 0.5) n = 13121101.0; // &
|
||||
if (gray > 0.6) n = 15252014.0; // 8
|
||||
if (gray > 0.7) n = 13195790.0; // @
|
||||
if (gray > 0.8) n = 11512810.0; // #
|
||||
|
||||
vec2 localUV = (fragTexCoord - cellUV)/uvCellSize; // Range [0.0, 1.0]
|
||||
|
||||
vec2 p = localUV*2.0 - 1.0; // Range [-1.0, 1.0]
|
||||
|
||||
// cellColor and charShape will define the color of the char
|
||||
vec3 color = cellColor*GetCharacter(n, p);
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
||||
58
Examples/resources/shaders/glsl100/cel.fs
Normal file
58
Examples/resources/shaders/glsl100/cel.fs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
varying vec3 fragNormal;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
uniform vec3 viewPos;
|
||||
uniform float numBands;
|
||||
|
||||
struct Light {
|
||||
int enabled;
|
||||
int type;
|
||||
vec3 position;
|
||||
vec3 target;
|
||||
vec4 color;
|
||||
};
|
||||
uniform Light lights[4];
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texColor = texture2D(texture0, fragTexCoord);
|
||||
vec3 baseColor = texColor.rgb * fragColor.rgb * colDiffuse.rgb;
|
||||
vec3 norm = normalize(fragNormal);
|
||||
|
||||
float lightAccum = 0.08; // ambient floor
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (lights[i].enabled == 1) // no continue in GLSL ES 1.0
|
||||
{
|
||||
vec3 lightDir;
|
||||
if (lights[i].type == 0)
|
||||
{
|
||||
// Directional: direction is from position toward target.
|
||||
lightDir = normalize(lights[i].position - lights[i].target);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Point: direction from surface to light.
|
||||
lightDir = normalize(lights[i].position - fragPosition);
|
||||
}
|
||||
|
||||
float NdotL = max(dot(norm, lightDir), 0.0);
|
||||
|
||||
// Quantize NdotL into numBands discrete steps.
|
||||
float quantized = min(floor(NdotL * numBands), numBands - 1.0) / (numBands - 1.0);
|
||||
lightAccum += quantized * lights[i].color.r;
|
||||
}
|
||||
}
|
||||
|
||||
lightAccum = clamp(lightAccum, 0.0, 1.0);
|
||||
gl_FragColor = vec4(baseColor * lightAccum, texColor.a * colDiffuse.a);
|
||||
}
|
||||
47
Examples/resources/shaders/glsl100/cel.vs
Normal file
47
Examples/resources/shaders/glsl100/cel.vs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#version 100
|
||||
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec3 vertexNormal;
|
||||
attribute vec4 vertexColor;
|
||||
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
varying vec3 fragNormal;
|
||||
|
||||
mat3 inverse(mat3 m)
|
||||
{
|
||||
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
|
||||
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
|
||||
float b01 = a22*a11 - a12*a21;
|
||||
float b11 = -a22*a10 + a12*a20;
|
||||
float b21 = a21*a10 - a11*a20;
|
||||
float det = a00*b01 + a01*b11 + a02*b21;
|
||||
return mat3(b01, (-a22*a01 + a02*a21), ( a12*a01 - a02*a11),
|
||||
b11, ( a22*a00 - a02*a20), (-a12*a00 + a02*a10),
|
||||
b21, (-a21*a00 + a01*a20), ( a11*a00 - a01*a10)) / det;
|
||||
}
|
||||
|
||||
mat3 transpose(mat3 m)
|
||||
{
|
||||
return mat3(m[0][0], m[1][0], m[2][0],
|
||||
m[0][1], m[1][1], m[2][1],
|
||||
m[0][2], m[1][2], m[2][2]);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||
fragNormal = normalize(normalMatrix * vertexNormal);
|
||||
|
||||
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||
}
|
||||
34
Examples/resources/shaders/glsl100/color_correction.fs
Normal file
34
Examples/resources/shaders/glsl100/color_correction.fs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#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 colDiffuse;
|
||||
|
||||
uniform float contrast;
|
||||
uniform float saturation;
|
||||
uniform float brightness;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Get texel color
|
||||
vec4 texel = texture2D(texture0, fragTexCoord);
|
||||
|
||||
// Apply contrast
|
||||
texel.rgb = (texel.rgb - 0.5)*(contrast/100.0 + 1.0) + 0.5;
|
||||
|
||||
// Apply brightness
|
||||
texel.rgb = texel.rgb + brightness/100.0;
|
||||
|
||||
// Apply saturation
|
||||
float intensity = dot(texel.rgb, vec3(0.299, 0.587, 0.114));
|
||||
texel.rgb = (texel.rgb - intensity)*saturation/100.0 + texel.rgb;
|
||||
|
||||
// Output resulting color
|
||||
gl_FragColor = texel;
|
||||
}
|
||||
59
Examples/resources/shaders/glsl100/deferred_shading.fs
Normal file
59
Examples/resources/shaders/glsl100/deferred_shading.fs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D gPosition;
|
||||
uniform sampler2D gNormal;
|
||||
uniform sampler2D gAlbedoSpec;
|
||||
|
||||
struct Light {
|
||||
int enabled;
|
||||
int type; // Unused in this demo
|
||||
vec3 position;
|
||||
vec3 target; // Unused in this demo
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
const int NR_LIGHTS = 4;
|
||||
uniform Light lights[NR_LIGHTS];
|
||||
uniform vec3 viewPosition;
|
||||
|
||||
const float QUADRATIC = 0.032;
|
||||
const float LINEAR = 0.09;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 fragPosition = texture2D(gPosition, fragTexCoord).rgb;
|
||||
vec3 normal = texture2D(gNormal, fragTexCoord).rgb;
|
||||
vec3 albedo = texture2D(gAlbedoSpec, fragTexCoord).rgb;
|
||||
float specular = texture2D(gAlbedoSpec, fragTexCoord).a;
|
||||
|
||||
vec3 ambient = albedo*vec3(0.1);
|
||||
vec3 viewDirection = normalize(viewPosition - fragPosition);
|
||||
|
||||
for (int i = 0; i < NR_LIGHTS; i++)
|
||||
{
|
||||
if (lights[i].enabled == 0) continue;
|
||||
vec3 lightDirection = lights[i].position - fragPosition;
|
||||
vec3 diffuse = max(dot(normal, lightDirection), 0.0)*albedo*lights[i].color.xyz;
|
||||
|
||||
vec3 halfwayDirection = normalize(lightDirection + viewDirection);
|
||||
float spec = pow(max(dot(normal, halfwayDirection), 0.0), 32.0);
|
||||
vec3 specular = specular*spec*lights[i].color.xyz;
|
||||
|
||||
// Attenuation
|
||||
float distance = length(lights[i].position - fragPosition);
|
||||
float attenuation = 1.0/(1.0 + LINEAR*distance + QUADRATIC*distance*distance);
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
ambient += diffuse + specular;
|
||||
}
|
||||
|
||||
gl_FragColor = vec4(ambient, 1.0);
|
||||
}
|
||||
|
||||
16
Examples/resources/shaders/glsl100/deferred_shading.vs
Normal file
16
Examples/resources/shaders/glsl100/deferred_shading.vs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#version 100
|
||||
|
||||
// Input vertex attributes
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
varying vec2 fragTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragTexCoord = vertexTexCoord;
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = vec4(vertexPosition, 1.0);
|
||||
}
|
||||
29
Examples/resources/shaders/glsl100/depth_render.fs
Normal file
29
Examples/resources/shaders/glsl100/depth_render.fs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D depthTexture;
|
||||
uniform bool flipY;
|
||||
|
||||
float nearPlane = 0.1;
|
||||
float farPlane = 100.0;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Handle potential Y-flipping
|
||||
vec2 texCoord = fragTexCoord;
|
||||
if (flipY) texCoord.y = 1.0 - texCoord.y;
|
||||
|
||||
// Sample depth texture
|
||||
float depth = texture2D(depthTexture, texCoord).r;
|
||||
|
||||
// Linearize depth
|
||||
float linearDepth = (2.0*nearPlane)/(farPlane + nearPlane - depth*(farPlane - nearPlane));
|
||||
|
||||
// Output final color
|
||||
gl_FragColor = vec4(vec3(linearDepth), 1.0);
|
||||
}
|
||||
20
Examples/resources/shaders/glsl100/depth_write.fs
Normal file
20
Examples/resources/shaders/glsl100/depth_write.fs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#version 100
|
||||
#extension GL_EXT_frag_depth : enable
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
|
||||
gl_FragColor = texelColor*colDiffuse*fragColor;
|
||||
gl_FragDepthEXT = 1.0 - gl_FragCoord.z;
|
||||
}
|
||||
44
Examples/resources/shaders/glsl100/game_of_life.fs
Normal file
44
Examples/resources/shaders/glsl100/game_of_life.fs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#version 100
|
||||
|
||||
precision highp float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Input size in pixels of the textures
|
||||
uniform vec2 resolution;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Size of one pixel in texture coordinates (from 0.0 to 1.0)
|
||||
float x = 1.0/resolution.x;
|
||||
float y = 1.0/resolution.y;
|
||||
|
||||
// Status of the current cell (1 = alive, 0 = dead)
|
||||
int origValue = (texture2D(texture0, fragTexCoord).r < 0.1)? 1 : 0;
|
||||
|
||||
// Sum of alive neighbors
|
||||
int sumValue = (texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y)).r < 0.1)? 1 : 0; // Top-left
|
||||
sumValue += (texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y )).r < 0.1)? 1 : 0; // Top
|
||||
sumValue += (texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y)).r < 0.1)? 1 : 0; // Top-right
|
||||
|
||||
sumValue += (texture2D(texture0, vec2(fragTexCoord.x, fragTexCoord.y - y)).r < 0.1)? 1 : 0; // Left
|
||||
sumValue += (texture2D(texture0, vec2(fragTexCoord.x, fragTexCoord.y + y)).r < 0.1)? 1 : 0; // Right
|
||||
|
||||
sumValue += (texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y)).r < 0.1)? 1 : 0; // Bottom-left
|
||||
sumValue += (texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y )).r < 0.1)? 1 : 0; // Bottom
|
||||
sumValue += (texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y)).r < 0.1)? 1 : 0; // Bottom-right
|
||||
|
||||
// Game of life rules:
|
||||
// Current cell remains alive when 2 or 3 neighbors are alive, dies otherwise
|
||||
// Current cell goes from dead to alive when exactly 3 neighbors are alive
|
||||
if ((origValue == 1 && sumValue == 2) || sumValue == 3)
|
||||
gl_FragColor = vec4(0.0, 0.0, 0.0, 255.0); // Alive: draw the pixel black
|
||||
else
|
||||
gl_FragColor = fragColor; // Dead: draw the pixel with the background color, RAYWHITE
|
||||
}
|
||||
36
Examples/resources/shaders/glsl100/gbuffer.fs
Normal file
36
Examples/resources/shaders/glsl100/gbuffer.fs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec3 fragNormal;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// TODO: Is there some alternative for GLSL100
|
||||
//layout (location = 0) out vec3 gPosition;
|
||||
//layout (location = 1) out vec3 gNormal;
|
||||
//layout (location = 2) out vec4 gAlbedoSpec;
|
||||
//uniform vec3 gPosition;
|
||||
//uniform vec3 gNormal;
|
||||
//uniform vec4 gAlbedoSpec;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0; // Diffuse texture
|
||||
uniform sampler2D specularTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Store the fragment position vector in the first gbuffer texture
|
||||
//gPosition = fragPosition;
|
||||
|
||||
// Store the per-fragment normals into the gbuffer
|
||||
//gNormal = normalize(fragNormal);
|
||||
|
||||
// Store the diffuse per-fragment color
|
||||
gl_FragColor.rgb = texture2D(texture0, fragTexCoord).rgb;
|
||||
|
||||
// Store specular intensity in gAlbedoSpec's alpha component
|
||||
gl_FragColor.a = texture2D(specularTexture, fragTexCoord).r;
|
||||
}
|
||||
60
Examples/resources/shaders/glsl100/gbuffer.vs
Normal file
60
Examples/resources/shaders/glsl100/gbuffer.vs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#version 100
|
||||
|
||||
// Input vertex attributes
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec3 vertexNormal;
|
||||
attribute vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 matModel;
|
||||
uniform mat4 matView;
|
||||
uniform mat4 matProjection;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec3 fragNormal;
|
||||
varying vec4 fragColor;
|
||||
|
||||
|
||||
// https://github.com/glslify/glsl-inverse
|
||||
mat3 inverse(mat3 m)
|
||||
{
|
||||
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
|
||||
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
|
||||
|
||||
float b01 = a22*a11 - a12*a21;
|
||||
float b11 = -a22*a10 + a12*a20;
|
||||
float b21 = a21*a10 - a11*a20;
|
||||
|
||||
float det = a00*b01 + a01*b11 + a02*b21;
|
||||
|
||||
return mat3(b01, (-a22*a01 + a02*a21), (a12*a01 - a02*a11),
|
||||
b11, (a22*a00 - a02*a20), (-a12*a00 + a02*a10),
|
||||
b21, (-a21*a00 + a01*a20), (a11*a00 - a01*a10))/det;
|
||||
}
|
||||
|
||||
// https://github.com/glslify/glsl-transpose
|
||||
mat3 transpose(mat3 m)
|
||||
{
|
||||
return mat3(m[0][0], m[1][0], m[2][0],
|
||||
m[0][1], m[1][1], m[2][1],
|
||||
m[0][2], m[1][2], m[2][2]);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// Calculate vertex attributes for fragment shader
|
||||
vec4 worldPos = matModel*vec4(vertexPosition, 1.0);
|
||||
fragPosition = worldPos.xyz;
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||
fragNormal = normalMatrix*vertexNormal;
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = matProjection*matView*worldPos;
|
||||
}
|
||||
22
Examples/resources/shaders/glsl100/lightmap.fs
Normal file
22
Examples/resources/shaders/glsl100/lightmap.fs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec2 fragTexCoord2;
|
||||
varying vec3 fragPosition;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform sampler2D texture1;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
vec4 texelColor2 = texture2D(texture1, fragTexCoord2);
|
||||
|
||||
gl_FragColor = texelColor*texelColor2;
|
||||
}
|
||||
31
Examples/resources/shaders/glsl100/lightmap.vs
Normal file
31
Examples/resources/shaders/glsl100/lightmap.vs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#version 100
|
||||
|
||||
// Input vertex attributes
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec2 vertexTexCoord2;
|
||||
attribute vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec2 fragTexCoord2;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragTexCoord2 = vertexTexCoord2;
|
||||
fragColor = vertexColor;
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
||||
62
Examples/resources/shaders/glsl100/mandelbrot_set.fs
Normal file
62
Examples/resources/shaders/glsl100/mandelbrot_set.fs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#version 100
|
||||
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
|
||||
precision highp float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
uniform vec2 offset; // Offset of the scale
|
||||
uniform float zoom; // Zoom of the scale
|
||||
// NOTE: Maximum number of shader for-loop iterations depend on GPU,
|
||||
// For example, on RasperryPi for this examply only supports up to 60
|
||||
uniform int maxIterations; // Max iterations per pixel
|
||||
|
||||
const float max = 4.0; // We consider infinite as 4.0: if a point reaches a distance of 4.0 it will escape to infinity
|
||||
const float max2 = max*max; // Square of max to avoid computing square root
|
||||
|
||||
// WebGL shaders for loop iteration limit only const
|
||||
const int maxIterationsLimit = 20000;
|
||||
|
||||
void main()
|
||||
{
|
||||
// The pixel coordinates are scaled so they are on the mandelbrot scale
|
||||
// NOTE: fragTexCoord already comes as normalized screen coordinates but offset must be normalized before scaling and zoom
|
||||
vec2 c = vec2((fragTexCoord.x - 0.5)*2.5, (fragTexCoord.y - 0.5)*1.5)/zoom;
|
||||
c.x += offset.x;
|
||||
c.y += offset.y;
|
||||
float a = 0.0;
|
||||
float b = 0.0;
|
||||
|
||||
// The Mandelbrot set is a two-dimensional set defined in the complex plane on which the iteration of the function
|
||||
// Fc(z) = z^2 + c on the complex numbers c from the plane does not diverge to infinity starting at z = 0
|
||||
// Here: z = a + bi. Iterations: z -> z^2 + c = (a + bi)^2 + (c.x + c.yi) = (a^2 - b^2 + c.x) + (2ab + c.y)i
|
||||
|
||||
for (int iter = 0; iter < maxIterationsLimit; iter++)
|
||||
{
|
||||
float aa = a*a;
|
||||
float bb = b*b;
|
||||
if (iter >= maxIterations)
|
||||
{
|
||||
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
return;
|
||||
}
|
||||
if (aa + bb > max2)
|
||||
{
|
||||
float normR = float(iter - (iter/55)*55)/55.0;
|
||||
float normG = float(iter - (iter/69)*69)/69.0;
|
||||
float normB = float(iter - (iter/40)*40)/40.0;
|
||||
|
||||
gl_FragColor = vec4(sin(normR*PI), sin(normG*PI), sin(normB*PI), 1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
float twoab = 2.0*a*b;
|
||||
a = aa - bb + c.x;
|
||||
b = twoab + c.y;
|
||||
}
|
||||
|
||||
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
64
Examples/resources/shaders/glsl100/normalmap.fs
Normal file
64
Examples/resources/shaders/glsl100/normalmap.fs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// 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 = texture2D(texture0, vec2(fragTexCoord.x, fragTexCoord.y));
|
||||
vec3 specular = vec3(0.0);
|
||||
vec3 viewDir = normalize(viewPos - fragPosition);
|
||||
vec3 lightDir = normalize(lightPos - fragPosition);
|
||||
|
||||
vec3 normal = vec3(0.0);
|
||||
if (useNormalMap)
|
||||
{
|
||||
normal = texture2D(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;
|
||||
|
||||
vec4 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));
|
||||
}
|
||||
76
Examples/resources/shaders/glsl100/normalmap.vs
Normal file
76
Examples/resources/shaders/glsl100/normalmap.vs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#version 100
|
||||
|
||||
// Input vertex attributes
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec3 vertexNormal;
|
||||
attribute vec4 vertexTangent;
|
||||
attribute vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec3 fragNormal; //used for when normal mapping is toggled off
|
||||
varying vec4 fragColor;
|
||||
varying mat3 TBN;
|
||||
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// https://github.com/glslify/glsl-inverse
|
||||
mat3 inverse(mat3 m)
|
||||
{
|
||||
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
|
||||
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
|
||||
|
||||
float b01 = a22*a11 - a12*a21;
|
||||
float b11 = -a22*a10 + a12*a20;
|
||||
float b21 = a21*a10 - a11*a20;
|
||||
|
||||
float det = a00*b01 + a01*b11 + a02*b21;
|
||||
|
||||
return mat3(b01, (-a22*a01 + a02*a21), (a12*a01 - a02*a11),
|
||||
b11, (a22*a00 - a02*a20), (-a12*a00 + a02*a10),
|
||||
b21, (-a21*a00 + a01*a20), (a11*a00 - a01*a10))/det;
|
||||
}
|
||||
|
||||
// https://github.com/glslify/glsl-transpose
|
||||
mat3 transpose(mat3 m)
|
||||
{
|
||||
return mat3(m[0][0], m[1][0], m[2][0],
|
||||
m[0][1], m[1][1], m[2][1],
|
||||
m[0][2], m[1][2], m[2][2]);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// Compute binormal from vertex normal and tangent. W component is the tangent handedness
|
||||
vec3 vertexBinormal = cross(vertexNormal, vertexTangent.xyz)*vertexTangent.w;
|
||||
|
||||
// Compute fragment normal based on normal transformations
|
||||
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||
|
||||
// Compute fragment position based on model transformations
|
||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
|
||||
|
||||
//Create TBN matrix for transforming the normal map values from tangent-space to world-space
|
||||
fragNormal = normalize(normalMatrix*vertexNormal);
|
||||
|
||||
vec3 fragTangent = normalize(normalMatrix*vertexTangent.xyz);
|
||||
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
|
||||
|
||||
vec3 fragBinormal = normalize(normalMatrix*vertexBinormal);
|
||||
fragBinormal = cross(fragNormal, fragTangent);
|
||||
|
||||
TBN = transpose(mat3(fragTangent, fragBinormal, fragNormal));
|
||||
|
||||
fragColor = vertexColor;
|
||||
|
||||
fragTexCoord = vertexTexCoord;
|
||||
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
||||
8
Examples/resources/shaders/glsl100/outline_hull.fs
Normal file
8
Examples/resources/shaders/glsl100/outline_hull.fs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vec4(0.05, 0.05, 0.05, 1.0);
|
||||
}
|
||||
15
Examples/resources/shaders/glsl100/outline_hull.vs
Normal file
15
Examples/resources/shaders/glsl100/outline_hull.vs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#version 100
|
||||
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec3 vertexNormal;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec4 vertexColor;
|
||||
|
||||
uniform mat4 mvp;
|
||||
uniform float outlineThickness;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 extruded = vertexPosition + vertexNormal * outlineThickness;
|
||||
gl_Position = mvp * vec4(extruded, 1.0);
|
||||
}
|
||||
161
Examples/resources/shaders/glsl100/pbr.fs
Normal file
161
Examples/resources/shaders/glsl100/pbr.fs
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
#version 100
|
||||
|
||||
precision highp float;
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
#define LIGHT_POINT 1
|
||||
#define PI 3.14159265358979323846
|
||||
|
||||
struct Light {
|
||||
int enabled;
|
||||
int type;
|
||||
vec3 position;
|
||||
vec3 target;
|
||||
vec4 color;
|
||||
float intensity;
|
||||
};
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
varying vec3 fragNormal;
|
||||
varying vec4 shadowPos;
|
||||
varying mat3 TBN;
|
||||
|
||||
// Input uniform values
|
||||
uniform int numOfLights;
|
||||
uniform sampler2D albedoMap;
|
||||
uniform sampler2D mraMap;
|
||||
uniform sampler2D normalMap;
|
||||
uniform sampler2D emissiveMap; // r: Hight g:emissive
|
||||
|
||||
uniform vec2 tiling;
|
||||
uniform vec2 offset;
|
||||
|
||||
uniform int useTexAlbedo;
|
||||
uniform int useTexNormal;
|
||||
uniform int useTexMRA;
|
||||
uniform int useTexEmissive;
|
||||
|
||||
uniform vec4 albedoColor;
|
||||
uniform vec4 emissiveColor;
|
||||
uniform float normalValue;
|
||||
uniform float metallicValue;
|
||||
uniform float roughnessValue;
|
||||
uniform float aoValue;
|
||||
uniform float emissivePower;
|
||||
|
||||
// Input lighting values
|
||||
uniform Light lights[MAX_LIGHTS];
|
||||
uniform vec3 viewPos;
|
||||
|
||||
uniform vec3 ambientColor;
|
||||
uniform float ambient;
|
||||
|
||||
// Reflectivity in range 0.0 to 1.0
|
||||
// NOTE: Reflectivity is increased when surface view at larger angle
|
||||
vec3 SchlickFresnel(float hDotV,vec3 refl)
|
||||
{
|
||||
return refl + (1.0 - refl)*pow(1.0 - hDotV, 5.0);
|
||||
}
|
||||
|
||||
float GgxDistribution(float nDotH,float roughness)
|
||||
{
|
||||
float a = roughness*roughness*roughness*roughness;
|
||||
float d = nDotH*nDotH*(a - 1.0) + 1.0;
|
||||
d = PI*d*d;
|
||||
return (a/max(d,0.0000001));
|
||||
}
|
||||
|
||||
float GeomSmith(float nDotV,float nDotL,float roughness)
|
||||
{
|
||||
float r = roughness + 1.0;
|
||||
float k = r*r/8.0;
|
||||
float ik = 1.0 - k;
|
||||
float ggx1 = nDotV/(nDotV*ik + k);
|
||||
float ggx2 = nDotL/(nDotL*ik + k);
|
||||
return ggx1*ggx2;
|
||||
}
|
||||
|
||||
vec3 ComputePBR()
|
||||
{
|
||||
vec3 albedo = texture2D(albedoMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y)).rgb;
|
||||
albedo = vec3(albedoColor.x*albedo.x, albedoColor.y*albedo.y, albedoColor.z*albedo.z);
|
||||
|
||||
float metallic = clamp(metallicValue, 0.0, 1.0);
|
||||
float roughness = clamp(roughnessValue, 0.0, 1.0);
|
||||
float ao = clamp(aoValue, 0.0, 1.0);
|
||||
|
||||
if (useTexMRA == 1)
|
||||
{
|
||||
vec4 mra = texture2D(mraMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y));
|
||||
metallic = clamp(mra.r + metallicValue, 0.04, 1.0);
|
||||
roughness = clamp(mra.g + roughnessValue, 0.04, 1.0);
|
||||
ao = (mra.b + aoValue)*0.5;
|
||||
}
|
||||
|
||||
vec3 N = normalize(fragNormal);
|
||||
if (useTexNormal == 1)
|
||||
{
|
||||
N = texture2D(normalMap, vec2(fragTexCoord.x*tiling.x + offset.y, fragTexCoord.y*tiling.y + offset.y)).rgb;
|
||||
N = normalize(N*2.0 - 1.0);
|
||||
N = normalize(N*TBN);
|
||||
}
|
||||
|
||||
vec3 V = normalize(viewPos - fragPosition);
|
||||
|
||||
vec3 emissive = vec3(0);
|
||||
emissive = (texture2D(emissiveMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y)).rgb).g*emissiveColor.rgb*emissivePower*float(useTexEmissive);
|
||||
|
||||
// return N;//vec3(metallic,metallic,metallic);
|
||||
// If dia-electric use base reflectivity of 0.04 otherwise ut is a metal use albedo as base reflectivity
|
||||
vec3 baseRefl = mix(vec3(0.04), albedo.rgb, metallic);
|
||||
vec3 lightAccum = vec3(0.0); // Acumulate lighting lum
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
vec3 L = normalize(lights[i].position - fragPosition); // Compute light vector
|
||||
vec3 H = normalize(V + L); // Compute halfway bisecting vector
|
||||
float dist = length(lights[i].position - fragPosition); // Compute distance to light
|
||||
float attenuation = 1.0/(dist*dist*0.23); // Compute attenuation
|
||||
vec3 radiance = lights[i].color.rgb*lights[i].intensity*attenuation; // Compute input radiance, light energy comming in
|
||||
|
||||
// Cook-Torrance BRDF distribution function
|
||||
float nDotV = max(dot(N,V), 0.0000001);
|
||||
float nDotL = max(dot(N,L), 0.0000001);
|
||||
float hDotV = max(dot(H,V), 0.0);
|
||||
float nDotH = max(dot(N,H), 0.0);
|
||||
float D = GgxDistribution(nDotH, roughness); // Larger the more micro-facets aligned to H
|
||||
float G = GeomSmith(nDotV, nDotL, roughness); // Smaller the more micro-facets shadow
|
||||
vec3 F = SchlickFresnel(hDotV, baseRefl); // Fresnel proportion of specular reflectance
|
||||
|
||||
vec3 spec = (D*G*F)/(4.0*nDotV*nDotL);
|
||||
|
||||
// Difuse and spec light can't be above 1.0
|
||||
// kD = 1.0 - kS diffuse component is equal 1.0 - spec comonent
|
||||
vec3 kD = vec3(1.0) - F;
|
||||
|
||||
// Mult kD by the inverse of metallnes, only non-metals should have diffuse light
|
||||
kD *= 1.0 - metallic;
|
||||
lightAccum += ((kD*albedo.rgb/PI + spec)*radiance*nDotL)*float(lights[i].enabled); // Angle of light has impact on result
|
||||
}
|
||||
|
||||
vec3 ambientFinal = (ambientColor + albedo)*ambient*0.5;
|
||||
|
||||
return (ambientFinal + lightAccum*ao + emissive);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = ComputePBR();
|
||||
|
||||
// HDR tonemapping
|
||||
color = pow(color, color + vec3(1.0));
|
||||
|
||||
// Gamma correction
|
||||
color = pow(color, vec3(1.0/2.2));
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
||||
74
Examples/resources/shaders/glsl100/pbr.vs
Normal file
74
Examples/resources/shaders/glsl100/pbr.vs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#version 100
|
||||
|
||||
// Input vertex attributes
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec3 vertexNormal;
|
||||
attribute vec4 vertexTangent;
|
||||
attribute vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
uniform mat4 matNormal;
|
||||
uniform vec3 lightPos;
|
||||
uniform vec4 difColor;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
varying vec3 fragNormal;
|
||||
varying mat3 TBN;
|
||||
|
||||
const float normalOffset = 0.1;
|
||||
|
||||
// https://github.com/glslify/glsl-inverse
|
||||
mat3 inverse(mat3 m)
|
||||
{
|
||||
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
|
||||
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
|
||||
|
||||
float b01 = a22*a11 - a12*a21;
|
||||
float b11 = -a22*a10 + a12*a20;
|
||||
float b21 = a21*a10 - a11*a20;
|
||||
|
||||
float det = a00*b01 + a01*b11 + a02*b21;
|
||||
|
||||
return mat3(b01, (-a22*a01 + a02*a21), (a12*a01 - a02*a11),
|
||||
b11, (a22*a00 - a02*a20), (-a12*a00 + a02*a10),
|
||||
b21, (-a21*a00 + a01*a20), (a11*a00 - a01*a10))/det;
|
||||
}
|
||||
|
||||
// https://github.com/glslify/glsl-transpose
|
||||
mat3 transpose(mat3 m)
|
||||
{
|
||||
return mat3(m[0][0], m[1][0], m[2][0],
|
||||
m[0][1], m[1][1], m[2][1],
|
||||
m[0][2], m[1][2], m[2][2]);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// Compute binormal from vertex normal and tangent
|
||||
vec3 vertexBinormal = cross(vertexNormal, vertexTangent.xyz)*vertexTangent.w;
|
||||
|
||||
// Compute fragment normal based on normal transformations
|
||||
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||
|
||||
// Compute fragment position based on model transformations
|
||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
|
||||
|
||||
fragTexCoord = vertexTexCoord*2.0;
|
||||
fragNormal = normalize(normalMatrix*vertexNormal);
|
||||
vec3 fragTangent = normalize(normalMatrix*vertexTangent.xyz);
|
||||
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
|
||||
vec3 fragBinormal = normalize(normalMatrix*vertexBinormal);
|
||||
fragBinormal = cross(fragNormal, fragTangent);
|
||||
|
||||
TBN = transpose(mat3(fragTangent, fragBinormal, fragNormal));
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
||||
16
Examples/resources/shaders/glsl100/point_particle.fs
Normal file
16
Examples/resources/shaders/glsl100/point_particle.fs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input uniform values
|
||||
uniform vec4 color;
|
||||
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
// Each point is drawn as a screen space square of gl_PointSize size. gl_PointCoord contains where we are inside of
|
||||
// it. (0, 0) is the top left, (1, 1) the bottom right corner
|
||||
// Draw each point as a colored circle with alpha 1.0 in the center and 0.0 at the outer edges
|
||||
gl_FragColor = vec4(color.rgb, color.a*(1.0 - length(gl_PointCoord.xy - vec2(0.5))*2.0));
|
||||
}
|
||||
24
Examples/resources/shaders/glsl100/point_particle.vs
Normal file
24
Examples/resources/shaders/glsl100/point_particle.vs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#version 100
|
||||
|
||||
// Input vertex attributes
|
||||
attribute vec3 vertexPosition;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform float currentTime;
|
||||
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
// Unpack data from vertexPosition
|
||||
vec2 pos = vertexPosition.xy;
|
||||
float period = vertexPosition.z;
|
||||
|
||||
// Calculate final vertex position (jiggle it around a bit horizontally)
|
||||
pos += vec2(100.0, 0.0)*sin(period*currentTime);
|
||||
gl_Position = mvp*vec4(pos.x, pos.y, 0.0, 1.0);
|
||||
|
||||
// Calculate the screen space size of this particle (also vary it over time)
|
||||
gl_PointSize = 10.0 - 5.0*abs(sin(period*currentTime));
|
||||
}
|
||||
76
Examples/resources/shaders/glsl100/rounded_rectangle.fs
Normal file
76
Examples/resources/shaders/glsl100/rounded_rectangle.fs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// NOTE: SDF by Iñigo Quilez, licensed under MIT License
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
uniform vec4 rectangle; // Rectangle dimensions (x, y, width, height)
|
||||
uniform vec4 radius; // Corner radius (top-left, top-right, bottom-left, bottom-right)
|
||||
uniform vec4 color;
|
||||
|
||||
// Shadow parameters
|
||||
uniform float shadowRadius;
|
||||
uniform vec2 shadowOffset;
|
||||
uniform float shadowScale;
|
||||
uniform vec4 shadowColor;
|
||||
|
||||
// Border parameters
|
||||
uniform float borderThickness;
|
||||
uniform vec4 borderColor;
|
||||
|
||||
// Create a rounded rectangle using signed distance field
|
||||
// Thanks to Iñigo Quilez (https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm)
|
||||
// And thanks to inobelar (https://www.shadertoy.com/view/fsdyzB) for shader
|
||||
// MIT License
|
||||
float RoundedRectangleSDF(vec2 fragCoord, vec2 center, vec2 halfSize, vec4 radius)
|
||||
{
|
||||
vec2 fragFromCenter = fragCoord - center;
|
||||
|
||||
// Determine which corner radius to use
|
||||
radius.xy = (fragFromCenter.y > 0.0) ? radius.xy : radius.zw;
|
||||
radius.x = (fragFromCenter.x < 0.0) ? radius.x : radius.y;
|
||||
|
||||
// Calculate signed distance field
|
||||
vec2 dist = abs(fragFromCenter) - halfSize + radius.x;
|
||||
return min(max(dist.x, dist.y), 0.0) + length(max(dist, 0.0)) - radius.x;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
|
||||
// Requires fragment coordinate varying pixels
|
||||
vec2 fragCoord = gl_FragCoord.xy;
|
||||
|
||||
// Calculate signed distance field for rounded rectangle
|
||||
vec2 halfSize = rectangle.zw*0.5;
|
||||
vec2 center = rectangle.xy + halfSize;
|
||||
float recSDF = RoundedRectangleSDF(fragCoord, center, halfSize, radius);
|
||||
|
||||
// Calculate signed distance field for rectangle shadow
|
||||
vec2 shadowHalfSize = halfSize*shadowScale;
|
||||
vec2 shadowCenter = center + shadowOffset;
|
||||
float shadowSDF = RoundedRectangleSDF(fragCoord, shadowCenter, shadowHalfSize, radius);
|
||||
|
||||
// Caculate alpha factors
|
||||
float recFactor = smoothstep(1.0, 0.0, recSDF);
|
||||
float shadowFactor = smoothstep(shadowRadius, 0.0, shadowSDF);
|
||||
float borderFactor = smoothstep(0.0, 1.0, recSDF + borderThickness)*recFactor;
|
||||
|
||||
// Multiply each color by its respective alpha factor
|
||||
vec4 recColor = vec4(color.rgb, color.a*recFactor);
|
||||
vec4 shadowCol = vec4(shadowColor.rgb, shadowColor.a*shadowFactor);
|
||||
vec4 borderCol = vec4(borderColor.rgb, borderColor.a*borderFactor);
|
||||
|
||||
// Combine the colors varying the order (shadow, rectangle, border)
|
||||
gl_FragColor = mix(mix(shadowCol, recColor, recColor.a), borderCol, borderCol.a);
|
||||
}
|
||||
86
Examples/resources/shaders/glsl100/shadowmap.fs
Normal file
86
Examples/resources/shaders/glsl100/shadowmap.fs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// This shader is based on the basic lighting shader
|
||||
// This only supports one light, which is directional, and it (of course) supports shadows
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
//varying in vec4 fragColor;
|
||||
varying vec3 fragNormal;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Input lighting values
|
||||
uniform vec3 lightDir;
|
||||
uniform vec4 lightColor;
|
||||
uniform vec4 ambient;
|
||||
uniform vec3 viewPos;
|
||||
|
||||
// Input shadowmapping values
|
||||
uniform mat4 lightVP; // Light source view-projection matrix
|
||||
uniform sampler2D shadowMap;
|
||||
|
||||
uniform int shadowMapResolution;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
vec3 lightDot = vec3(0.0);
|
||||
vec3 normal = normalize(fragNormal);
|
||||
vec3 viewD = normalize(viewPos - fragPosition);
|
||||
vec3 specular = vec3(0.0);
|
||||
|
||||
vec3 l = -lightDir;
|
||||
|
||||
float NdotL = max(dot(normal, l), 0.0);
|
||||
lightDot += lightColor.rgb*NdotL;
|
||||
|
||||
float specCo = 0.0;
|
||||
if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(l), normal))), 16.0); // 16 refers to shine
|
||||
specular += specCo;
|
||||
|
||||
vec4 finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
|
||||
|
||||
// Shadow calculations
|
||||
vec4 fragPosLightSpace = lightVP*vec4(fragPosition, 1);
|
||||
fragPosLightSpace.xyz /= fragPosLightSpace.w; // Perform the perspective division
|
||||
fragPosLightSpace.xyz = (fragPosLightSpace.xyz + 1.0)/2.0; // Transform from [-1, 1] range to [0, 1] range
|
||||
vec2 sampleCoords = fragPosLightSpace.xy;
|
||||
float curDepth = fragPosLightSpace.z;
|
||||
|
||||
// Slope-scale depth bias: depth biasing reduces "shadow acne" artifacts, where dark stripes appear all over the scene
|
||||
// The solution is adding a small bias to the depth
|
||||
// In this case, the bias is proportional to the slope of the surface, relative to the light
|
||||
float bias = max(0.0008*(1.0 - dot(normal, l)), 0.00008);
|
||||
int shadowCounter = 0;
|
||||
const int numSamples = 9;
|
||||
|
||||
// PCF (percentage-closer filtering) algorithm:
|
||||
// Instead of testing if just one point is closer to the current point,
|
||||
// we test the surrounding points as well
|
||||
// This blurs shadow edges, hiding aliasing artifacts
|
||||
vec2 texelSize = vec2(1.0/float(shadowMapResolution));
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
for (int y = -1; y <= 1; y++)
|
||||
{
|
||||
float sampleDepth = texture2D(shadowMap, sampleCoords + texelSize*vec2(x, y)).r;
|
||||
if (curDepth - bias > sampleDepth) shadowCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
finalColor = mix(finalColor, vec4(0, 0, 0, 1), float(shadowCounter)/float(numSamples));
|
||||
|
||||
// Add ambient lighting whether in shadow or not
|
||||
finalColor += texelColor*(ambient/10.0)*colDiffuse;
|
||||
|
||||
// Gamma correction
|
||||
finalColor = pow(finalColor, vec4(1.0/2.2));
|
||||
gl_FragColor = finalColor;
|
||||
}
|
||||
32
Examples/resources/shaders/glsl100/shadowmap.vs
Normal file
32
Examples/resources/shaders/glsl100/shadowmap.vs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#version 100
|
||||
|
||||
// Input vertex attributes
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec3 vertexNormal;
|
||||
attribute vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
uniform mat4 matNormal;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
varying vec3 fragNormal;
|
||||
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
||||
20
Examples/resources/shaders/glsl100/skinning.fs
Normal file
20
Examples/resources/shaders/glsl100/skinning.fs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#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 colDiffuse;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Fetch color from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
|
||||
// Calculate final fragment color
|
||||
gl_FragColor = texelColor*colDiffuse*fragColor;
|
||||
}
|
||||
59
Examples/resources/shaders/glsl100/skinning.vs
Normal file
59
Examples/resources/shaders/glsl100/skinning.vs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#version 100
|
||||
|
||||
#define MAX_BONE_NUM 64
|
||||
|
||||
// Input vertex attributes
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec4 vertexColor;
|
||||
attribute vec4 vertexBoneIndices;
|
||||
attribute vec4 vertexBoneWeights;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 boneMatrices[MAX_BONE_NUM];
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
int boneIndex0 = int(vertexBoneIndices.x);
|
||||
int boneIndex1 = int(vertexBoneIndices.y);
|
||||
int boneIndex2 = int(vertexBoneIndices.z);
|
||||
int boneIndex3 = int(vertexBoneIndices.w);
|
||||
|
||||
// WARNING: OpenGL ES 2.0 does not support automatic matrix transposing, neither transpose() function
|
||||
mat4 boneMatrixTransposed0 = mat4(
|
||||
vec4(boneMatrices[boneIndex0][0].x, boneMatrices[boneIndex0][1].x, boneMatrices[boneIndex0][2].x, boneMatrices[boneIndex0][3].x),
|
||||
vec4(boneMatrices[boneIndex0][0].y, boneMatrices[boneIndex0][1].y, boneMatrices[boneIndex0][2].y, boneMatrices[boneIndex0][3].y),
|
||||
vec4(boneMatrices[boneIndex0][0].z, boneMatrices[boneIndex0][1].z, boneMatrices[boneIndex0][2].z, boneMatrices[boneIndex0][3].z),
|
||||
vec4(boneMatrices[boneIndex0][0].w, boneMatrices[boneIndex0][1].w, boneMatrices[boneIndex0][2].w, boneMatrices[boneIndex0][3].w));
|
||||
mat4 boneMatrixTransposed1 = mat4(
|
||||
vec4(boneMatrices[boneIndex1][0].x, boneMatrices[boneIndex1][1].x, boneMatrices[boneIndex1][2].x, boneMatrices[boneIndex1][3].x),
|
||||
vec4(boneMatrices[boneIndex1][0].y, boneMatrices[boneIndex1][1].y, boneMatrices[boneIndex1][2].y, boneMatrices[boneIndex1][3].y),
|
||||
vec4(boneMatrices[boneIndex1][0].z, boneMatrices[boneIndex1][1].z, boneMatrices[boneIndex1][2].z, boneMatrices[boneIndex1][3].z),
|
||||
vec4(boneMatrices[boneIndex1][0].w, boneMatrices[boneIndex1][1].w, boneMatrices[boneIndex1][2].w, boneMatrices[boneIndex1][3].w));
|
||||
mat4 boneMatrixTransposed2 = mat4(
|
||||
vec4(boneMatrices[boneIndex2][0].x, boneMatrices[boneIndex2][1].x, boneMatrices[boneIndex2][2].x, boneMatrices[boneIndex2][3].x),
|
||||
vec4(boneMatrices[boneIndex2][0].y, boneMatrices[boneIndex2][1].y, boneMatrices[boneIndex2][2].y, boneMatrices[boneIndex2][3].y),
|
||||
vec4(boneMatrices[boneIndex2][0].z, boneMatrices[boneIndex2][1].z, boneMatrices[boneIndex2][2].z, boneMatrices[boneIndex2][3].z),
|
||||
vec4(boneMatrices[boneIndex2][0].w, boneMatrices[boneIndex2][1].w, boneMatrices[boneIndex2][2].w, boneMatrices[boneIndex2][3].w));
|
||||
mat4 boneMatrixTransposed3 = mat4(
|
||||
vec4(boneMatrices[boneIndex3][0].x, boneMatrices[boneIndex3][1].x, boneMatrices[boneIndex3][2].x, boneMatrices[boneIndex3][3].x),
|
||||
vec4(boneMatrices[boneIndex3][0].y, boneMatrices[boneIndex3][1].y, boneMatrices[boneIndex3][2].y, boneMatrices[boneIndex3][3].y),
|
||||
vec4(boneMatrices[boneIndex3][0].z, boneMatrices[boneIndex3][1].z, boneMatrices[boneIndex3][2].z, boneMatrices[boneIndex3][3].z),
|
||||
vec4(boneMatrices[boneIndex3][0].w, boneMatrices[boneIndex3][1].w, boneMatrices[boneIndex3][2].w, boneMatrices[boneIndex3][3].w));
|
||||
|
||||
vec4 skinnedPosition =
|
||||
vertexBoneWeights.x*(boneMatrixTransposed0*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.y*(boneMatrixTransposed1*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.z*(boneMatrixTransposed2*vec4(vertexPosition, 1.0)) +
|
||||
vertexBoneWeights.w*(boneMatrixTransposed3*vec4(vertexPosition, 1.0));
|
||||
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
gl_Position = mvp*skinnedPosition;
|
||||
}
|
||||
21
Examples/resources/shaders/glsl100/tiling.fs
Normal file
21
Examples/resources/shaders/glsl100/tiling.fs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#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 colDiffuse;
|
||||
|
||||
// NOTE: Add your custom variables here
|
||||
uniform vec2 tiling;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texCoord = fragTexCoord*tiling;
|
||||
|
||||
gl_FragColor = texture2D(texture0, texCoord)*colDiffuse;
|
||||
}
|
||||
17
Examples/resources/shaders/glsl100/vertex_displacement.fs
Normal file
17
Examples/resources/shaders/glsl100/vertex_displacement.fs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from fragment shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying float height;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 darkblue = vec4(0.0, 0.13, 0.18, 1.0);
|
||||
vec4 lightblue = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
// Interpolate between two colors based on height
|
||||
vec4 finalColor = mix(darkblue, lightblue, height);
|
||||
|
||||
gl_FragColor = finalColor;
|
||||
}
|
||||
45
Examples/resources/shaders/glsl100/vertex_displacement.vs
Normal file
45
Examples/resources/shaders/glsl100/vertex_displacement.vs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec3 vertexNormal;
|
||||
attribute vec4 vertexColor;
|
||||
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
uniform mat4 matNormal;
|
||||
|
||||
uniform float time;
|
||||
|
||||
uniform sampler2D perlinNoiseMap;
|
||||
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec3 fragNormal;
|
||||
varying float height;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Calculate animated texture coordinates based on time and vertex position
|
||||
vec2 animatedTexCoord = sin(vertexTexCoord + vec2(sin(time + vertexPosition.x*0.1), cos(time + vertexPosition.z*0.1))*0.3);
|
||||
|
||||
// Normalize animated texture coordinates to range [0, 1]
|
||||
animatedTexCoord = animatedTexCoord*0.5 + 0.5;
|
||||
|
||||
// Fetch displacement from the perlin noise map
|
||||
float displacement = texture2D(perlinNoiseMap, animatedTexCoord).r*7.0; // Amplified displacement
|
||||
|
||||
// Displace vertex position
|
||||
vec3 displacedPosition = vertexPosition + vec3(0.0, displacement, 0.0);
|
||||
|
||||
// Send vertex attributes to fragment shader
|
||||
fragPosition = vec3(matModel*vec4(displacedPosition, 1.0));
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
|
||||
height = displacedPosition.y*0.2; // send height to fragment shader for coloring
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(displacedPosition, 1.0);
|
||||
}
|
||||
65
Examples/resources/shaders/glsl100/voxel_lighting.fs
Normal file
65
Examples/resources/shaders/glsl100/voxel_lighting.fs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#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;
|
||||
}
|
||||
28
Examples/resources/shaders/glsl100/voxel_lighting.vs
Normal file
28
Examples/resources/shaders/glsl100/voxel_lighting.vs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// 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);
|
||||
}
|
||||
Loading…
Reference in a new issue