<commit_before>#include <stdlib.h>
#include <gtk/gtk.h>

#include <epoxy/gl.h>

#include <gthree/gthree.h>
#include "utils.h"

GthreeEffectComposer *composer;
GthreeScene *scene;
GthreeMesh *mesh;
GthreePerspectiveCamera *camera;
GthreeMesh *mesh2;
GthreeScene *scene2;
GthreePerspectiveCamera *camera2;
GthreeMeshBasicMaterial *material;

GthreePass *clear_pass;
GthreePass *psycho_pass;
GthreePass *clear_depth_pass;
GthreePass *render_pass;
GthreePass *render2_pass;
GthreePass *greyscale_pass;

GthreeRenderTarget *render_target;

void
init_scene (void)
{
  GthreeGeometry *geometry;
  graphene_point3d_t pos;
  GdkPixbuf *crate_pixbuf;
  GthreeTexture *texture;

  geometry = gthree_geometry_new_box (80, 80, 80, 1, 1, 1);

  scene = gthree_scene_new ();

  crate_pixbuf = examples_load_pixbuf ("crate.gif");
  texture = gthree_texture_new (crate_pixbuf);

  material = gthree_mesh_basic_material_new ();
  gthree_mesh_basic_material_set_color (GTHREE_MESH_BASIC_MATERIAL (material), &yellow);
  gthree_mesh_basic_material_set_map (GTHREE_MESH_BASIC_MATERIAL (material), texture);
  mesh = gthree_mesh_new (geometry, GTHREE_MATERIAL (material));
  gthree_object_set_position (GTHREE_OBJECT (mesh),
                              graphene_point3d_init (&pos, -20, 0, 0));


  gthree_object_add_child (GTHREE_OBJECT (scene), GTHREE_OBJECT (mesh));

  camera = gthree_perspective_camera_new (30, 1, 1, 10000);
  gthree_object_set_position (GTHREE_OBJECT (camera),
                              graphene_point3d_init (&pos, 0, 0, 400));
  gthree_object_add_child (GTHREE_OBJECT (scene), GTHREE_OBJECT (camera));
}

void
init_scene2 (void)
{
  GthreeGeometry *geometry;
  graphene_point3d_t pos;
  GthreeMeshPhongMaterial *material_phong;
  GthreeAmbientLight *ambient_light;
  GthreeDirectionalLight *directional_light;

  geometry = gthree_geometry_new_sphere (40, 40, 16);

  scene2 = gthree_scene_new ();

  material_phong = gthree_mesh_phong_material_new ();
  gthree_mesh_phong_material_set_color (material_phong, &light_grey);
  gthree_mesh_phong_material_set_specular_color (material_phong, &dark_green);
  gthree_mesh_phong_material_set_shininess (material_phong, 30);

  mesh2 = gthree_mesh_new (geometry, GTHREE_MATERIAL (material_phong));
  gthree_object_set_position (GTHREE_OBJECT (mesh2),
                              graphene_point3d_init (&pos, 20, 0, 0));

  gthree_object_add_child (GTHREE_OBJECT (scene2), GTHREE_OBJECT (mesh2));

  ambient_light = gthree_ambient_light_new (&dark_grey);
  gthree_object_add_child (GTHREE_OBJECT (scene2), GTHREE_OBJECT (ambient_light));

  directional_light = gthree_directional_light_new (&white, 0.425);
  gthree_object_set_position (GTHREE_OBJECT (directional_light),
                              graphene_point3d_init (&pos,
                                                     1, 1, -1));
  gthree_object_add_child (GTHREE_OBJECT (scene2), GTHREE_OBJECT (directional_light));

  camera2 = gthree_perspective_camera_new (30, 1, 1, 10000);
  gthree_object_set_position (GTHREE_OBJECT (camera2),
                              graphene_point3d_init (&pos, 0, 0, 400));
  gthree_object_add_child (GTHREE_OBJECT (scene2), GTHREE_OBJECT (camera2));
}


static const char *vertex_shader =
  "varying vec2 vUv;\n"
  "void main()\n"
  "{\n"
  "  vUv = uv;\n"
  "  vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n"
  "  gl_Position = projectionMatrix * mvPosition;\n"
  "}\n";


