@@ -1106,12 +1106,14 @@ MaterialStorage::MaterialStorage() {
1106
1106
shader_data_request_func[RS::SHADER_CANVAS_ITEM] = _create_canvas_shader_func;
1107
1107
shader_data_request_func[RS::SHADER_PARTICLES] = _create_particles_shader_func;
1108
1108
shader_data_request_func[RS::SHADER_SKY] = _create_sky_shader_func;
1109
+ shader_data_request_func[RS::SHADER_TEXTURE_BLIT] = _create_tex_blit_shader_func;
1109
1110
shader_data_request_func[RS::SHADER_FOG] = nullptr ;
1110
1111
1111
1112
material_data_request_func[RS::SHADER_SPATIAL] = _create_scene_material_func;
1112
1113
material_data_request_func[RS::SHADER_CANVAS_ITEM] = _create_canvas_material_func;
1113
1114
material_data_request_func[RS::SHADER_PARTICLES] = _create_particles_material_func;
1114
1115
material_data_request_func[RS::SHADER_SKY] = _create_sky_material_func;
1116
+ material_data_request_func[RS::SHADER_TEXTURE_BLIT] = _create_tex_blit_material_func;
1115
1117
material_data_request_func[RS::SHADER_FOG] = nullptr ;
1116
1118
1117
1119
static_assert (sizeof (GlobalShaderUniforms::Value) == 16 );
@@ -1508,6 +1510,27 @@ MaterialStorage::MaterialStorage() {
1508
1510
1509
1511
shaders.compiler_sky .initialize (actions);
1510
1512
}
1513
+
1514
+ {
1515
+ // Setup TextureBlit compiler
1516
+ ShaderCompiler::DefaultIdentifierActions actions;
1517
+
1518
+ actions.renames [" PI" ] = _MKSTR (Math_PI);
1519
+ actions.renames [" TAU" ] = _MKSTR (Math_TAU);
1520
+ actions.renames [" E" ] = _MKSTR (Math_E);
1521
+
1522
+ actions.renames [" FRAGCOORD" ] = " gl_FragCoord" ;
1523
+
1524
+ actions.renames [" UV" ] = " uv" ;
1525
+ actions.renames [" MODULATE" ] = " modulate" ;
1526
+
1527
+ actions.renames [" COLOR" ] = " color" ;
1528
+ actions.renames [" COLOR2" ] = " color2" ;
1529
+ actions.renames [" COLOR3" ] = " color3" ;
1530
+ actions.renames [" COLOR4" ] = " color4" ;
1531
+
1532
+ shaders.compiler_tex_blit .initialize (actions);
1533
+ }
1511
1534
}
1512
1535
1513
1536
MaterialStorage::~MaterialStorage () {
@@ -2192,6 +2215,8 @@ void MaterialStorage::shader_set_code(RID p_shader, const String &p_code) {
2192
2215
new_mode = RS::SHADER_SKY;
2193
2216
// } else if (mode_string == "fog") {
2194
2217
// new_mode = RS::SHADER_FOG;
2218
+ } else if (mode_string == " texture_blit" ) {
2219
+ new_mode = RS::SHADER_TEXTURE_BLIT;
2195
2220
} else {
2196
2221
new_mode = RS::SHADER_MAX;
2197
2222
ERR_PRINT (" shader type " + mode_string + " not supported in OpenGL renderer" );
@@ -3248,7 +3273,123 @@ void ParticleProcessMaterialData::bind_uniforms() {
3248
3273
// Bind Material Uniforms
3249
3274
glBindBufferBase (GL_UNIFORM_BUFFER, GLES3::PARTICLES_MATERIAL_UNIFORM_LOCATION, uniform_buffer);
3250
3275
3251
- bind_uniforms_generic (texture_cache, shader_data->texture_uniforms , 1 ); // Start at GL_TEXTURE1 because texture slot 0 is reserved for the heightmap texture.
3276
+ bind_uniforms_generic (texture_cache, shader_data->texture_uniforms );
3277
+ }
3278
+
3279
+ /* TextureBlit SHADER */
3280
+
3281
+ void TexBlitShaderData::set_code (const String &p_code) {
3282
+ // Initialize and compile the shader.
3283
+
3284
+ code = p_code;
3285
+ valid = false ;
3286
+ ubo_size = 0 ;
3287
+ uniforms.clear ();
3288
+
3289
+ if (code.is_empty ()) {
3290
+ return ; // Just invalid, but no error.
3291
+ }
3292
+
3293
+ ShaderCompiler::GeneratedCode gen_code;
3294
+
3295
+ // Actual enum set further down after compilation.
3296
+ int blend_modei = BLEND_MODE_MIX;
3297
+
3298
+ ShaderCompiler::IdentifierActions actions;
3299
+ actions.entry_point_stages [" blit" ] = ShaderCompiler::STAGE_FRAGMENT;
3300
+
3301
+ actions.render_mode_values [" blend_add" ] = Pair<int *, int >(&blend_modei, BLEND_MODE_ADD);
3302
+ actions.render_mode_values [" blend_mix" ] = Pair<int *, int >(&blend_modei, BLEND_MODE_MIX);
3303
+ actions.render_mode_values [" blend_sub" ] = Pair<int *, int >(&blend_modei, BLEND_MODE_SUB);
3304
+ actions.render_mode_values [" blend_mul" ] = Pair<int *, int >(&blend_modei, BLEND_MODE_MUL);
3305
+ actions.render_mode_values [" blend_disabled" ] = Pair<int *, int >(&blend_modei, BLEND_MODE_DISABLED);
3306
+
3307
+ actions.uniforms = &uniforms;
3308
+ Error err = MaterialStorage::get_singleton ()->shaders .compiler_tex_blit .compile (RS::SHADER_TEXTURE_BLIT, code, &actions, path, gen_code);
3309
+ ERR_FAIL_COND_MSG (err != OK, " Shader compilation failed." );
3310
+
3311
+ if (version.is_null ()) {
3312
+ version = MaterialStorage::get_singleton ()->shaders .tex_blit_shader .version_create ();
3313
+ }
3314
+
3315
+ blend_mode = BlendMode (blend_modei);
3316
+
3317
+ #if 0
3318
+ print_line("**compiling shader:");
3319
+ print_line("**defines:\n");
3320
+ for (int i = 0; i < gen_code.defines.size(); i++) {
3321
+ print_line(gen_code.defines[i]);
3322
+ }
3323
+
3324
+ HashMap<String, String>::Iterator el = gen_code.code.begin();
3325
+ while (el) {
3326
+ print_line("\n**code " + el->key + ":\n" + el->value);
3327
+ ++el;
3328
+ }
3329
+
3330
+ print_line("\n**uniforms:\n" + gen_code.uniforms);
3331
+ print_line("\n**vertex_globals:\n" + gen_code.stage_globals[ShaderCompiler::STAGE_VERTEX]);
3332
+ print_line("\n**fragment_globals:\n" + gen_code.stage_globals[ShaderCompiler::STAGE_FRAGMENT]);
3333
+ #endif
3334
+
3335
+ LocalVector<ShaderGLES3::TextureUniformData> texture_uniform_data = get_texture_uniform_data (gen_code.texture_uniforms );
3336
+
3337
+ MaterialStorage::get_singleton ()->shaders .tex_blit_shader .version_set_code (version, gen_code.code , gen_code.uniforms , gen_code.stage_globals [ShaderCompiler::STAGE_VERTEX], gen_code.stage_globals [ShaderCompiler::STAGE_FRAGMENT], gen_code.defines , texture_uniform_data);
3338
+ ERR_FAIL_COND (!MaterialStorage::get_singleton ()->shaders .tex_blit_shader .version_is_valid (version));
3339
+
3340
+ ubo_size = gen_code.uniform_total_size ;
3341
+ ubo_offsets = gen_code.uniform_offsets ;
3342
+ texture_uniforms = gen_code.texture_uniforms ;
3343
+
3344
+ valid = true ;
3345
+ }
3346
+
3347
+ bool TexBlitShaderData::is_animated () const {
3348
+ return false ;
3349
+ }
3350
+
3351
+ bool TexBlitShaderData::casts_shadows () const {
3352
+ return false ;
3353
+ }
3354
+
3355
+ RS::ShaderNativeSourceCode TexBlitShaderData::get_native_source_code () const {
3356
+ return MaterialStorage::get_singleton ()->shaders .tex_blit_shader .version_get_native_source_code (version);
3357
+ }
3358
+
3359
+ TexBlitShaderData::TexBlitShaderData () {
3360
+ valid = false ;
3361
+ }
3362
+
3363
+ TexBlitShaderData::~TexBlitShaderData () {
3364
+ if (version.is_valid ()) {
3365
+ MaterialStorage::get_singleton ()->shaders .tex_blit_shader .version_free (version);
3366
+ }
3367
+ }
3368
+
3369
+ GLES3::ShaderData *GLES3::_create_tex_blit_shader_func () {
3370
+ TexBlitShaderData *shader_data = memnew (TexBlitShaderData);
3371
+ return shader_data;
3372
+ }
3373
+
3374
+ void TexBlitMaterialData::update_parameters (const HashMap<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) {
3375
+ update_parameters_internal (p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms , shader_data->ubo_offsets .ptr (), shader_data->texture_uniforms , shader_data->default_texture_params , shader_data->ubo_size , false );
3376
+ }
3377
+
3378
+ void TexBlitMaterialData::bind_uniforms () {
3379
+ glBindBufferBase (GL_UNIFORM_BUFFER, 0 , uniform_buffer);
3380
+
3381
+ bind_uniforms_generic (texture_cache, shader_data->texture_uniforms , 1 );
3382
+ }
3383
+
3384
+ TexBlitMaterialData::~TexBlitMaterialData () {
3385
+ // Pass for now
3386
+ }
3387
+
3388
+ GLES3::MaterialData *GLES3::_create_tex_blit_material_func (ShaderData *p_shader) {
3389
+ TexBlitMaterialData *material_data = memnew (TexBlitMaterialData);
3390
+ material_data->shader_data = static_cast <TexBlitShaderData *>(p_shader);
3391
+ // update will happen later anyway so do nothing.
3392
+ return material_data;
3252
3393
}
3253
3394
3254
3395
#endif // !GLES3_ENABLED
0 commit comments