2022-03-06 18:33:10 +01:00
|
|
|
Class {
|
|
|
|
#name : #Diya2DShader,
|
|
|
|
#superclass : #OpenGLSL,
|
|
|
|
#category : #'Diya-Shaders'
|
|
|
|
}
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DShader class >> fragmentShader [
|
|
|
|
^'
|
|
|
|
#ifdef GL_ES
|
|
|
|
precision highp float;
|
|
|
|
#endif
|
|
|
|
uniform vec2 u_resolution;
|
|
|
|
uniform vec2 u_mouse;
|
|
|
|
uniform float u_time;
|
|
|
|
// 2D uniforms
|
2022-03-08 23:30:01 +01:00
|
|
|
uniform int u_texture_type;
|
2022-03-06 18:33:10 +01:00
|
|
|
uniform vec4 u_color;
|
2022-08-06 03:11:36 +02:00
|
|
|
uniform vec4 u_bg_color;
|
2022-03-06 18:33:10 +01:00
|
|
|
uniform sampler2D u_texture;
|
|
|
|
varying vec2 texcoord;
|
|
|
|
void main(void) {
|
2022-08-08 00:12:54 +02:00
|
|
|
if(u_texture_type == 1)
|
|
|
|
{
|
|
|
|
// draw border
|
|
|
|
gl_FragColor = u_color;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
vec4 texcolor = u_bg_color;
|
2022-03-08 23:30:01 +01:00
|
|
|
// alpha
|
|
|
|
if(u_texture_type == 0x1906) {
|
2022-03-06 18:33:10 +01:00
|
|
|
texcolor = vec4(1, 1, 1, texture2D(u_texture, texcoord).a);
|
|
|
|
}
|
2022-03-08 23:30:01 +01:00
|
|
|
// rgba
|
|
|
|
else if (u_texture_type == 0x1908){
|
|
|
|
texcolor = texture2D(u_texture, texcoord);
|
2022-08-08 00:12:54 +02:00
|
|
|
}
|
2022-08-06 03:11:36 +02:00
|
|
|
vec4 pxcolor = texcolor * u_color;
|
|
|
|
if(pxcolor.a > 0.0)
|
2022-08-08 00:12:54 +02:00
|
|
|
{
|
2022-08-06 03:11:36 +02:00
|
|
|
gl_FragColor = pxcolor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-08 00:12:54 +02:00
|
|
|
gl_FragColor = u_bg_color;
|
2022-08-06 03:11:36 +02:00
|
|
|
}
|
2022-03-06 18:33:10 +01:00
|
|
|
}'
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DShader class >> vertexShader [
|
|
|
|
^'
|
|
|
|
#ifdef GL_ES
|
|
|
|
precision mediump float;
|
|
|
|
#endif
|
|
|
|
uniform mat4 u_projection;
|
|
|
|
uniform mat3 u_transform;
|
|
|
|
varying vec2 texcoord;
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec3 coord_global = u_transform * vec3(gl_Vertex.xy, 1.0);
|
|
|
|
gl_Position = u_projection * vec4(coord_global.xy, 0, 1.0);
|
|
|
|
texcoord = gl_Vertex.zw;
|
|
|
|
}'
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
Diya2DShader >> setUpUniforms [
|
|
|
|
self addUniform: #u_texture of: Uniform1i.
|
2022-03-08 23:30:01 +01:00
|
|
|
self addUniform: #u_texture_type of: Uniform1i.
|
2022-03-06 18:33:10 +01:00
|
|
|
self addUniform: #u_color of: Uniform4F.
|
2022-08-06 03:11:36 +02:00
|
|
|
self addUniform: #u_bg_color of: Uniform4F.
|
2022-03-06 18:33:10 +01:00
|
|
|
self addUniform: #u_border_color of: Uniform4F.
|
2022-03-16 17:48:18 +01:00
|
|
|
self addUniform: #u_border of: Uniform1F.
|
2022-03-06 18:33:10 +01:00
|
|
|
]
|