static const char *fragment_psycho_shader =
  "uniform float time;\n"
  "varying vec2 vUv;\n"
  "void main(void)\n"
  "{\n"
  "  vec2 p = -1.0 + 2.0 * vUv;\n"
  "  float a = time*40.0;\n"
  "  float d,e,f,g=1.0/40.0,h,i,r,q;\n"
  "  e=400.0*(p.x*0.5+0.5);\n"
  "  f=400.0*(p.y*0.5+0.5);\n"
  "  i=200.0+sin(e*g+a/150.0)*20.0;\n"
  "  d=200.0+cos(f*g/2.0)*18.0+cos(e*g)*7.0;\n"
  "  r=sqrt(pow(i-e,2.0)+pow(d-f,2.0));\n"
  "  q=f/r;\n"
  "  e=(r*cos(q))-a/2.0;f=(r*sin(q))-a/2.0;\n"
  "  d=sin(e*g)*176.0+sin(e*g)*164.0+r;\n"
  "  h=((f+d)+a/2.0)*g;\n"
  "  i=cos(h+r*p.x/1.3)*(e+e+a)+cos(q*g*6.0)*(r+h/3.0);\n"
  "  h=sin(f*g)*144.0-sin(e*g)*212.0*p.x;\n"
  "  h=(h+(f-e)*q+sin(r-(a+h)/7.0)*10.0+i/4.0)*g;\n"
  "  i+=cos(h*2.3*sin(a/350.0-q))*184.0*sin(q-(r*4.3+a/12.0)*g)+tan(r*g+h)*184.0*cos(r*g+h);\n"
  "  i=mod(i/5.6,256.0)/64.0;\n"
  "  if(i<0.0) i+=4.0;\n"
  "  if(i>=2.0) i=4.0-i;\n"
  "  d=r/350.0;\n"
  "  d+=sin(d*d*8.0)*0.52;\n"
  "  f=(sin(a*g)+1.0)/2.0;\n"
  "  gl_FragColor=vec4(vec3(f*i/1.6,i/2.0+d/13.0,i)*d*p.x+vec3(i/1.3+d/8.0,i/2.0+d/18.0,i)*d*(1.0-p.x),1.0);\n"
  "}\n";

float f1 = 1;
static GthreeUniformsDefinition psycho_shader_uniforms_defs[] = {
   {"time", GTHREE_UNIFORM_TYPE_FLOAT, &f1},
};
static GthreeUniforms *psycho_shader_uniforms;

static const char *fragment_greyscale_shader =
  "uniform sampler2D tDiffuse;\n"
  "varying vec2 vUv;\n"
  "void main(void)\n"
  "{\n"
  "vec4 cTextureScreen = texture2D( tDiffuse, vUv );\n"
  "vec3 cResult = cTextureScreen.rgb;\n"
  "cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );\n"
  "gl_FragColor =  vec4(cResult, 1);\n"
  "}\n";

static GthreeUniformsDefinition greyscale_shader_uniforms_defs[] = {
  {"tDiffuse", GTHREE_UNIFORM_TYPE_TEXTURE, NULL },
};
static GthreeUniforms *greyscale_shader_uniforms;

