1
0
Fork 0

Fold used shaders into the main shader

This commit is contained in:
Erik Hofman 2023-03-08 11:27:55 +01:00
parent cfef45c93b
commit 61664836a4
4 changed files with 6 additions and 76 deletions

View file

@ -1,7 +1,5 @@
// -*-C++-*- // -*-C++-*-
#version 330 #version 330 core
/*** Enum constans ************************************/
#define PAINT_TYPE_COLOR 0x1B00 #define PAINT_TYPE_COLOR 0x1B00
#define PAINT_TYPE_LINEAR_GRADIENT 0x1B01 #define PAINT_TYPE_LINEAR_GRADIENT 0x1B01
@ -14,40 +12,19 @@
#define DRAW_MODE_PATH 0 #define DRAW_MODE_PATH 0
#define DRAW_MODE_IMAGE 1 #define DRAW_MODE_IMAGE 1
/*** Interpolated *************************************/
in vec2 texImageCoord; in vec2 texImageCoord;
in vec2 paintCoord; in vec2 paintCoord;
/*** Input ********************************************/
// Basic rendering Mode
uniform int drawMode; uniform int drawMode;
// Image
uniform sampler2D imageSampler; uniform sampler2D imageSampler;
uniform int imageMode; uniform int imageMode;
// Paint
uniform int paintType; uniform int paintType;
uniform vec4 paintColor; uniform vec4 paintColor;
uniform vec2 paintParams[3]; uniform vec2 paintParams[3];
// Gradient
uniform sampler2D rampSampler; uniform sampler2D rampSampler;
// Pattern
uniform sampler2D patternSampler; uniform sampler2D patternSampler;
// Color transform
uniform vec4 scaleFactorBias[2]; uniform vec4 scaleFactorBias[2];
/*** Output *******************************************/
//out vec4 fragColor;
/*** Built-in variables for shMain *******************************************/
vec4 sh_Color;
/*** Functions ****************************************/
// 9.3.1 Linear Gradients
float linearGradient(vec2 fragCoord, vec2 p0, vec2 p1){ float linearGradient(vec2 fragCoord, vec2 p0, vec2 p1){
float x = fragCoord.x; float x = fragCoord.x;
@ -64,7 +41,6 @@ float linearGradient(vec2 fragCoord, vec2 p0, vec2 p1){
/ ( dx*dx + dy*dy ); / ( dx*dx + dy*dy );
} }
// 9.3.2 Radial Gradients
float radialGradient(vec2 fragCoord, vec2 centerCoord, vec2 focalCoord, float r){ float radialGradient(vec2 fragCoord, vec2 centerCoord, vec2 focalCoord, float r){
float x = fragCoord.x; float x = fragCoord.x;
@ -83,16 +59,10 @@ float radialGradient(vec2 fragCoord, vec2 centerCoord, vec2 focalCoord, float r)
/ ( r*r - (dfx*dfx + dfy*dfy) ); / ( r*r - (dfx*dfx + dfy*dfy) );
} }
// User defined shader
void shMain(void);
/*** Main thread *************************************/
void main() void main()
{ {
vec4 col; vec4 col;
/* Stage 6: Paint Generation */
switch(paintType){ switch(paintType){
case PAINT_TYPE_LINEAR_GRADIENT: case PAINT_TYPE_LINEAR_GRADIENT:
{ {
@ -125,15 +95,10 @@ void main()
break; break;
} }
/* Stage 7: Image Interpolation */
if(drawMode == DRAW_MODE_IMAGE) { if(drawMode == DRAW_MODE_IMAGE) {
col = texture(imageSampler, texImageCoord) col = texture(imageSampler, texImageCoord)
* (imageMode == DRAW_IMAGE_MULTIPLY ? col : vec4(1.0, 1.0, 1.0, 1.0)); * (imageMode == DRAW_IMAGE_MULTIPLY ? col : vec4(1.0, 1.0, 1.0, 1.0));
} }
/* Stage 8: Color Transformation, Blending, and Antialiasing */ gl_FragColor = col * scaleFactorBias[0] + scaleFactorBias[1];
sh_Color = col * scaleFactorBias[0] + scaleFactorBias[1] ;
/* Extended Stage: User defined shader that affects gl_FragColor */
shMain();
} }

View file

@ -1,39 +1,16 @@
// -*-C++-*- // -*-C++-*-
#version 330 #version 330 core
/*** Input *******************/
in vec2 pos; in vec2 pos;
in vec2 textureUV; in vec2 textureUV;
uniform mat4 sh_View;
uniform mat4 sh_Model;
uniform mat4 sh_Ortho;
uniform mat3 paintInverted; uniform mat3 paintInverted;
/*** Output ******************/
out vec2 texImageCoord; out vec2 texImageCoord;
out vec2 paintCoord; out vec2 paintCoord;
/*** Grobal variables ********************/ void main()
vec4 sh_Vertex; {
// gl_Position = vec4(pos, 0, 1);
/*** Functions ****************************************/
// User defined shader
void shMain(void);
/*** Main thread **************************************************/
void main() {
/* Stage 3: Transformation */
sh_Vertex = vec4(pos, 0, 1);
/* Extended Stage: User defined shader that affects gl_Position */
shMain();
/* 2D pos in texture space */
texImageCoord = textureUV; texImageCoord = textureUV;
/* 2D pos in paint space (Back to paint space) */
paintCoord = (paintInverted * vec3(pos, 1)).xy; paintCoord = (paintInverted * vec3(pos, 1)).xy;
} }

View file

@ -1,6 +0,0 @@
// -*-C++-*-
void shMain() {
gl_FragColor = sh_Color;
}

View file

@ -1,6 +0,0 @@
// -*-C++-*-
void shMain() {
gl_Position = sh_Ortho * sh_View * sh_Model * sh_Vertex;
}