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
|
||||
|
||||
#ifdef GL_ES
|
||||
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);
|
||||
}
|
||||
varying vec4 v_color;
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
||||
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;
|
||||
gl_FragColor = v_color;
|
||||
}
|
@@ -1,5 +1,9 @@
|
||||
#version 120
|
||||
|
||||
// The color manually set with glColor4f, glColor4ubv etc etc.
|
||||
varying vec4 v_color;
|
||||
|
||||
void main() {
|
||||
v_color = gl_Color;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
}
|
||||
|
20
main.cpp
20
main.cpp
@@ -113,7 +113,6 @@ Texture* image;
|
||||
Texture* image_mask;
|
||||
RenderTarget* j2d_render_target;
|
||||
Shader shader;
|
||||
float u_time = 0;
|
||||
|
||||
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::End();
|
||||
|
||||
J2D::Begin(j2d_render_target, true);
|
||||
shader.Use();
|
||||
J2D::Begin(nullptr, true);
|
||||
|
||||
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);
|
||||
@@ -235,11 +235,9 @@ public:
|
||||
|
||||
J2D::End();
|
||||
|
||||
shader.Use();
|
||||
|
||||
J2D::Begin();
|
||||
J2D::DrawRenderTarget(j2d_render_target, {0, 0});
|
||||
J2D::DrawSprite(image, image_mask, {0, 0}, 0.25, {0.5, 0.5}, {1,1});
|
||||
//J2D::DrawRenderTarget(j2d_render_target, {0, 0});
|
||||
//J2D::DrawSprite(image, image_mask, {0, 0}, 0.25, {0.5, 0.5}, {1,1});
|
||||
J2D::End();
|
||||
|
||||
|
||||
@@ -248,16 +246,6 @@ public:
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
if (IsKeyDown(Keys::RightArrow))
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
#include <JGL/types/RenderTarget.h>
|
||||
#include <JGL/types/Light.h>
|
||||
#include <JGL/types/Shader.h>
|
||||
#include <JGL/logger/logger.h>
|
||||
|
||||
namespace JGL {
|
||||
@@ -23,6 +24,7 @@ public:
|
||||
GLint blend_func[2];
|
||||
GLuint current_fbo = 0;
|
||||
RenderTarget* current_render_target = nullptr;
|
||||
//Shader* current_shader = nullptr;
|
||||
|
||||
bool texture_2D = false;
|
||||
bool texture_coordinate_array = false;
|
||||
|
@@ -150,32 +150,17 @@ namespace JGL {
|
||||
glCompileShader(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
|
||||
id = glCreateProgram();
|
||||
glAttachShader(id, vertex);
|
||||
glAttachShader(id, fragment);
|
||||
|
||||
if (false)
|
||||
glAttachShader(id, geometry);
|
||||
|
||||
glLinkProgram(id);
|
||||
checkCompileErrors(id, "PROGRAM");
|
||||
|
||||
// delete the shaders as they're linked into our program now and are no longer necessary
|
||||
glDeleteShader(vertex);
|
||||
glDeleteShader(fragment);
|
||||
if (false)
|
||||
glDeleteShader(geometry);
|
||||
}
|
||||
|
||||
void Shader::Use() {
|
||||
|
Reference in New Issue
Block a user