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;
|
|
|
|
uniform sampler2D u_texture;
|
|
|
|
varying vec2 texcoord;
|
|
|
|
void main(void) {
|
|
|
|
vec4 texcolor = vec4(1,1,1,1);
|
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);
|
|
|
|
}
|
|
|
|
gl_FragColor = texcolor * u_color;
|
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.
|
|
|
|
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
|
|
|
]
|