Raylib 6.0 bugs after tests (#338)
* Sync of all the shaders from upstream + LoadFontData did not match anymore with C and crashed on MacOS * Updated JuliaSet demo. Did not work with the new shader version. * Removed unused `pause` variable from JuliaSet example. --------- Co-authored-by: Meatcorps <info@meatcorps.nl>
This commit is contained in:
parent
21d83c60a9
commit
8daf812930
83 changed files with 823 additions and 815 deletions
|
|
@ -41,6 +41,10 @@ public class JuliaSet
|
|||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
const float zoomSpeed = 1.01f;
|
||||
const float offsetSpeedMul = 2.0f;
|
||||
|
||||
const float startingZoom = 0.75f;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - julia sets");
|
||||
|
||||
|
|
@ -48,14 +52,15 @@ public class JuliaSet
|
|||
// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
|
||||
Shader shader = LoadShader(null, $"resources/shaders/glsl{GlslVersion}/julia_set.fs");
|
||||
|
||||
// Create a RenderTexture2D to be used for render to texture
|
||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||
|
||||
// c constant to use in z^2 + c
|
||||
float[] c = { PointsOfInterest[0][0], PointsOfInterest[0][1] };
|
||||
|
||||
// Offset and zoom to draw the julia set at. (centered on screen and default size)
|
||||
float[] offset = { -(float)screenWidth / 2, -(float)screenHeight / 2 };
|
||||
float zoom = 1.0f;
|
||||
|
||||
Vector2 offsetSpeed = new(0.0f, 0.0f);
|
||||
float[] offset = { 0, 0 };
|
||||
float zoom = startingZoom;
|
||||
|
||||
// Get variable (uniform) locations on the shader to connect with the program
|
||||
// NOTE: If uniform variable could not be found in the shader, function returns -1
|
||||
|
|
@ -63,28 +68,15 @@ public class JuliaSet
|
|||
int zoomLoc = GetShaderLocation(shader, "zoom");
|
||||
int offsetLoc = GetShaderLocation(shader, "offset");
|
||||
|
||||
// Tell the shader what the screen dimensions, zoom, offset and c are
|
||||
float[] screenDims = { (float)screenWidth, (float)screenHeight };
|
||||
Raylib.SetShaderValue(
|
||||
shader,
|
||||
GetShaderLocation(shader, "screenDims"),
|
||||
screenDims,
|
||||
ShaderUniformDataType.Vec2
|
||||
);
|
||||
|
||||
// Upload the shader uniform values!
|
||||
Raylib.SetShaderValue(shader, cLoc, c, ShaderUniformDataType.Vec2);
|
||||
Raylib.SetShaderValue(shader, zoomLoc, zoomLoc, ShaderUniformDataType.Float);
|
||||
Raylib.SetShaderValue(shader, zoomLoc, zoom, ShaderUniformDataType.Float);
|
||||
Raylib.SetShaderValue(shader, offsetLoc, offset, ShaderUniformDataType.Vec2);
|
||||
|
||||
// Create a RenderTexture2D to be used for render to texture
|
||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||
|
||||
// Multiplier of speed to change c value
|
||||
int incrementSpeed = 0;
|
||||
// Show controls
|
||||
bool showControls = true;
|
||||
// Pause animation
|
||||
bool pause = false;
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
|
@ -136,10 +128,19 @@ public class JuliaSet
|
|||
Raylib.SetShaderValue(shader, cLoc, c, ShaderUniformDataType.Vec2);
|
||||
}
|
||||
|
||||
if (IsKeyPressed(KeyboardKey.R))
|
||||
{
|
||||
zoom = startingZoom;
|
||||
offset[0] = 1f;
|
||||
offset[1] = 1f;
|
||||
Raylib.SetShaderValue(shader, zoomLoc, zoom, ShaderUniformDataType.Float);
|
||||
Raylib.SetShaderValue(shader, offsetLoc, offset, ShaderUniformDataType.Vec2);
|
||||
}
|
||||
|
||||
// Pause animation (c change)
|
||||
if (IsKeyPressed(KeyboardKey.Space))
|
||||
{
|
||||
pause = !pause;
|
||||
incrementSpeed = 0;
|
||||
}
|
||||
|
||||
// Toggle whether or not to show controls
|
||||
|
|
@ -148,8 +149,6 @@ public class JuliaSet
|
|||
showControls = !showControls;
|
||||
}
|
||||
|
||||
if (!pause)
|
||||
{
|
||||
if (IsKeyPressed(KeyboardKey.Right))
|
||||
{
|
||||
incrementSpeed++;
|
||||
|
|
@ -159,36 +158,32 @@ public class JuliaSet
|
|||
incrementSpeed--;
|
||||
}
|
||||
|
||||
// TODO: The idea is to zoom and move around with mouse
|
||||
// Probably offset movement should be proportional to zoom level
|
||||
// If either left or right button is pressed, zoom in/out
|
||||
if (IsMouseButtonDown(MouseButton.Left) || IsMouseButtonDown(MouseButton.Right))
|
||||
{
|
||||
if (IsMouseButtonDown(MouseButton.Left))
|
||||
{
|
||||
zoom += zoom * 0.003f;
|
||||
zoom *= zoomSpeed;
|
||||
}
|
||||
|
||||
if (IsMouseButtonDown(MouseButton.Right))
|
||||
{
|
||||
zoom -= zoom * 0.003f;
|
||||
zoom *= 1.0f / zoomSpeed;
|
||||
}
|
||||
|
||||
Vector2 mousePos = GetMousePosition();
|
||||
Vector2 offsetVelocity = Vector2.Zero;
|
||||
|
||||
offsetSpeed.X = mousePos.X - (float)screenWidth / 2;
|
||||
offsetSpeed.Y = mousePos.Y - (float)screenHeight / 2;
|
||||
offsetVelocity.X = (mousePos.X / screenWidth - 0.5f) * offsetSpeedMul / zoom;
|
||||
offsetVelocity.Y = (mousePos.Y / screenHeight - 0.5f) * offsetSpeedMul / zoom;
|
||||
|
||||
// Slowly move camera to targetOffset
|
||||
offset[0] += GetFrameTime() * offsetSpeed.X * 0.8f;
|
||||
offset[1] += GetFrameTime() * offsetSpeed.Y * 0.8f;
|
||||
}
|
||||
else
|
||||
{
|
||||
offsetSpeed = new Vector2(0.0f, 0.0f);
|
||||
}
|
||||
// Apply move velocity to camera
|
||||
offset[0] += GetFrameTime() * offsetVelocity.X;
|
||||
offset[1] += GetFrameTime() * offsetVelocity.Y;
|
||||
|
||||
Raylib.SetShaderValue(shader, zoomLoc, zoom, ShaderUniformDataType.Float);
|
||||
Raylib.SetShaderValue(shader, offsetLoc, offset, ShaderUniformDataType.Vec2);
|
||||
}
|
||||
|
||||
// Increment c value with time
|
||||
float amount = GetFrameTime() * incrementSpeed * 0.0005f;
|
||||
|
|
@ -196,13 +191,6 @@ public class JuliaSet
|
|||
c[1] += amount;
|
||||
|
||||
Raylib.SetShaderValue(shader, cLoc, c, ShaderUniformDataType.Vec2);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(Color.Black);
|
||||
|
||||
// Using a render texture to draw Julia set
|
||||
// Enable drawing to texture
|
||||
|
|
@ -216,6 +204,11 @@ public class JuliaSet
|
|||
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Color.Black);
|
||||
EndTextureMode();
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(Color.Black);
|
||||
|
||||
// Draw the saved texture and rendered julia set with shader
|
||||
// NOTE: We do not invert texture on Y, already considered inside shader
|
||||
BeginShaderMode(shader);
|
||||
|
|
@ -229,6 +222,7 @@ public class JuliaSet
|
|||
DrawText("Press KEYS [1 - 6] to change point of interest", 10, 45, 10, Color.RayWhite);
|
||||
DrawText("Press KEY_LEFT | KEY_RIGHT to change speed", 10, 60, 10, Color.RayWhite);
|
||||
DrawText("Press KEY_SPACE to pause movement animation", 10, 75, 10, Color.RayWhite);
|
||||
DrawText("Press KEY_R to recenter the camera", 10, 90, 10, Color.RayWhite);
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class FontSdf
|
|||
|
||||
// Loading font data from memory data
|
||||
// Parameters > font size: 16, no chars array provided (0), chars count: 95 (autogenerate chars array)
|
||||
fontDefault.Glyphs = LoadFontData(fileData, (int)fileSize, 16, null, 95, FontType.Default);
|
||||
fontDefault.Glyphs = LoadFontData(fileData, (int)fileSize, 16, null, 95, FontType.Default, &fontDefault.GlyphCount);
|
||||
// Parameters > chars count: 95, font size: 16, chars padding in image: 4 px, pack method: 0 (default)
|
||||
Image atlas = GenImageFontAtlas(fontDefault.Glyphs, &fontDefault.Recs, 95, 16, 4, 0);
|
||||
fontDefault.Texture = LoadTextureFromImage(atlas);
|
||||
|
|
@ -52,7 +52,7 @@ public class FontSdf
|
|||
fontSDF.BaseSize = 16;
|
||||
fontSDF.GlyphCount = 95;
|
||||
// Parameters > font size: 16, no chars array provided (0), chars count: 0 (defaults to 95)
|
||||
fontSDF.Glyphs = LoadFontData(fileData, (int)fileSize, 16, null, 0, FontType.Sdf);
|
||||
fontSDF.Glyphs = LoadFontData(fileData, (int)fileSize, 16, null, 0, FontType.Sdf, &fontDefault.GlyphCount);
|
||||
// Parameters > chars count: 95, font size: 16, chars padding in image: 0 px, pack method: 1 (Skyline algorythm)
|
||||
atlas = GenImageFontAtlas(fontSDF.Glyphs, &fontSDF.Recs, 95, 16, 0, 1);
|
||||
fontSDF.Texture = LoadTextureFromImage(atlas);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ uniform mat4 mvp;
|
|||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
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
|
||||
const vec2 size = vec2(800, 450); // Framebuffer size
|
||||
const float samples = 5.0; // Pixels per axis; higher = bigger glow, worse performance
|
||||
const float quality = 2.5; // Defines size factor: Lower = smaller glow, better quality
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
float hatchOffsetY = 5.0;
|
||||
float lumThreshold01 = 0.9;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ float angle = 0.0;
|
|||
vec2 VectorRotateTime(vec2 v, float speed)
|
||||
{
|
||||
float time = uTime*speed;
|
||||
float localTime = fract(time); // The time domain this works on is 1 sec.
|
||||
float localTime = fract(time); // The time domain this works on is 1 sec
|
||||
|
||||
if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0;
|
||||
else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4.0*sin(2.0*PI*localTime - PI/2.0);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ precision mediump float;
|
|||
The Sieve of Eratosthenes -- a simple shader by ProfJski
|
||||
An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
|
||||
|
||||
The screen is divided into a square grid of boxes, each representing an integer value.
|
||||
Each integer is tested to see if it is a prime number. Primes are colored white.
|
||||
Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer.
|
||||
The screen is divided into a square grid of boxes, each representing an integer value
|
||||
Each integer is tested to see if it is a prime number. Primes are colored white
|
||||
Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer
|
||||
|
||||
You can change the scale variable to make a larger or smaller grid.
|
||||
Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers.
|
||||
You can change the scale variable to make a larger or smaller grid
|
||||
Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers
|
||||
|
||||
WARNING: If you make scale too large, your GPU may bog down!
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ vec4 Colorizer(float counter, float maxSize)
|
|||
void main()
|
||||
{
|
||||
vec4 color = vec4(1.0);
|
||||
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid.
|
||||
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid
|
||||
float value = scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale); // Group pixels into boxes representing integer values
|
||||
int valuei = int(value);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
const float PI = 3.1415926535;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ varying vec3 fragNormal;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#version 100
|
||||
|
||||
#extension GL_EXT_frag_depth : enable // Extension required for writing depth
|
||||
|
||||
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
||||
|
||||
varying vec2 fragTexCoord;
|
||||
|
|
@ -11,6 +13,7 @@ uniform vec4 colDiffuse;
|
|||
void main()
|
||||
{
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
|
||||
gl_FragColor = texelColor*colDiffuse*fragColor;
|
||||
gl_FragDepthEXT = gl_FragCoord.z;
|
||||
}
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
#version 100
|
||||
|
||||
#extension GL_EXT_frag_depth : enable //Extension required for writing depth
|
||||
#extension GL_OES_standard_derivatives : enable //Extension used for fwidth()
|
||||
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
||||
|
||||
#define ZERO 0
|
||||
|
||||
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
|
|
@ -17,15 +20,14 @@ uniform vec3 camPos;
|
|||
uniform vec3 camDir;
|
||||
uniform vec2 screenCenter;
|
||||
|
||||
#define ZERO 0
|
||||
|
||||
// https://learnopengl.com/Advanced-OpenGL/Depth-testing
|
||||
float CalcDepth(in vec3 rd, in float Idist){
|
||||
// SRC: https://learnopengl.com/Advanced-OpenGL/Depth-testing
|
||||
float CalcDepth(in vec3 rd, in float Idist)
|
||||
{
|
||||
float local_z = dot(normalize(camDir),rd)*Idist;
|
||||
return (1.0/(local_z) - 1.0/0.01)/(1.0/1000.0 -1.0/0.01);
|
||||
}
|
||||
|
||||
// https://iquilezles.org/articles/distfunctions/
|
||||
// SRC: https://iquilezles.org/articles/distfunctions/
|
||||
float sdHorseshoe(in vec3 p, in vec2 c, in float r, in float le, vec2 w)
|
||||
{
|
||||
p.x = abs(p.x);
|
||||
|
|
@ -57,11 +59,10 @@ float sdSixWayCutHollowSphere( vec3 p, float r, float h, float t )
|
|||
|
||||
float w = sqrt(r*r-h*h);
|
||||
|
||||
return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) :
|
||||
abs(length(q)-r) ) - t;
|
||||
return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) : abs(length(q)-r)) - t;
|
||||
}
|
||||
|
||||
// https://iquilezles.org/articles/boxfunctions
|
||||
// SRC: https://iquilezles.org/articles/boxfunctions
|
||||
vec2 iBox(in vec3 ro, in vec3 rd, in vec3 rad)
|
||||
{
|
||||
vec3 m = 1.0/rd;
|
||||
|
|
@ -69,6 +70,7 @@ vec2 iBox( in vec3 ro, in vec3 rd, in vec3 rad )
|
|||
vec3 k = abs(m)*rad;
|
||||
vec3 t1 = -n - k;
|
||||
vec3 t2 = -n + k;
|
||||
|
||||
return vec2(max(max(t1.x, t1.y), t1.z),
|
||||
min(min(t2.x, t2.y), t2.z));
|
||||
}
|
||||
|
|
@ -78,20 +80,23 @@ vec2 opU( vec2 d1, vec2 d2 )
|
|||
return (d1.x<d2.x) ? d1 : d2;
|
||||
}
|
||||
|
||||
vec2 map( in vec3 pos ){
|
||||
vec2 map(in vec3 pos)
|
||||
{
|
||||
vec2 res = vec2(sdHorseshoe(pos-vec3(-1.0,0.08, 1.0), vec2(cos(1.3),sin(1.3)), 0.2, 0.3, vec2(0.03,0.5)), 11.5) ;
|
||||
res = opU(res, vec2(sdSixWayCutHollowSphere(pos-vec3(0.0, 1.0, 0.0), 4.0, 3.5, 0.5), 4.5)) ;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// https://www.shadertoy.com/view/Xds3zN
|
||||
vec2 raycast( in vec3 ro, in vec3 rd ){
|
||||
// SRC: https://www.shadertoy.com/view/Xds3zN
|
||||
vec2 raycast(in vec3 ro, in vec3 rd)
|
||||
{
|
||||
vec2 res = vec2(-1.0,-1.0);
|
||||
|
||||
float tmin = 1.0;
|
||||
float tmax = 20.0;
|
||||
|
||||
// raytrace floor plane
|
||||
// Raytrace floor plane
|
||||
float tp1 = (-ro.y)/rd.y;
|
||||
if (tp1>0.0)
|
||||
{
|
||||
|
|
@ -253,7 +258,8 @@ vec4 render( in vec3 ro, in vec3 rd)
|
|||
return vec4(vec3(clamp(col,0.0,1.0)),t);
|
||||
}
|
||||
|
||||
vec3 CalcRayDir(vec2 nCoord){
|
||||
vec3 CalcRayDir(vec2 nCoord)
|
||||
{
|
||||
vec3 horizontal = normalize(cross(camDir,vec3(.0 , 1.0, .0)));
|
||||
vec3 vertical = normalize(cross(horizontal,camDir));
|
||||
return normalize(camDir + horizontal*nCoord.x + vertical*nCoord.y);
|
||||
|
|
@ -283,6 +289,7 @@ void main()
|
|||
color = res.xyz;
|
||||
depth = CalcDepth(rd,res.w);
|
||||
}
|
||||
|
||||
gl_FragColor = vec4(color , 1.0);
|
||||
gl_FragDepthEXT = depth;
|
||||
}
|
||||
|
|
@ -6,22 +6,19 @@ precision mediump float;
|
|||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
uniform vec2 screenDims; // Dimensions of the screen
|
||||
uniform vec2 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c
|
||||
uniform vec2 offset; // Offset of the scale.
|
||||
uniform float zoom; // Zoom of the scale.
|
||||
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
|
||||
const int MAX_ITERATIONS = 48; // Max iterations to do
|
||||
const int maxIterations = 255; // Max iterations to do.
|
||||
const float colorCycles = 1.0; // Number of times the color palette repeats.
|
||||
|
||||
// Square a complex number
|
||||
vec2 ComplexSquare(vec2 z)
|
||||
{
|
||||
return vec2(
|
||||
z.x * z.x - z.y * z.y,
|
||||
z.x * z.y * 2.0
|
||||
);
|
||||
return vec2(z.x*z.x - z.y*z.y, z.x*z.y*2.0);
|
||||
}
|
||||
|
||||
// Convert Hue Saturation Value (HSV) color into RGB
|
||||
|
|
@ -35,30 +32,32 @@ vec3 Hsv2rgb(vec3 c)
|
|||
void main()
|
||||
{
|
||||
/**********************************************************************************************
|
||||
Julia sets use a function z^2 + c, where c is a constant.
|
||||
This function is iterated until the nature of the point is determined.
|
||||
Julia sets use a function z^2 + c, where c is a constant
|
||||
This function is iterated until the nature of the point is determined
|
||||
|
||||
If the magnitude of the number becomes greater than 2, then from that point onward
|
||||
the number will get bigger and bigger, and will never get smaller (tends towards infinity).
|
||||
2^2 = 4, 4^2 = 8 and so on.
|
||||
So at 2 we stop iterating.
|
||||
the number will get bigger and bigger, and will never get smaller (tends towards infinity)
|
||||
2^2 = 4, 4^2 = 8 and so on
|
||||
So at 2 we stop iterating
|
||||
|
||||
If the number is below 2, we keep iterating.
|
||||
If the number is below 2, we keep iterating
|
||||
But when do we stop iterating if the number is always below 2 (it converges)?
|
||||
That is what MAX_ITERATIONS is for.
|
||||
Then we can divide the iterations by the MAX_ITERATIONS value to get a normalized value that we can
|
||||
then map to a color.
|
||||
That is what maxIterations is for
|
||||
Then we can divide the iterations by the maxIterations value to get a normalized value
|
||||
that we can then map to a color
|
||||
|
||||
We use dot product (z.x * z.x + z.y * z.y) to determine the magnitude (length) squared.
|
||||
And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power).
|
||||
We use dot product (z.x*z.x + z.y*z.y) to determine the magnitude (length) squared
|
||||
And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power)
|
||||
*************************************************************************************************/
|
||||
|
||||
// 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 z = vec2((fragTexCoord.x + offset.x/screenDims.x)*2.5/zoom, (fragTexCoord.y + offset.y/screenDims.y)*1.5/zoom);
|
||||
vec2 z = vec2((fragTexCoord.x - 0.5)*2.5, (fragTexCoord.y - 0.5)*1.5)/zoom;
|
||||
z.x += offset.x;
|
||||
z.y += offset.y;
|
||||
|
||||
int iter = 0;
|
||||
for (int iterations = 0; iterations < 60; iterations++)
|
||||
for (int iterations = 0; iterations < maxIterations; iterations++)
|
||||
{
|
||||
z = ComplexSquare(z) + c; // Iterate function
|
||||
if (dot(z, z) > 4.0) break;
|
||||
|
|
@ -66,18 +65,18 @@ void main()
|
|||
iter = iterations;
|
||||
}
|
||||
|
||||
// Another few iterations decreases errors in the smoothing calculation.
|
||||
// See http://linas.org/art-gallery/escape/escape.html for more information.
|
||||
// Another few iterations decreases errors in the smoothing calculation
|
||||
// See http://linas.org/art-gallery/escape/escape.html for more information
|
||||
z = ComplexSquare(z) + c;
|
||||
z = ComplexSquare(z) + c;
|
||||
|
||||
// This last part smooths the color (again see link above).
|
||||
// This last part smooths the color (again see link above)
|
||||
float smoothVal = float(iter) + 1.0 - (log(log(length(z)))/log(2.0));
|
||||
|
||||
// Normalize the value so it is between 0 and 1.
|
||||
float norm = smoothVal/float(MAX_ITERATIONS);
|
||||
// Normalize the value so it is between 0 and 1
|
||||
float norm = smoothVal/float(maxIterations);
|
||||
|
||||
// If in set, color black. 0.999 allows for some float accuracy error.
|
||||
// If in set, color black. 0.999 allows for some float accuracy error
|
||||
if (norm > 0.999) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
else gl_FragColor = vec4(Hsv2rgb(vec3(norm, 1.0, 1.0)), 1.0);
|
||||
else gl_FragColor = vec4(Hsv2rgb(vec3(norm*colorCycles, 1.0, 1.0)), 1.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,18 +12,12 @@ varying vec3 fragNormal;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
#define LIGHT_POINT 1
|
||||
|
||||
struct MaterialProperty {
|
||||
vec3 color;
|
||||
int useSampler;
|
||||
sampler2D sampler;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
int enabled;
|
||||
int type;
|
||||
|
|
@ -46,6 +40,8 @@ void main()
|
|||
vec3 viewD = normalize(viewPos - fragPosition);
|
||||
vec3 specular = vec3(0.0);
|
||||
|
||||
vec4 tint = colDiffuse*fragColor;
|
||||
|
||||
// NOTE: Implement here your fragment shader code
|
||||
|
||||
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||
|
|
@ -73,7 +69,7 @@ void main()
|
|||
}
|
||||
}
|
||||
|
||||
vec4 finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
|
||||
vec4 finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
|
||||
finalColor += texelColor*(ambient/10.0);
|
||||
|
||||
// Gamma correction
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ varying vec2 fragTexCoord;
|
|||
varying vec4 fragColor;
|
||||
varying vec3 fragNormal;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// https://github.com/glslify/glsl-inverse
|
||||
mat3 inverse(mat3 m)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ varying vec2 fragTexCoord;
|
|||
varying vec4 fragColor;
|
||||
varying vec3 fragNormal;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ uniform sampler2D mask;
|
|||
uniform vec4 colDiffuse;
|
||||
uniform int frame;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
precision mediump float;
|
||||
|
||||
const int colors = 8;
|
||||
const int MAX_INDEXED_COLORS = 8;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
|
|
@ -10,7 +10,8 @@ varying vec4 fragColor;
|
|||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform ivec3 palette[colors];
|
||||
uniform ivec3 palette[MAX_INDEXED_COLORS];
|
||||
//uniform sampler2D palette; // Alternative to ivec3, palette provided as a 256x1 texture
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
@ -18,7 +19,7 @@ void main()
|
|||
vec4 texelColor = texture2D(texture0, fragTexCoord)*fragColor;
|
||||
|
||||
// Convert the (normalized) texel color RED component (GB would work, too)
|
||||
// to the palette index by scaling up from [0, 1] to [0, 255].
|
||||
// to the palette index by scaling up from [0..1] to [0..255]
|
||||
int index = int(texelColor.r*255.0);
|
||||
|
||||
ivec3 color = ivec3(0);
|
||||
|
|
@ -34,8 +35,9 @@ void main()
|
|||
else if (index == 6) color = palette[6];
|
||||
else if (index == 7) color = palette[7];
|
||||
|
||||
//gl_FragColor = texture2D(palette, texelColor.xy); // Alternative to ivec3
|
||||
|
||||
// Calculate final fragment color. Note that the palette color components
|
||||
// are defined in the range [0, 255] and need to be normalized to [0, 1]
|
||||
// for OpenGL to work.
|
||||
// are defined in the range [0..255] and need to be normalized to [0..1]
|
||||
gl_FragColor = vec4(float(color.x)/255.0, float(color.y)/255.0, float(color.z)/255.0, texelColor.a);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
float gamma = 0.6;
|
||||
float numColors = 8.0;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
#extension GL_OES_standard_derivatives : enable
|
||||
|
||||
precision mediump float;
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
|
@ -34,11 +34,11 @@ uniform vec2 resolution;
|
|||
// SOFTWARE.
|
||||
|
||||
// A list of useful distance function to simple primitives, and an example on how to
|
||||
// do some interesting boolean operations, repetition and displacement.
|
||||
// do some interesting boolean operations, repetition and displacement
|
||||
//
|
||||
// More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
||||
|
||||
#define AA 1 // make this 1 is your machine is too slow
|
||||
#define AA 1 // make this 1 if your machine is too slow
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
float offset = 0.0;
|
||||
float frequency = 450.0/3.0;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
vec2 resolution = vec2(800.0, 450.0);
|
||||
|
||||
void main()
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values should be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
|
|
@ -42,5 +42,5 @@ void main()
|
|||
tc += center;
|
||||
vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
|
||||
|
||||
gl_FragColor = vec4(color.rgb, 1.0);;
|
||||
gl_FragColor = vec4(color.rgb, 1.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,8 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
uniform float secondes;
|
||||
|
||||
uniform float seconds;
|
||||
uniform vec2 size;
|
||||
|
||||
uniform float freqX;
|
||||
uniform float freqY;
|
||||
uniform float ampX;
|
||||
|
|
@ -21,7 +19,8 @@ uniform float ampY;
|
|||
uniform float speedX;
|
||||
uniform float speedY;
|
||||
|
||||
void main() {
|
||||
void main()
|
||||
{
|
||||
float pixelWidth = 1.0/size.x;
|
||||
float pixelHeight = 1.0/size.y;
|
||||
float aspect = pixelHeight/pixelWidth;
|
||||
|
|
@ -29,8 +28,8 @@ void main() {
|
|||
float boxTop = 0.0;
|
||||
|
||||
vec2 p = fragTexCoord;
|
||||
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth;
|
||||
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight;
|
||||
p.x += cos((fragTexCoord.y - boxTop)*freqX/(pixelWidth*750.0) + (seconds*speedX))*ampX*pixelWidth;
|
||||
p.y += sin((fragTexCoord.x - boxLeft)*freqY*aspect/(pixelHeight*750.0) + (seconds*speedY))*ampY*pixelHeight;
|
||||
|
||||
gl_FragColor = texture2D(texture0, p)*colDiffuse*fragColor;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
uniform vec2 resolution = vec2(800, 450);
|
||||
|
||||
void main()
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ uniform mat4 mvp;
|
|||
varying vec2 fragTexCoord;
|
||||
varying vec4 fragColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
const vec2 size = vec2(800, 450); // Framebuffer size
|
||||
const float samples = 5.0; // Pixels per axis; higher = bigger glow, worse performance
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
float hatchOffsetY = 5.0;
|
||||
float lumThreshold01 = 0.9;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
const float PI = 3.1415926535;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ varying vec3 fragNormal;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,18 +10,12 @@ varying vec3 fragNormal;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
#define LIGHT_POINT 1
|
||||
|
||||
struct MaterialProperty {
|
||||
vec3 color;
|
||||
int useSampler;
|
||||
sampler2D sampler;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
int enabled;
|
||||
int type;
|
||||
|
|
@ -44,6 +38,8 @@ void main()
|
|||
vec3 viewD = normalize(viewPos - fragPosition);
|
||||
vec3 specular = vec3(0.0);
|
||||
|
||||
vec4 tint = colDiffuse*fragColor;
|
||||
|
||||
// NOTE: Implement here your fragment shader code
|
||||
|
||||
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||
|
|
@ -71,7 +67,7 @@ void main()
|
|||
}
|
||||
}
|
||||
|
||||
vec4 finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
|
||||
vec4 finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
|
||||
finalColor += texelColor*(ambient/10.0);
|
||||
|
||||
// Gamma correction
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ varying vec2 fragTexCoord;
|
|||
varying vec4 fragColor;
|
||||
varying vec3 fragNormal;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// https://github.com/glslify/glsl-inverse
|
||||
mat3 inverse(mat3 m)
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ void main()
|
|||
vec4 texelColor = texture(texture0, fragTexCoord)*fragColor;
|
||||
|
||||
// Convert the (normalized) texel color RED component (GB would work, too)
|
||||
// to the palette index by scaling up from [0, 1] to [0, 255].
|
||||
// to the palette index by scaling up from [0, 1] to [0, 255]
|
||||
int index = int(texelColor.r*255.0);
|
||||
ivec3 color = palette[index];
|
||||
|
||||
// Calculate final fragment color. Note that the palette color components
|
||||
// are defined in the range [0, 255] and need to be normalized to [0, 1]
|
||||
// for OpenGL to work.
|
||||
// for OpenGL to work
|
||||
gl_FragColor = vec4(color/255.0, texelColor.a);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
float gamma = 0.6;
|
||||
float numColors = 8.0;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
float offset = 0.0;
|
||||
float frequency = 450.0/3.0;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
vec2 resolution = vec2(800.0, 450.0);
|
||||
|
||||
void main()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ varying vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values should be passed from code
|
||||
const float renderWidth = 800;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
@ -20,6 +20,9 @@ void main()
|
|||
|
||||
// NOTE: Implement here your fragment shader code
|
||||
|
||||
finalColor = texelColor*colDiffuse;
|
||||
// final color is the color from the texture
|
||||
// times the tint color (colDiffuse)
|
||||
// times the fragment color (interpolated vertex color)
|
||||
finalColor = texelColor*colDiffuse*fragColor;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ uniform mat4 mvp;
|
|||
out vec2 fragTexCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
const vec2 size = vec2(800, 450); // Framebuffer size
|
||||
const float samples = 5.0; // Pixels per axis; higher = bigger glow, worse performance
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
float hatchOffsetY = 5.0;
|
||||
float lumThreshold01 = 0.9;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800.0;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ float angle = 0.0;
|
|||
vec2 VectorRotateTime(vec2 v, float speed)
|
||||
{
|
||||
float time = uTime*speed;
|
||||
float localTime = fract(time); // The time domain this works on is 1 sec.
|
||||
float localTime = fract(time); // The time domain this works on is 1 sec
|
||||
|
||||
if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0;
|
||||
else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4*sin(2*PI*localTime - PI/2);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ out vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@
|
|||
The Sieve of Eratosthenes -- a simple shader by ProfJski
|
||||
An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
|
||||
|
||||
The screen is divided into a square grid of boxes, each representing an integer value.
|
||||
Each integer is tested to see if it is a prime number. Primes are colored white.
|
||||
Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer.
|
||||
The screen is divided into a square grid of boxes, each representing an integer value
|
||||
Each integer is tested to see if it is a prime number. Primes are colored white
|
||||
Non-primes are colored with a color that indicates the smallest factor which evenly divides our integer
|
||||
|
||||
You can change the scale variable to make a larger or smaller grid.
|
||||
Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers.
|
||||
You can change the scale variable to make a larger or smaller grid
|
||||
Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers
|
||||
|
||||
WARNING: If you make scale too large, your GPU may bog down!
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ vec4 Colorizer(float counter, float maxSize)
|
|||
void main()
|
||||
{
|
||||
vec4 color = vec4(1.0);
|
||||
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid.
|
||||
float scale = 1000.0; // Makes 100x100 square grid, change this variable to make a smaller or larger grid
|
||||
int value = int(scale*floor(fragTexCoord.y*scale)+floor(fragTexCoord.x*scale)); // Group pixels into boxes representing integer values
|
||||
|
||||
if ((value == 0) || (value == 1) || (value == 2)) finalColor = vec4(1.0);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ out vec4 fragColor;
|
|||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
const float PI = 3.1415926535;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
|
|
@ -37,6 +37,7 @@ struct Light {
|
|||
uniform Light lights[MAX_LIGHTS];
|
||||
uniform vec4 ambient;
|
||||
uniform vec3 viewPos;
|
||||
uniform vec4 fogColor;
|
||||
uniform float fogDensity;
|
||||
|
||||
void main()
|
||||
|
|
@ -77,10 +78,6 @@ void main()
|
|||
// Fog calculation
|
||||
float dist = length(viewPos - fragPosition);
|
||||
|
||||
// these could be parameters...
|
||||
const vec4 fogColor = vec4(0.5, 0.5, 0.5, 1.0);
|
||||
//const float fogDensity = 0.16;
|
||||
|
||||
// Exponential fog
|
||||
float fogFactor = 1.0/exp((dist*fogDensity)*(dist*fogDensity));
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,14 +1,22 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
gl_FragColor = texelColor*colDiffuse*fragColor;
|
||||
gl_FragDepth = gl_FragCoord.z;
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
|
||||
finalColor = texelColor*colDiffuse*fragColor;
|
||||
gl_FragDepth = finalColor.z;
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
# version 330
|
||||
|
||||
#define ZERO 0
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
|
@ -13,10 +15,12 @@ uniform vec3 camPos;
|
|||
uniform vec3 camDir;
|
||||
uniform vec2 screenCenter;
|
||||
|
||||
#define ZERO 0
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// https://learnopengl.com/Advanced-OpenGL/Depth-testing
|
||||
float CalcDepth(in vec3 rd, in float Idist){
|
||||
float CalcDepth(in vec3 rd, in float Idist)
|
||||
{
|
||||
float local_z = dot(normalize(camDir),rd)*Idist;
|
||||
return (1.0/(local_z) - 1.0/0.01)/(1.0/1000.0 -1.0/0.01);
|
||||
}
|
||||
|
|
@ -26,10 +30,8 @@ float sdHorseshoe( in vec3 p, in vec2 c, in float r, in float le, vec2 w )
|
|||
{
|
||||
p.x = abs(p.x);
|
||||
float l = length(p.xy);
|
||||
p.xy = mat2(-c.x, c.y,
|
||||
c.y, c.x)*p.xy;
|
||||
p.xy = vec2((p.y>0.0 || p.x>0.0)?p.x:l*sign(-c.x),
|
||||
(p.x>0.0)?p.y:l );
|
||||
p.xy = mat2(-c.x, c.y, c.y, c.x)*p.xy;
|
||||
p.xy = vec2(((p.y > 0.0) || (p.x > 0.0))? p.x : l*sign(-c.x), (p.x>0.0)? p.y : l);
|
||||
p.xy = vec2(p.x, abs(p.y - r)) - vec2(le, 0.0);
|
||||
|
||||
vec2 q = vec2(length(max(p.xy, 0.0)) + min(0.0, max(p.x, p.y)), p.z);
|
||||
|
|
@ -44,17 +46,16 @@ float sdSixWayCutHollowSphere( vec3 p, float r, float h, float t )
|
|||
{
|
||||
// Six way symetry Transformation
|
||||
vec3 ap = abs(p);
|
||||
if(ap.x < max(ap.y, ap.z)){
|
||||
if (ap.x < max(ap.y, ap.z))
|
||||
{
|
||||
if (ap.y < ap.z) ap.xz = ap.zx;
|
||||
else ap.xy = ap.yx;
|
||||
}
|
||||
|
||||
vec2 q = vec2(length(ap.yz), ap.x);
|
||||
|
||||
float w = sqrt(r*r-h*h);
|
||||
|
||||
return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) :
|
||||
abs(length(q)-r) ) - t;
|
||||
return ((h*q.x < w*q.y)? length(q - vec2(w, h)) : abs(length(q) - r)) - t;
|
||||
}
|
||||
|
||||
// https://iquilezles.org/articles/boxfunctions
|
||||
|
|
@ -65,8 +66,8 @@ vec2 iBox( in vec3 ro, in vec3 rd, in vec3 rad )
|
|||
vec3 k = abs(m)*rad;
|
||||
vec3 t1 = -n - k;
|
||||
vec3 t2 = -n + k;
|
||||
return vec2( max( max( t1.x, t1.y ), t1.z ),
|
||||
min( min( t2.x, t2.y ), t2.z ) );
|
||||
|
||||
return vec2(max(max(t1.x, t1.y), t1.z), min(min(t2.x, t2.y), t2.z));
|
||||
}
|
||||
|
||||
vec2 opU(vec2 d1, vec2 d2)
|
||||
|
|
@ -74,14 +75,17 @@ vec2 opU( vec2 d1, vec2 d2 )
|
|||
return (d1.x < d2.x)? d1 : d2;
|
||||
}
|
||||
|
||||
vec2 map( in vec3 pos ){
|
||||
vec2 map(in vec3 pos)
|
||||
{
|
||||
vec2 res = vec2(sdHorseshoe(pos - vec3(-1.0, 0.08, 1.0), vec2(cos(1.3), sin(1.3)), 0.2, 0.3, vec2(0.03,0.5)), 11.5);
|
||||
res = opU(res, vec2(sdSixWayCutHollowSphere(pos-vec3(0.0, 1.0, 0.0), 4.0, 3.5, 0.5), 4.5));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// https://www.shadertoy.com/view/Xds3zN
|
||||
vec2 raycast( in vec3 ro, in vec3 rd ){
|
||||
vec2 raycast(in vec3 ro, in vec3 rd)
|
||||
{
|
||||
vec2 res = vec2(-1.0, -1.0);
|
||||
|
||||
float tmin = 1.0;
|
||||
|
|
@ -111,7 +115,6 @@ vec2 raycast( in vec3 ro, in vec3 rd ){
|
|||
return res;
|
||||
}
|
||||
|
||||
|
||||
// https://iquilezles.org/articles/rmshadows
|
||||
float calcSoftshadow(in vec3 ro, in vec3 rd, in float mint, in float tmax)
|
||||
{
|
||||
|
|
@ -126,12 +129,13 @@ float calcSoftshadow( in vec3 ro, in vec3 rd, in float mint, in float tmax )
|
|||
float s = clamp(8.0*h/t, 0.0, 1.0);
|
||||
res = min(res, s);
|
||||
t += clamp(h, 0.01, 0.2);
|
||||
if( res<0.004 || t>tmax ) break;
|
||||
}
|
||||
res = clamp( res, 0.0, 1.0 );
|
||||
return res*res*(3.0-2.0*res);
|
||||
if ((res < 0.004) || (t > tmax)) break;
|
||||
}
|
||||
|
||||
res = clamp(res, 0.0, 1.0);
|
||||
|
||||
return res*res*(3.0-2.0*res);
|
||||
}
|
||||
|
||||
// https://iquilezles.org/articles/normalsSDF
|
||||
vec3 calcNormal(in vec3 pos)
|
||||
|
|
@ -156,6 +160,7 @@ float calcAO( in vec3 pos, in vec3 nor )
|
|||
sca *= 0.95;
|
||||
if (occ>0.35) break;
|
||||
}
|
||||
|
||||
return clamp(1.0 - 3.0*occ, 0.0, 1.0)*(0.5+0.5*nor.y);
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +172,7 @@ float checkersGradBox( in vec2 p )
|
|||
// analytical integral (box filter)
|
||||
vec2 i = 2.0*(abs(fract((p - 0.5*w)*0.5)-0.5) - abs(fract((p + 0.5*w)*0.5) - 0.5))/w;
|
||||
// xor pattern
|
||||
return 0.5 - 0.5*i.x*i.y;
|
||||
return (0.5 - 0.5*i.x*i.y);
|
||||
}
|
||||
|
||||
// https://www.shadertoy.com/view/tdS3DG
|
||||
|
|
@ -249,7 +254,8 @@ vec4 render( in vec3 ro, in vec3 rd)
|
|||
return vec4(vec3(clamp(col,0.0,1.0)),t);
|
||||
}
|
||||
|
||||
vec3 CalcRayDir(vec2 nCoord){
|
||||
vec3 CalcRayDir(vec2 nCoord)
|
||||
{
|
||||
vec3 horizontal = normalize(cross(camDir,vec3(.0 , 1.0, .0)));
|
||||
vec3 vertical = normalize(cross(horizontal,camDir));
|
||||
return normalize(camDir + horizontal*nCoord.x + vertical*nCoord.y);
|
||||
|
|
@ -279,6 +285,7 @@ void main()
|
|||
color = res.xyz;
|
||||
depth = CalcDepth(rd,res.w);
|
||||
}
|
||||
gl_FragColor = vec4(color , 1.0);
|
||||
|
||||
finalColor = vec4(color , 1.0);
|
||||
gl_FragDepth = depth;
|
||||
}
|
||||
|
|
@ -7,20 +7,17 @@ in vec4 fragColor;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
uniform vec2 screenDims; // Dimensions of the screen
|
||||
uniform vec2 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c
|
||||
uniform vec2 offset; // Offset of the scale.
|
||||
uniform float zoom; // Zoom of the scale.
|
||||
uniform vec2 offset; // Offset of the scale
|
||||
uniform float zoom; // Zoom of the scale
|
||||
|
||||
const int MAX_ITERATIONS = 255; // Max iterations to do.
|
||||
const int maxIterations = 255; // Max iterations to do
|
||||
const float colorCycles = 2.0; // Number of times the color palette repeats. Can show higher detail for higher iteration numbers
|
||||
|
||||
// Square a complex number
|
||||
vec2 ComplexSquare(vec2 z)
|
||||
{
|
||||
return vec2(
|
||||
z.x * z.x - z.y * z.y,
|
||||
z.x * z.y * 2.0
|
||||
);
|
||||
return vec2(z.x*z.x - z.y*z.y, z.x*z.y*2.0);
|
||||
}
|
||||
|
||||
// Convert Hue Saturation Value (HSV) color into RGB
|
||||
|
|
@ -34,48 +31,50 @@ vec3 Hsv2rgb(vec3 c)
|
|||
void main()
|
||||
{
|
||||
/**********************************************************************************************
|
||||
Julia sets use a function z^2 + c, where c is a constant.
|
||||
This function is iterated until the nature of the point is determined.
|
||||
Julia sets use a function z^2 + c, where c is a constant
|
||||
This function is iterated until the nature of the point is determined
|
||||
|
||||
If the magnitude of the number becomes greater than 2, then from that point onward
|
||||
the number will get bigger and bigger, and will never get smaller (tends towards infinity).
|
||||
2^2 = 4, 4^2 = 8 and so on.
|
||||
So at 2 we stop iterating.
|
||||
the number will get bigger and bigger, and will never get smaller (tends towards infinity)
|
||||
2^2 = 4, 4^2 = 8 and so on
|
||||
So at 2 we stop iterating
|
||||
|
||||
If the number is below 2, we keep iterating.
|
||||
If the number is below 2, we keep iterating
|
||||
But when do we stop iterating if the number is always below 2 (it converges)?
|
||||
That is what MAX_ITERATIONS is for.
|
||||
Then we can divide the iterations by the MAX_ITERATIONS value to get a normalized value that we can
|
||||
then map to a color.
|
||||
That is what maxIterations is for
|
||||
Then we can divide the iterations by the maxIterations value to get a normalized value
|
||||
that we can then map to a color
|
||||
|
||||
We use dot product (z.x * z.x + z.y * z.y) to determine the magnitude (length) squared.
|
||||
And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power).
|
||||
We use dot product (z.x*z.x + z.y*z.y) to determine the magnitude (length) squared
|
||||
And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power)
|
||||
*************************************************************************************************/
|
||||
|
||||
// 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 z = vec2((fragTexCoord.x + offset.x/screenDims.x)*2.5/zoom, (fragTexCoord.y + offset.y/screenDims.y)*1.5/zoom);
|
||||
vec2 z = vec2((fragTexCoord.x - 0.5f)*2.5, (fragTexCoord.y - 0.5)*1.5)/zoom;
|
||||
z.x += offset.x;
|
||||
z.y += offset.y;
|
||||
|
||||
int iterations = 0;
|
||||
for (iterations = 0; iterations < MAX_ITERATIONS; iterations++)
|
||||
for (iterations = 0; iterations < maxIterations; iterations++)
|
||||
{
|
||||
z = ComplexSquare(z) + c; // Iterate function
|
||||
|
||||
if (dot(z, z) > 4.0) break;
|
||||
}
|
||||
|
||||
// Another few iterations decreases errors in the smoothing calculation.
|
||||
// See http://linas.org/art-gallery/escape/escape.html for more information.
|
||||
// Another few iterations decreases errors in the smoothing calculation
|
||||
// See http://linas.org/art-gallery/escape/escape.html for more information
|
||||
z = ComplexSquare(z) + c;
|
||||
z = ComplexSquare(z) + c;
|
||||
|
||||
// This last part smooths the color (again see link above).
|
||||
// This last part smooths the color (again see link above)
|
||||
float smoothVal = float(iterations) + 1.0 - (log(log(length(z)))/log(2.0));
|
||||
|
||||
// Normalize the value so it is between 0 and 1.
|
||||
float norm = smoothVal/float(MAX_ITERATIONS);
|
||||
// Normalize the value so it is between 0 and 1
|
||||
float norm = smoothVal/float(maxIterations);
|
||||
|
||||
// If in set, color black. 0.999 allows for some float accuracy error.
|
||||
// If in set, color black. 0.999 allows for some float accuracy error
|
||||
if (norm > 0.999) finalColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
else finalColor = vec4(Hsv2rgb(vec3(norm, 1.0, 1.0)), 1.0);
|
||||
else finalColor = vec4(Hsv2rgb(vec3(norm*colorCycles, 1.0, 1.0)), 1.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
// Input vertex attributes (from vertex shader)
|
||||
in vec3 fragPosition;
|
||||
in vec2 fragTexCoord;
|
||||
//in vec4 fragColor;
|
||||
in vec4 fragColor;
|
||||
in vec3 fragNormal;
|
||||
|
||||
// Input uniform values
|
||||
|
|
@ -13,18 +13,12 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
#define LIGHT_POINT 1
|
||||
|
||||
struct MaterialProperty {
|
||||
vec3 color;
|
||||
int useSampler;
|
||||
sampler2D sampler;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
int enabled;
|
||||
int type;
|
||||
|
|
@ -47,6 +41,8 @@ void main()
|
|||
vec3 viewD = normalize(viewPos - fragPosition);
|
||||
vec3 specular = vec3(0.0);
|
||||
|
||||
vec4 tint = colDiffuse*fragColor;
|
||||
|
||||
// NOTE: Implement here your fragment shader code
|
||||
|
||||
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||
|
|
@ -74,8 +70,8 @@ void main()
|
|||
}
|
||||
}
|
||||
|
||||
finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
|
||||
finalColor += texelColor*(ambient/10.0)*colDiffuse;
|
||||
finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
|
||||
finalColor += texelColor*(ambient/10.0)*tint;
|
||||
|
||||
// Gamma correction
|
||||
finalColor = pow(finalColor, vec4(1.0/2.2));
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ out vec2 fragTexCoord;
|
|||
out vec4 fragColor;
|
||||
out vec3 fragNormal;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,19 +18,16 @@ out vec2 fragTexCoord;
|
|||
out vec4 fragColor;
|
||||
out vec3 fragNormal;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
// Compute MVP for current instance
|
||||
mat4 mvpi = mvp*instanceTransform;
|
||||
|
||||
// Send vertex attributes to fragment shader
|
||||
fragPosition = vec3(mvpi*vec4(vertexPosition, 1.0));
|
||||
fragPosition = vec3(instanceTransform*vec4(vertexPosition, 1.0));
|
||||
fragTexCoord = vertexTexCoord;
|
||||
//fragColor = vertexColor;
|
||||
fragColor = vec4(1.0);
|
||||
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvpi*vec4(vertexPosition, 1.0);
|
||||
// Calculate final vertex position, note that we multiply mvp by instanceTransform
|
||||
gl_Position = mvp*instanceTransform*vec4(vertexPosition, 1.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#version 330
|
||||
|
||||
const int colors = 8;
|
||||
const int MAX_INDEXED_COLORS = 8;
|
||||
|
||||
// Input fragment attributes (from fragment shader)
|
||||
in vec2 fragTexCoord;
|
||||
|
|
@ -8,7 +8,8 @@ in vec4 fragColor;
|
|||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform ivec3 palette[colors];
|
||||
uniform ivec3 palette[MAX_INDEXED_COLORS];
|
||||
//uniform sampler2D palette; // Alternative to ivec3, palette provided as a 256x1 texture
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
|
@ -16,15 +17,17 @@ out vec4 finalColor;
|
|||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
// NOTE: The texel is actually the GRAYSCALE index color
|
||||
vec4 texelColor = texture(texture0, fragTexCoord)*fragColor;
|
||||
|
||||
// Convert the (normalized) texel color RED component (GB would work, too)
|
||||
// to the palette index by scaling up from [0, 1] to [0, 255].
|
||||
// to the palette index by scaling up from [0..1] to [0..255]
|
||||
int index = int(texelColor.r*255.0);
|
||||
ivec3 color = palette[index];
|
||||
|
||||
//finalColor = texture(palette, texelColor.xy); // Alternative to ivec3
|
||||
|
||||
// Calculate final fragment color. Note that the palette color components
|
||||
// are defined in the range [0, 255] and need to be normalized to [0, 1]
|
||||
// for OpenGL to work.
|
||||
// are defined in the range [0..255] and need to be normalized to [0..1]
|
||||
finalColor = vec4(color/255.0, texelColor.a);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ 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);
|
||||
return (a/max(d,0.0000001));
|
||||
}
|
||||
|
||||
float GeomSmith(float nDotV,float nDotL,float roughness)
|
||||
|
|
@ -91,7 +91,7 @@ vec3 ComputePBR()
|
|||
|
||||
if (useTexMRA == 1)
|
||||
{
|
||||
vec4 mra = texture(mraMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y))*useTexMRA;
|
||||
vec4 mra = texture(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;
|
||||
|
|
@ -111,7 +111,7 @@ vec3 ComputePBR()
|
|||
emissive = (texture(emissiveMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y)).rgb).g*emissiveColor.rgb*emissivePower*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
|
||||
// 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
|
||||
|
||||
|
|
@ -145,7 +145,7 @@ vec3 ComputePBR()
|
|||
|
||||
vec3 ambientFinal = (ambientColor + albedo)*ambient*0.5;
|
||||
|
||||
return ambientFinal + lightAccum*ao + emissive;
|
||||
return (ambientFinal + lightAccum*ao + emissive);
|
||||
}
|
||||
|
||||
void main()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
in vec3 vertexTangent;
|
||||
in vec4 vertexTangent;
|
||||
in vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
|
|
@ -26,17 +26,17 @@ const float normalOffset = 0.1;
|
|||
void main()
|
||||
{
|
||||
// Compute binormal from vertex normal and tangent
|
||||
vec3 vertexBinormal = cross(vertexNormal, vertexTangent);
|
||||
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.0f));
|
||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
|
||||
|
||||
fragTexCoord = vertexTexCoord*2.0;
|
||||
fragNormal = normalize(normalMatrix*vertexNormal);
|
||||
vec3 fragTangent = normalize(normalMatrix*vertexTangent);
|
||||
vec3 fragTangent = normalize(normalMatrix*vertexTangent.xyz);
|
||||
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
|
||||
vec3 fragBinormal = normalize(normalMatrix*vertexBinormal);
|
||||
fragBinormal = cross(fragNormal, fragTangent);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
float gamma = 0.6;
|
||||
float numColors = 8.0;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ uniform vec2 resolution;
|
|||
// SOFTWARE.
|
||||
|
||||
// A list of useful distance function to simple primitives, and an example on how to
|
||||
// do some interesting boolean operations, repetition and displacement.
|
||||
// do some interesting boolean operations, repetition and displacement
|
||||
//
|
||||
// More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values must be passed from code
|
||||
const float renderWidth = 800;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
uniform vec2 resolution = vec2(800, 450);
|
||||
|
||||
void main()
|
||||
|
|
@ -20,22 +20,22 @@ void main()
|
|||
float y = 1.0/resolution.y;
|
||||
|
||||
vec4 horizEdge = vec4(0.0);
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
|
||||
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
|
||||
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
horizEdge -= texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge -= texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
|
||||
horizEdge -= texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
horizEdge += texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
horizEdge += texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
|
||||
horizEdge += texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec4 vertEdge = vec4(0.0);
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
|
||||
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
|
||||
vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
vertEdge -= texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge -= texture(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
|
||||
vertEdge -= texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
|
||||
vertEdge += texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
|
||||
vertEdge += texture(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
|
||||
vertEdge += texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
|
||||
|
||||
vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
|
||||
|
||||
finalColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
|
||||
finalColor = vec4(edge, texture(texture0, fragTexCoord).a);
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ in vec4 fragColor;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
#define MAX_SPOTS 3
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// NOTE: Add here your custom variables
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
// NOTE: Render size values should be passed from code
|
||||
const float renderWidth = 800;
|
||||
|
|
@ -41,7 +41,7 @@ void main()
|
|||
}
|
||||
|
||||
tc += center;
|
||||
vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
|
||||
vec4 color = texture(texture0, tc/texSize)*colDiffuse*fragColor;;
|
||||
|
||||
finalColor = vec4(color.rgb, 1.0);;
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ uniform vec4 colDiffuse;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
uniform float secondes;
|
||||
uniform float seconds;
|
||||
|
||||
uniform vec2 size;
|
||||
|
||||
|
|
@ -22,7 +22,8 @@ uniform float ampY;
|
|||
uniform float speedX;
|
||||
uniform float speedY;
|
||||
|
||||
void main() {
|
||||
void main()
|
||||
{
|
||||
float pixelWidth = 1.0/size.x;
|
||||
float pixelHeight = 1.0/size.y;
|
||||
float aspect = pixelHeight/pixelWidth;
|
||||
|
|
@ -30,8 +31,8 @@ void main() {
|
|||
float boxTop = 0.0;
|
||||
|
||||
vec2 p = fragTexCoord;
|
||||
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth;
|
||||
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight;
|
||||
p.x += cos((fragTexCoord.y - boxTop)*freqX/(pixelWidth*750.0) + (seconds*speedX))*ampX*pixelWidth;
|
||||
p.y += sin((fragTexCoord.x - boxLeft)*freqY*aspect/(pixelHeight*750.0) + (seconds*speedY))*ampY*pixelHeight;
|
||||
|
||||
finalColor = texture(texture0, p)*colDiffuse*fragColor;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2582,9 +2582,10 @@ public static unsafe partial class Raylib
|
|||
byte* fileData,
|
||||
int dataSize,
|
||||
int fontSize,
|
||||
int* fontChars,
|
||||
int glyphCount,
|
||||
FontType type
|
||||
int* codepoints,
|
||||
int codepointsCount,
|
||||
FontType type,
|
||||
int* glyphCount
|
||||
);
|
||||
|
||||
/// <summary>Generate image font atlas using chars info</summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue