Reorganize examples folder
This commit is contained in:
parent
5a230659ef
commit
dd4dd0e87d
222 changed files with 55637 additions and 663 deletions
26
examples/shaders/resources/shaders/glsl100/base.vs
Normal file
26
examples/shaders/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);
|
||||
}
|
39
examples/shaders/resources/shaders/glsl100/bloom.fs
Normal file
39
examples/shaders/resources/shaders/glsl100/bloom.fs
Normal file
|
@ -0,0 +1,39 @@
|
|||
#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 here your custom variables
|
||||
|
||||
const vec2 size = vec2(800, 450); // render size
|
||||
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
|
||||
const float quality = 2.5; // lower = smaller glow, better quality
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 sum = vec4(0);
|
||||
vec2 sizeFactor = vec2(1)/size*quality;
|
||||
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 source = texture2D(texture0, fragTexCoord);
|
||||
|
||||
const int range = 2; // should be = (samples - 1)/2;
|
||||
|
||||
for (int x = -range; x <= range; x++)
|
||||
{
|
||||
for (int y = -range; y <= range; y++)
|
||||
{
|
||||
sum += texture2D(texture0, fragTexCoord + vec2(x, y)*sizeFactor);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate final fragment color
|
||||
gl_FragColor = ((sum/(samples*samples)) + source)*colDiffuse;
|
||||
}
|
54
examples/shaders/resources/shaders/glsl100/distortion.fs
Normal file
54
examples/shaders/resources/shaders/glsl100/distortion.fs
Normal file
|
@ -0,0 +1,54 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
|
||||
// NOTE: Default parameters for Oculus Rift DK2 device
|
||||
const vec2 LeftLensCenter = vec2(0.2863248, 0.5);
|
||||
const vec2 RightLensCenter = vec2(0.7136753, 0.5);
|
||||
const vec2 LeftScreenCenter = vec2(0.25, 0.5);
|
||||
const vec2 RightScreenCenter = vec2(0.75, 0.5);
|
||||
const vec2 Scale = vec2(0.25, 0.45);
|
||||
const vec2 ScaleIn = vec2(4.0, 2.5);
|
||||
const vec4 HmdWarpParam = vec4(1.0, 0.22, 0.24, 0.0);
|
||||
const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0);
|
||||
|
||||
void main()
|
||||
{
|
||||
// The following two variables need to be set per eye
|
||||
vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter;
|
||||
vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter;
|
||||
|
||||
// Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter)
|
||||
vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1]
|
||||
float rSq = theta.x*theta.x + theta.y*theta.y;
|
||||
vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq);
|
||||
//vec2 tc = LensCenter + Scale*theta1;
|
||||
|
||||
// Detect whether blue texture coordinates are out of range since these will scaled out the furthest
|
||||
vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq);
|
||||
vec2 tcBlue = LensCenter + Scale*thetaBlue;
|
||||
|
||||
if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
else
|
||||
{
|
||||
// Do blue texture lookup
|
||||
float blue = texture2D(texture0, tcBlue).b;
|
||||
|
||||
// Do green lookup (no scaling)
|
||||
vec2 tcGreen = LensCenter + Scale*theta1;
|
||||
float green = texture2D(texture0, tcGreen).g;
|
||||
|
||||
// Do red scale and lookup
|
||||
vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq);
|
||||
vec2 tcRed = LensCenter + Scale*thetaRed;
|
||||
float red = texture2D(texture0, tcRed).r;
|
||||
|
||||
gl_FragColor = vec4(red, green, blue, 1.0);
|
||||
}
|
||||
}
|
25
examples/shaders/resources/shaders/glsl100/grayscale.fs
Normal file
25
examples/shaders/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 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*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);
|
||||
}
|
152
examples/shaders/resources/shaders/glsl100/standard.fs
Normal file
152
examples/shaders/resources/shaders/glsl100/standard.fs
Normal file
|
@ -0,0 +1,152 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
varying vec3 fragNormal;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
|
||||
uniform vec4 colAmbient;
|
||||
uniform vec4 colDiffuse;
|
||||
uniform vec4 colSpecular;
|
||||
uniform float glossiness;
|
||||
|
||||
uniform int useNormal;
|
||||
uniform int useSpecular;
|
||||
|
||||
uniform mat4 modelMatrix;
|
||||
uniform vec3 viewDir;
|
||||
|
||||
struct Light {
|
||||
int enabled;
|
||||
int type;
|
||||
vec3 position;
|
||||
vec3 direction;
|
||||
vec4 diffuse;
|
||||
float intensity;
|
||||
float radius;
|
||||
float coneAngle;
|
||||
};
|
||||
|
||||
const int maxLights = 8;
|
||||
uniform Light lights[maxLights];
|
||||
|
||||
vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s)
|
||||
{
|
||||
vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1.0));
|
||||
vec3 surfaceToLight = l.position - surfacePos;
|
||||
|
||||
// Diffuse shading
|
||||
float brightness = clamp(float(dot(n, surfaceToLight)/(length(surfaceToLight)*length(n))), 0.0, 1.0);
|
||||
float diff = 1.0/dot(surfaceToLight/l.radius, surfaceToLight/l.radius)*brightness*l.intensity;
|
||||
|
||||
// Specular shading
|
||||
float spec = 0.0;
|
||||
if (diff > 0.0)
|
||||
{
|
||||
vec3 h = normalize(-l.direction + v);
|
||||
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||
}
|
||||
|
||||
return (diff*l.diffuse.rgb + spec*colSpecular.rgb);
|
||||
}
|
||||
|
||||
vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s)
|
||||
{
|
||||
vec3 lightDir = normalize(-l.direction);
|
||||
|
||||
// Diffuse shading
|
||||
float diff = clamp(float(dot(n, lightDir)), 0.0, 1.0)*l.intensity;
|
||||
|
||||
// Specular shading
|
||||
float spec = 0.0;
|
||||
if (diff > 0.0)
|
||||
{
|
||||
vec3 h = normalize(lightDir + v);
|
||||
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||
}
|
||||
|
||||
// Combine results
|
||||
return (diff*l.intensity*l.diffuse.rgb + spec*colSpecular.rgb);
|
||||
}
|
||||
|
||||
vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s)
|
||||
{
|
||||
vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1));
|
||||
vec3 lightToSurface = normalize(surfacePos - l.position);
|
||||
vec3 lightDir = normalize(-l.direction);
|
||||
|
||||
// Diffuse shading
|
||||
float diff = clamp(float(dot(n, lightDir)), 0.0, 1.0)*l.intensity;
|
||||
|
||||
// Spot attenuation
|
||||
float attenuation = clamp(float(dot(n, lightToSurface)), 0.0, 1.0);
|
||||
attenuation = dot(lightToSurface, -lightDir);
|
||||
|
||||
float lightToSurfaceAngle = degrees(acos(attenuation));
|
||||
if (lightToSurfaceAngle > l.coneAngle) attenuation = 0.0;
|
||||
|
||||
float falloff = (l.coneAngle - lightToSurfaceAngle)/l.coneAngle;
|
||||
|
||||
// Combine diffuse and attenuation
|
||||
float diffAttenuation = diff*attenuation;
|
||||
|
||||
// Specular shading
|
||||
float spec = 0.0;
|
||||
if (diffAttenuation > 0.0)
|
||||
{
|
||||
vec3 h = normalize(lightDir + v);
|
||||
spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;
|
||||
}
|
||||
|
||||
return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// Calculate fragment normal in screen space
|
||||
// NOTE: important to multiply model matrix by fragment normal to apply model transformation (rotation and scale)
|
||||
mat3 normalMatrix = mat3(modelMatrix);
|
||||
vec3 normal = normalize(normalMatrix*fragNormal);
|
||||
|
||||
// Normalize normal and view direction vectors
|
||||
vec3 n = normalize(normal);
|
||||
vec3 v = normalize(viewDir);
|
||||
|
||||
// Calculate diffuse texture color fetching
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
vec3 lighting = colAmbient.rgb;
|
||||
|
||||
// Calculate normal texture color fetching or set to maximum normal value by default
|
||||
if (useNormal == 1)
|
||||
{
|
||||
n *= texture2D(texture1, fragTexCoord).rgb;
|
||||
n = normalize(n);
|
||||
}
|
||||
|
||||
// Calculate specular texture color fetching or set to maximum specular value by default
|
||||
float spec = 1.0;
|
||||
if (useSpecular == 1) spec = texture2D(texture2, fragTexCoord).r;
|
||||
|
||||
for (int i = 0; i < maxLights; i++)
|
||||
{
|
||||
// Check if light is enabled
|
||||
if (lights[i].enabled == 1)
|
||||
{
|
||||
// Calculate lighting based on light type
|
||||
if(lights[i].type == 0) lighting += ComputeLightPoint(lights[i], n, v, spec);
|
||||
else if(lights[i].type == 1) lighting += ComputeLightDirectional(lights[i], n, v, spec);
|
||||
else if(lights[i].type == 2) lighting += ComputeLightSpot(lights[i], n, v, spec);
|
||||
|
||||
// NOTE: It seems that too many ComputeLight*() operations inside for loop breaks the shader on RPI
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate final fragment color
|
||||
gl_FragColor = vec4(texelColor.rgb*lighting*colDiffuse.rgb, texelColor.a*colDiffuse.a);
|
||||
}
|
23
examples/shaders/resources/shaders/glsl100/standard.vs
Normal file
23
examples/shaders/resources/shaders/glsl100/standard.vs
Normal file
|
@ -0,0 +1,23 @@
|
|||
#version 100
|
||||
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec3 vertexNormal;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec4 vertexColor;
|
||||
|
||||
varying vec3 fragPosition;
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
varying vec3 fragNormal;
|
||||
|
||||
uniform mat4 mvpMatrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragPosition = vertexPosition;
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
fragNormal = vertexNormal;
|
||||
|
||||
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||
}
|
45
examples/shaders/resources/shaders/glsl100/swirl.fs
Normal file
45
examples/shaders/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 colDiffuse;
|
||||
|
||||
// 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;
|
||||
|
||||
void main()
|
||||
{
|
||||
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;
|
||||
vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
|
||||
|
||||
gl_FragColor = vec4(color.rgb, 1.0);;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue