Working on the default shader
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 5m16s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 5m16s
( Need a system for accessing texture units & sampling etc )
This commit is contained in:
@@ -1,50 +1,7 @@
|
|||||||
#version 120
|
#version 120
|
||||||
|
|
||||||
#ifdef GL_ES
|
varying vec4 v_color;
|
||||||
precision mediump float;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
attribute vec4 gl_Color;
|
|
||||||
|
|
||||||
uniform vec2 u_resolution;
|
|
||||||
uniform float u_time;
|
|
||||||
|
|
||||||
vec3 rgb2hsb( in vec3 c ){
|
|
||||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
|
||||||
vec4 p = mix(vec4(c.bg, K.wz),
|
|
||||||
vec4(c.gb, K.xy),
|
|
||||||
step(c.b, c.g));
|
|
||||||
vec4 q = mix(vec4(p.xyw, c.r),
|
|
||||||
vec4(c.r, p.yzx),
|
|
||||||
step(p.x, c.r));
|
|
||||||
float d = q.x - min(q.w, q.y);
|
|
||||||
float e = 1.0e-10;
|
|
||||||
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)),
|
|
||||||
d / (q.x + e),
|
|
||||||
q.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function from Iñigo Quiles
|
|
||||||
// https://www.shadertoy.com/view/MsS3Wc
|
|
||||||
vec3 hsb2rgb( in vec3 c ){
|
|
||||||
vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),
|
|
||||||
6.0)-3.0)-1.0,
|
|
||||||
0.0,
|
|
||||||
1.0 );
|
|
||||||
rgb = rgb*rgb*(3.0-2.0*rgb);
|
|
||||||
return c.z * mix(vec3(1.0), rgb, c.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
gl_FragColor = v_color;
|
||||||
vec3 color = vec3(0.0);
|
|
||||||
|
|
||||||
// We map x (0.0 - 1.0) to the hue (0.0 - 1.0)
|
|
||||||
// And the y (0.0 - 1.0) to the brightness
|
|
||||||
color = hsb2rgb(vec3(st.x,1.0,st.y));
|
|
||||||
|
|
||||||
gl_FragColor = vec4(color,1.0);
|
|
||||||
|
|
||||||
|
|
||||||
gl_FragColor = gl_Color;
|
|
||||||
}
|
}
|
@@ -1,5 +1,9 @@
|
|||||||
#version 120
|
#version 120
|
||||||
|
|
||||||
|
// The color manually set with glColor4f, glColor4ubv etc etc.
|
||||||
|
varying vec4 v_color;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
v_color = gl_Color;
|
||||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||||
}
|
}
|
||||||
|
20
main.cpp
20
main.cpp
@@ -113,7 +113,6 @@ Texture* image;
|
|||||||
Texture* image_mask;
|
Texture* image_mask;
|
||||||
RenderTarget* j2d_render_target;
|
RenderTarget* j2d_render_target;
|
||||||
Shader shader;
|
Shader shader;
|
||||||
float u_time = 0;
|
|
||||||
|
|
||||||
class JGLDemoWindow : public ReWindow::OpenGLWindow
|
class JGLDemoWindow : public ReWindow::OpenGLWindow
|
||||||
{
|
{
|
||||||
@@ -194,7 +193,8 @@ public:
|
|||||||
J3D::WireframeAABB(Colors::Yellow, {0.5, 0, 0.5}, {0.125, 0.125, 0.125}, 1);
|
J3D::WireframeAABB(Colors::Yellow, {0.5, 0, 0.5}, {0.125, 0.125, 0.125}, 1);
|
||||||
J3D::End();
|
J3D::End();
|
||||||
|
|
||||||
J2D::Begin(j2d_render_target, true);
|
shader.Use();
|
||||||
|
J2D::Begin(nullptr, true);
|
||||||
|
|
||||||
J2D::FillRect(Colors::Blue, {0,52}, {100,100});
|
J2D::FillRect(Colors::Blue, {0,52}, {100,100});
|
||||||
J2D::DrawSprite(image, {300, 400}, sprite_radians * 0.10f, {0.5,0.5}, {1, 1}, Colors::White);
|
J2D::DrawSprite(image, {300, 400}, sprite_radians * 0.10f, {0.5,0.5}, {1, 1}, Colors::White);
|
||||||
@@ -235,11 +235,9 @@ public:
|
|||||||
|
|
||||||
J2D::End();
|
J2D::End();
|
||||||
|
|
||||||
shader.Use();
|
|
||||||
|
|
||||||
J2D::Begin();
|
J2D::Begin();
|
||||||
J2D::DrawRenderTarget(j2d_render_target, {0, 0});
|
//J2D::DrawRenderTarget(j2d_render_target, {0, 0});
|
||||||
J2D::DrawSprite(image, image_mask, {0, 0}, 0.25, {0.5, 0.5}, {1,1});
|
//J2D::DrawSprite(image, image_mask, {0, 0}, 0.25, {0.5, 0.5}, {1,1});
|
||||||
J2D::End();
|
J2D::End();
|
||||||
|
|
||||||
|
|
||||||
@@ -248,16 +246,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnRefresh(float elapsed) override {
|
void OnRefresh(float elapsed) override {
|
||||||
|
|
||||||
u_time += elapsed;
|
|
||||||
|
|
||||||
shader.SetFloat("u_time", u_time);
|
|
||||||
|
|
||||||
auto dimensions = GetSize();
|
|
||||||
|
|
||||||
shader.SetVector2("u_resolution", Vector2(dimensions.x, dimensions.y));
|
|
||||||
|
|
||||||
|
|
||||||
fps = GetRefreshRate();
|
fps = GetRefreshRate();
|
||||||
|
|
||||||
if (IsKeyDown(Keys::RightArrow))
|
if (IsKeyDown(Keys::RightArrow))
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||||
#include <JGL/types/RenderTarget.h>
|
#include <JGL/types/RenderTarget.h>
|
||||||
#include <JGL/types/Light.h>
|
#include <JGL/types/Light.h>
|
||||||
|
#include <JGL/types/Shader.h>
|
||||||
#include <JGL/logger/logger.h>
|
#include <JGL/logger/logger.h>
|
||||||
|
|
||||||
namespace JGL {
|
namespace JGL {
|
||||||
@@ -23,6 +24,7 @@ public:
|
|||||||
GLint blend_func[2];
|
GLint blend_func[2];
|
||||||
GLuint current_fbo = 0;
|
GLuint current_fbo = 0;
|
||||||
RenderTarget* current_render_target = nullptr;
|
RenderTarget* current_render_target = nullptr;
|
||||||
|
//Shader* current_shader = nullptr;
|
||||||
|
|
||||||
bool texture_2D = false;
|
bool texture_2D = false;
|
||||||
bool texture_coordinate_array = false;
|
bool texture_coordinate_array = false;
|
||||||
|
@@ -150,32 +150,17 @@ namespace JGL {
|
|||||||
glCompileShader(fragment);
|
glCompileShader(fragment);
|
||||||
checkCompileErrors(fragment, "FRAGMENT");
|
checkCompileErrors(fragment, "FRAGMENT");
|
||||||
|
|
||||||
// if geometry shader is given, compile geometry shader.
|
|
||||||
unsigned int geometry;
|
|
||||||
if (false) {
|
|
||||||
// const char* gShaderCode = geometry_code.c_str();
|
|
||||||
// geometry = glCreateShader(GL_GEOMETRY_SHADER);
|
|
||||||
// glShaderSource(geometry, 1 &gShaderCode, NULL);
|
|
||||||
// glCompileShader(geometry);
|
|
||||||
// checkCompileErrors(geometry, "GEOMETRY");
|
|
||||||
}
|
|
||||||
|
|
||||||
// shader Program
|
// shader Program
|
||||||
id = glCreateProgram();
|
id = glCreateProgram();
|
||||||
glAttachShader(id, vertex);
|
glAttachShader(id, vertex);
|
||||||
glAttachShader(id, fragment);
|
glAttachShader(id, fragment);
|
||||||
|
|
||||||
if (false)
|
|
||||||
glAttachShader(id, geometry);
|
|
||||||
|
|
||||||
glLinkProgram(id);
|
glLinkProgram(id);
|
||||||
checkCompileErrors(id, "PROGRAM");
|
checkCompileErrors(id, "PROGRAM");
|
||||||
|
|
||||||
// delete the shaders as they're linked into our program now and are no longer necessary
|
// delete the shaders as they're linked into our program now and are no longer necessary
|
||||||
glDeleteShader(vertex);
|
glDeleteShader(vertex);
|
||||||
glDeleteShader(fragment);
|
glDeleteShader(fragment);
|
||||||
if (false)
|
|
||||||
glDeleteShader(geometry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::Use() {
|
void Shader::Use() {
|
||||||
|
Reference in New Issue
Block a user