void
init_composer (void)
{
  GthreeShader *psycho_shader, *shader2;

  psycho_shader_uniforms = gthree_uniforms_new_from_definitions (psycho_shader_uniforms_defs,
                                                           G_N_ELEMENTS (psycho_shader_uniforms_defs));
  greyscale_shader_uniforms = gthree_uniforms_new_from_definitions (greyscale_shader_uniforms_defs,
                                                           G_N_ELEMENTS (greyscale_shader_uniforms_defs));
  psycho_shader = gthree_shader_new (NULL, psycho_shader_uniforms,
                                     vertex_shader,
                                     fragment_psycho_shader);
  shader2 = gthree_shader_new (NULL, greyscale_shader_uniforms,
                               vertex_shader,
                               fragment_greyscale_shader);

  clear_pass = gthree_clear_pass_new (&cyan);
  psycho_pass = gthree_shader_pass_new (psycho_shader, NULL);
  greyscale_pass = gthree_shader_pass_new (shader2, NULL);
  gthree_pass_set_enabled (greyscale_pass, FALSE);
<commit_msg>examples/effects - no need to clear in psycho shader<commit_after>#include <stdlib.h>
#include <gtk/gtk.h>

#include <epoxy/gl.h>

#include <gthree/gthree.h>
#include "utils.h"

GthreeEffectComposer *composer;
GthreeScene *scene;
GthreeMesh *mesh;
GthreePerspectiveCamera *camera;
GthreeMesh *mesh2;
GthreeScene *scene2;
GthreePerspectiveCamera *camera2;
GthreeMeshBasicMaterial *material;

GthreePass *clear_pass;
GthreePass *psycho_pass;
GthreePass *clear_depth_pass;
GthreePass *render_pass;
GthreePass *render2_pass;
GthreePass *greyscale_pass;

GthreeRenderTarget *render_target;

void
init_scene (void)
{
  GthreeGeometry *geometry;
  graphene_point3d_t pos;
  GdkPixbuf *crate_pixbuf;
  GthreeTexture *texture;

  geometry = gthree_geometry_new_box (80, 80, 80, 1, 1, 1);

  scene = gthree_scene_new ();

  crate_pixbuf = examples_load_pixbuf ("crate.gif");
  texture = gthree_texture_new (crate_pixbuf);

  material = gthree_mesh_basic_material_new ();
  gthree_mesh_basic_material_set_color (GTHREE_MESH_BASIC_MATERIAL (material), &yellow);
  gthree_mesh_basic_material_set_map (GTHREE_MESH_BASIC_MATERIAL (material), texture);
  mesh = gthree_mesh_new (geometry, GTHREE_MATERIAL (material));
  gthree_object_set_position (GTHREE_OBJECT (mesh),
                              graphene_point3d_init (&pos, -20, 0, 0));


  gthree_object_add_child (GTHREE_OBJECT (scene), GTHREE_OBJECT (mesh));

  camera = gthree_perspective_camera_new (30, 1, 1, 10000);
  gthree_object_set_position (GTHREE_OBJECT (camera),
                              graphene_point3d_init (&pos, 0, 0, 400));
  gthree_object_add_child (GTHREE_OBJECT (scene), GTHREE_OBJECT (camera));
}

void
init_scene2 (void)
{
  GthreeGeometry *geometry;
  graphene_point3d_t pos;
  GthreeMeshPhongMaterial *material_phong;
  GthreeAmbientLight *ambient_light;
  GthreeDirectionalLight *directional_light;

  geometry = gthree_geometry_new_sphere (40, 40, 16);

  scene2 = gthree_scene_new ();

  material_phong = gthree_mesh_phong_material_new ();
  gthree_mesh_phong_material_set_color (material_phong, &light_grey);
  gthree_mesh_phong_material_set_specular_color (material_phong, &dark_green);
  gthree_mesh_phong_material_set_shininess (material_phong, 30);

  mesh2 = gthree_mesh_new (geometry, GTHREE_MATERIAL (material_phong));
  gthree_object_set_position (GTHREE_OBJECT (mesh2),
                              graphene_point3d_init (&pos, 20, 0, 0));

  gthree_object_add_child (GTHREE_OBJECT (scene2), GTHREE_OBJECT (mesh2));

  ambient_light = gthree_ambient_light_new (&dark_grey);
  gthree_object_add_child (GTHREE_OBJECT (scene2), GTHREE_OBJECT (ambient_light));

  directional_light = gthree_directional_light_new (&white, 0.425);
  gthree_object_set_position (GTHREE_OBJECT (directional_light),
                              graphene_point3d_init (&pos,
                                                     1, 1, -1));
  gthree_object_add_child (GTHREE_OBJECT (scene2), GTHREE_OBJECT (directional_light));

  camera2 = gthree_perspective_camera_new (30, 1, 1, 10000);
  gthree_object_set_position (GTHREE_OBJECT (camera2),
                              graphene_point3d_init (&pos, 0, 0, 400));
  gthree_object_add_child (GTHREE_OBJECT (scene2), GTHREE_OBJECT (camera2));
}


static const char *vertex_shader =
  "varying vec2 vUv;\n"
  "void main()\n"
  "{\n"
  "  vUv = uv;\n"
  "  vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n"
  "  gl_Position = projectionMatrix * mvPosition;\n"
  "}\n";


static const char *fragment_psycho_shader =
  "uniform float time;\n"
  "varying vec2 vUv;\n"
  "void main(void)\n"
  "{\n"
  "  vec2 p = -1.0 + 2.0 * vUv;\n"
  "  float a = time*40.0;\n"
  "  float d,e,f,g=1.0/40.0,h,i,r,q;\n"
  "  e=400.0*(p.x*0.5+0.5);\n"
  "  f=400.0*(p.y*0.5+0.5);\n"
  "  i=200.0+sin(e*g+a/150.0)*20.0;\n"
  "  d=200.0+cos(f*g/2.0)*18.0+cos(e*g)*7.0;\n"
  "  r=sqrt(pow(i-e,2.0)+pow(d-f,2.0));\n"
  "  q=f/r;\n"
  "  e=(r*cos(q))-a/2.0;f=(r*sin(q))-a/2.0;\n"
  "  d=sin(e*g)*176.0+sin(e*g)*164.0+r;\n"
  "  h=((f+d)+a/2.0)*g;\n"
  "  i=cos(h+r*p.x/1.3)*(e+e+a)+cos(q*g*6.0)*(r+h/3.0);\n"
  "  h=sin(f*g)*144.0-sin(e*g)*212.0*p.x;\n"
  "  h=(h+(f-e)*q+sin(r-(a+h)/7.0)*10.0+i/4.0)*g;\n"
  "  i+=cos(h*2.3*sin(a/350.0-q))*184.0*sin(q-(r*4.3+a/12.0)*g)+tan(r*g+h)*184.0*cos(r*g+h);\n"
  "  i=mod(i/5.6,256.0)/64.0;\n"
  "  if(i<0.0) i+=4.0;\n"
  "  if(i>=2.0) i=4.0-i;\n"
  "  d=r/350.0;\n"
  "  d+=sin(d*d*8.0)*0.52;\n"
  "  f=(sin(a*g)+1.0)/2.0;\n"
  "  gl_FragColor=vec4(vec3(f*i/1.6,i/2.0+d/13.0,i)*d*p.x+vec3(i/1.3+d/8.0,i/2.0+d/18.0,i)*d*(1.0-p.x),1.0);\n"
  "}\n";

float f1 = 1;
static GthreeUniformsDefinition psycho_shader_uniforms_defs[] = {
   {"time", GTHREE_UNIFORM_TYPE_FLOAT, &f1},
};
static GthreeUniforms *psycho_shader_uniforms;

static const char *fragment_greyscale_shader =
  "uniform sampler2D tDiffuse;\n"
  "varying vec2 vUv;\n"
  "void main(void)\n"
  "{\n"
  "vec4 cTextureScreen = texture2D( tDiffuse, vUv );\n"
  "vec3 cResult = cTextureScreen.rgb;\n"
  "cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );\n"
  "gl_FragColor =  vec4(cResult, 1);\n"
  "}\n";

static GthreeUniformsDefinition greyscale_shader_uniforms_defs[] = {
  {"tDiffuse", GTHREE_UNIFORM_TYPE_TEXTURE, NULL },
};
static GthreeUniforms *greyscale_shader_uniforms;

void
init_composer (void)
{
  GthreeShader *psycho_shader, *shader2;

  psycho_shader_uniforms = gthree_uniforms_new_from_definitions (psycho_shader_uniforms_defs,
                                                           G_N_ELEMENTS (psycho_shader_uniforms_defs));
  greyscale_shader_uniforms = gthree_uniforms_new_from_definitions (greyscale_shader_uniforms_defs,
                                                           G_N_ELEMENTS (greyscale_shader_uniforms_defs));
  psycho_shader = gthree_shader_new (NULL, psycho_shader_uniforms,
                                     vertex_shader,
                                     fragment_psycho_shader);
  shader2 = gthree_shader_new (NULL, greyscale_shader_uniforms,
                               vertex_shader,
                               fragment_greyscale_shader);

  clear_pass = gthree_clear_pass_new (&cyan);
  psycho_pass = gthree_shader_pass_new (psycho_shader, NULL);
  gthree_pass_set_clear (psycho_pass, FALSE);
  greyscale_pass = gthree_shader_pass_new (shader2, NULL);
  gthree_pass_set_enabled (greyscale_pass, FALSE);

{'fraction_non_alphanumeric': 0.14550327106486954, 'fraction_numerical': 0.04303617876566564, 'mean_word_length': 3.7414050822122573, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6466771', 'n_tokens_mistral': 5477, 'n_tokens_neox': 5236, 'n_words': 758}