baking now shows a proper button, and bakes can be saved.

This commit is contained in:
Juan Linietsky 2016-12-23 00:37:38 -03:00
parent f9603d8236
commit 4e729f38e0
11 changed files with 211 additions and 211 deletions

View File

@ -645,6 +645,10 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image
bool srgb;
if (config.keep_original_textures && !(texture->flags&VS::TEXTURE_FLAG_USED_FOR_STREAMING)) {
texture->images[p_cube_side]=p_image;
}
Image img = _get_gl_image_and_format(p_image, p_image.get_format(),texture->flags,format,internal_format,type,compressed,srgb);
if (config.shrink_textures_x2 && (p_image.has_mipmaps() || !p_image.is_compressed()) && !(texture->flags&VS::TEXTURE_FLAG_USED_FOR_STREAMING)) {
@ -822,6 +826,9 @@ Image RasterizerStorageGLES3::texture_get_data(RID p_texture,VS::CubeMapSide p_c
ERR_FAIL_COND_V(texture->data_size==0,Image());
ERR_FAIL_COND_V(texture->render_target,Image());
if (!texture->images[p_cube_side].empty())
return texture->images[p_cube_side];
#ifdef GLES_OVER_GL
DVector<uint8_t> data;
@ -871,6 +878,7 @@ Image RasterizerStorageGLES3::texture_get_data(RID p_texture,VS::CubeMapSide p_c
#else
ERR_EXPLAIN("Sorry, It's not posible to obtain images back in OpenGL ES");
return Image();
#endif
}
@ -1047,6 +1055,11 @@ void RasterizerStorageGLES3::texture_set_shrink_all_x2_on_set_data(bool p_enable
config.shrink_textures_x2=p_enable;
}
void RasterizerStorageGLES3::textures_keep_original(bool p_enable) {
config.keep_original_textures=p_enable;
}
RID RasterizerStorageGLES3::texture_create_radiance_cubemap(RID p_source,int p_resolution) const {
Texture * texture = texture_owner.get(p_source);
@ -4690,9 +4703,6 @@ RID RasterizerStorageGLES3::gi_probe_create() {
GIProbe *gip = memnew( GIProbe );
gip->data_width=0;
gip->data_height=0;
gip->data_depth=0;
gip->bounds=AABB(Vector3(),Vector3(1,1,1));
gip->dynamic_range=1.0;
gip->energy=1.0;
@ -4827,64 +4837,6 @@ float RasterizerStorageGLES3::gi_probe_get_energy(RID p_probe) const{
}
void RasterizerStorageGLES3::gi_probe_set_static_data(RID p_gi_probe,const DVector<uint8_t>& p_data,VS::GIProbeDataFormat p_format,int p_width,int p_height,int p_depth) {
GIProbe *gip = gi_probe_owner.getornull(p_gi_probe);
ERR_FAIL_COND(!gip);
if (gip->data.is_valid()) {
free(gip->data);
}
gip->data=RID();
//this is platform dependent
gip->version++;
gip->instance_change_notify();
}
DVector<uint8_t> RasterizerStorageGLES3::gi_probe_get_static_data(RID p_gi_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_gi_probe);
ERR_FAIL_COND_V(!gip,DVector<uint8_t>());
//platform dependent
return DVector<uint8_t>();
}
VS::GIProbeDataFormat RasterizerStorageGLES3::gi_probe_get_static_data_format(RID p_gi_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_gi_probe);
ERR_FAIL_COND_V(!gip,VS::GI_PROBE_DATA_RGBA8);
return gip->data_format;
}
int RasterizerStorageGLES3::gi_probe_get_static_data_width(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND_V(!gip,0);
return gip->data_width;
}
int RasterizerStorageGLES3::gi_probe_get_static_data_height(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND_V(!gip,0);
return gip->data_height;
}
int RasterizerStorageGLES3::gi_probe_get_static_data_depth(RID p_probe) const {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND_V(!gip,0);
return gip->data_depth;
}
RID RasterizerStorageGLES3::gi_probe_get_data(RID p_probe) {
const GIProbe *gip = gi_probe_owner.getornull(p_probe);
ERR_FAIL_COND_V(!gip,RID());
return gip->data;
}
uint32_t RasterizerStorageGLES3::gi_probe_get_version(RID p_probe) {
@ -5892,9 +5844,6 @@ bool RasterizerStorageGLES3::free(RID p_rid){
// delete the texture
GIProbe *gi_probe = gi_probe_owner.get(p_rid);
if (gi_probe->data.is_valid()) {
free(gi_probe->data);
}
gi_probe_owner.free(p_rid);
memdelete(gi_probe);
@ -6119,6 +6068,7 @@ void RasterizerStorageGLES3::initialize() {
glEnable(_EXT_TEXTURE_CUBE_MAP_SEAMLESS);
frame.count=0;
config.keep_original_textures=false;
}
void RasterizerStorageGLES3::finalize() {

View File

@ -56,6 +56,8 @@ public:
int max_texture_size;
Set<String> extensions;
bool keep_original_textures;
} config;
mutable struct Shaders {
@ -221,6 +223,8 @@ public:
RenderTarget *render_target;
Image images[6];
Texture() {
using_srgb=false;
@ -272,6 +276,8 @@ public:
virtual RID texture_create_radiance_cubemap(RID p_source,int p_resolution=-1) const;
virtual void textures_keep_original(bool p_enable);
/* SKYBOX API */
struct SkyBox : public RID_Data {
@ -898,12 +904,6 @@ public:
DVector<int> dynamic_data;
RID data;
int data_width;
int data_height;
int data_depth;
VS::GIProbeDataFormat data_format;
};
@ -932,14 +932,6 @@ public:
virtual void gi_probe_set_interior(RID p_probe,bool p_enable);
virtual bool gi_probe_is_interior(RID p_probe) const;
virtual void gi_probe_set_static_data(RID p_gi_probe,const DVector<uint8_t>& p_data,VS::GIProbeDataFormat p_format,int p_width,int p_height,int p_depth);
virtual DVector<uint8_t> gi_probe_get_static_data(RID p_gi_probe) const;
virtual VS::GIProbeDataFormat gi_probe_get_static_data_format(RID p_gi_probe) const;
virtual int gi_probe_get_static_data_width(RID p_probe) const;
virtual int gi_probe_get_static_data_height(RID p_probe) const;
virtual int gi_probe_get_static_data_depth(RID p_probe) const;
virtual RID gi_probe_get_data(RID p_probe); //get data in case this is static
virtual uint32_t gi_probe_get_version(RID p_probe);
struct GIProbeData : public RID_Data {

View File

@ -1,12 +1,6 @@
#include "gi_probe.h"
#include "mesh_instance.h"
enum DataFormat {
DATA_RGBA8,
DATA_DXT5,
DATA_ETC2_EAC,
};
void GIProbeData::set_bounds(const AABB& p_bounds) {
@ -87,42 +81,47 @@ int GIProbeData::get_dynamic_range() const{
return VS::get_singleton()->gi_probe_get_dynamic_range(probe);
}
void GIProbeData::set_static_data(const DVector<uint8_t>& p_data,DataFormat p_format,int p_width,int p_height,int p_depth){
VS::get_singleton()->gi_probe_set_static_data(probe,p_data,VS::GIProbeDataFormat(p_format),p_width,p_height,p_depth);
}
DVector<uint8_t> GIProbeData::get_static_data() const{
return VS::get_singleton()->gi_probe_get_static_data(probe);
}
GIProbeData::DataFormat GIProbeData::get_static_data_format() const{
return GIProbeData::DataFormat(VS::get_singleton()->gi_probe_get_static_data_format(probe));
}
int GIProbeData::get_static_data_width() const{
return VS::get_singleton()->gi_probe_get_static_data_width(probe);
}
int GIProbeData::get_static_data_height() const{
return VS::get_singleton()->gi_probe_get_static_data_height(probe);
}
int GIProbeData::get_static_data_depth() const{
return VS::get_singleton()->gi_probe_get_static_data_depth(probe);
}
RID GIProbeData::get_rid() const {
return probe;
}
void GIProbeData::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_bounds","bounds"),&GIProbeData::set_bounds);
ObjectTypeDB::bind_method(_MD("get_bounds"),&GIProbeData::get_bounds);
ObjectTypeDB::bind_method(_MD("set_cell_size","cell_size"),&GIProbeData::set_cell_size);
ObjectTypeDB::bind_method(_MD("get_cell_size"),&GIProbeData::get_cell_size);
ObjectTypeDB::bind_method(_MD("set_to_cell_xform","to_cell_xform"),&GIProbeData::set_to_cell_xform);
ObjectTypeDB::bind_method(_MD("get_to_cell_xform"),&GIProbeData::get_to_cell_xform);
ObjectTypeDB::bind_method(_MD("set_dynamic_data","dynamic_data"),&GIProbeData::set_dynamic_data);
ObjectTypeDB::bind_method(_MD("get_dynamic_data"),&GIProbeData::get_dynamic_data);
ObjectTypeDB::bind_method(_MD("set_dynamic_range","dynamic_range"),&GIProbeData::set_dynamic_range);
ObjectTypeDB::bind_method(_MD("get_dynamic_range"),&GIProbeData::get_dynamic_range);
ObjectTypeDB::bind_method(_MD("set_energy","energy"),&GIProbeData::set_energy);
ObjectTypeDB::bind_method(_MD("get_energy"),&GIProbeData::get_energy);
ObjectTypeDB::bind_method(_MD("set_interior","interior"),&GIProbeData::set_interior);
ObjectTypeDB::bind_method(_MD("is_interior"),&GIProbeData::is_interior);
ADD_PROPERTY(PropertyInfo(Variant::_AABB,"bounds",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_bounds"),_SCS("get_bounds"));
ADD_PROPERTY(PropertyInfo(Variant::REAL,"cell_size",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_cell_size"),_SCS("get_cell_size"));
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM,"to_cell_xform",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_to_cell_xform"),_SCS("get_to_cell_xform"));
ADD_PROPERTY(PropertyInfo(Variant::INT_ARRAY,"dynamic_data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_dynamic_data"),_SCS("get_dynamic_data"));
ADD_PROPERTY(PropertyInfo(Variant::INT,"dynamic_range",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_dynamic_range"),_SCS("get_dynamic_range"));
ADD_PROPERTY(PropertyInfo(Variant::REAL,"energy",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_energy"),_SCS("get_energy"));
ADD_PROPERTY(PropertyInfo(Variant::BOOL,"interior",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_interior"),_SCS("is_interior"));
}
GIProbeData::GIProbeData() {
probe=VS::get_singleton()->gi_probe_create();

View File

@ -10,13 +10,11 @@ class GIProbeData : public Resource {
RID probe;
protected:
static void _bind_methods();
public:
enum DataFormat {
DATA_RGBA8,
DATA_DXT5,
DATA_ETC2_EAC,
};
void set_bounds(const AABB& p_bounds);
@ -40,20 +38,13 @@ public:
void set_interior(bool p_enable);
bool is_interior() const;
void set_static_data(const DVector<uint8_t>& p_data,DataFormat p_format,int p_width,int p_height,int p_depth);
DVector<uint8_t> get_static_data() const;
DataFormat get_static_data_format() const;
int get_static_data_width() const;
int get_static_data_height() const;
int get_static_data_depth() const;
virtual RID get_rid() const;
GIProbeData();
~GIProbeData();
};
VARIANT_ENUM_CAST(GIProbeData::DataFormat);
class GIProbe : public VisualInstance {
OBJ_TYPE(GIProbe,VisualInstance);

View File

@ -193,6 +193,9 @@ public:
virtual RID texture_create_radiance_cubemap(RID p_source,int p_resolution=-1) const=0;
virtual void textures_keep_original(bool p_enable)=0;
/* SKYBOX API */
virtual RID skybox_create()=0;
@ -427,14 +430,6 @@ public:
virtual void gi_probe_set_interior(RID p_probe,bool p_enable)=0;
virtual bool gi_probe_is_interior(RID p_probe) const=0;
virtual void gi_probe_set_static_data(RID p_gi_probe,const DVector<uint8_t>& p_data,VS::GIProbeDataFormat p_format,int p_width,int p_height,int p_depth)=0;
virtual DVector<uint8_t> gi_probe_get_static_data(RID p_gi_probe) const=0;
virtual VS::GIProbeDataFormat gi_probe_get_static_data_format(RID p_gi_probe) const=0;
virtual int gi_probe_get_static_data_width(RID p_probe) const=0;
virtual int gi_probe_get_static_data_height(RID p_probe) const=0;
virtual int gi_probe_get_static_data_depth(RID p_probe) const=0;
virtual RID gi_probe_get_data(RID p_probe)=0; //get data in case this is static
virtual uint32_t gi_probe_get_version(RID p_probe)=0;
virtual RID gi_probe_dynamic_data_create(int p_width,int p_height,int p_depth)=0;

View File

@ -629,6 +629,8 @@ public:
BIND1(texture_set_shrink_all_x2_on_set_data,bool)
BIND1(texture_debug_usage,List<TextureInfo>*)
BIND1(textures_keep_original,bool)
/* SKYBOX API */
BIND0R(RID,skybox_create)
@ -828,12 +830,6 @@ public:
BIND2(gi_probe_set_dynamic_data,RID,const DVector<int>& )
BIND1RC( DVector<int>,gi_probe_get_dynamic_data,RID)
BIND6(gi_probe_set_static_data,RID,const DVector<uint8_t>&,GIProbeDataFormat,int,int,int)
BIND1RC(DVector<uint8_t>,gi_probe_get_static_data,RID)
BIND1RC(GIProbeDataFormat,gi_probe_get_static_data_format,RID)
BIND1RC(int,gi_probe_get_static_data_width,RID)
BIND1RC(int,gi_probe_get_static_data_height,RID)
BIND1RC(int,gi_probe_get_static_data_depth,RID)
#undef BINDBASE

View File

@ -2390,7 +2390,8 @@ void VisualServerScene::_setup_gi_probe(Instance *p_instance) {
probe->dynamic.light_data=VSG::storage->gi_probe_get_dynamic_data(p_instance->base);
if (probe->dynamic.light_data.size()) {
if (probe->dynamic.light_data.size()==0)
return;
//using dynamic data
DVector<int>::Read r=probe->dynamic.light_data.read();
@ -2452,17 +2453,6 @@ void VisualServerScene::_setup_gi_probe(Instance *p_instance) {
VSG::scene_render->gi_probe_instance_set_bounds(probe->probe_instance,bounds.size/cell_size);
} else {
RID data = VSG::storage->gi_probe_get_data(p_instance->base);
probe->dynamic.enabled=false;
probe->invalid=!data.is_valid();
if (data.is_valid()) {
VSG::scene_render->gi_probe_instance_set_light_data(probe->probe_instance,p_instance->base,data);
}
}
probe->base_version=VSG::storage->gi_probe_get_version(p_instance->base);
}

View File

@ -139,6 +139,8 @@ public:
virtual void texture_debug_usage(List<TextureInfo> *r_info)=0;
virtual void textures_keep_original(bool p_enable)=0;
/* SKYBOX API */
virtual RID skybox_create()=0;
@ -470,20 +472,6 @@ public:
virtual void gi_probe_set_interior(RID p_probe,bool p_enable)=0;
virtual bool gi_probe_is_interior(RID p_probe) const=0;
enum GIProbeDataFormat {
GI_PROBE_DATA_RGBA8,
GI_PROBE_DATA_DXT5,
GI_PROBE_DATA_ETC2_EAC,
};
virtual void gi_probe_set_static_data(RID p_gi_probe,const DVector<uint8_t>& p_data,GIProbeDataFormat p_format,int p_width,int p_height,int p_depth)=0;
virtual DVector<uint8_t> gi_probe_get_static_data(RID p_gi_probe) const=0;
virtual GIProbeDataFormat gi_probe_get_static_data_format(RID p_gi_probe) const=0;
virtual int gi_probe_get_static_data_width(RID p_probe) const=0;
virtual int gi_probe_get_static_data_height(RID p_probe) const=0;
virtual int gi_probe_get_static_data_depth(RID p_probe) const=0;
/* CAMERA API */

View File

@ -99,6 +99,7 @@
#include "plugins/light_occluder_2d_editor_plugin.h"
#include "plugins/color_ramp_editor_plugin.h"
#include "plugins/collision_shape_2d_editor_plugin.h"
#include "plugins/gi_probe_editor_plugin.h"
#include "main/input_default.h"
// end
#include "tools/editor/io_plugins/editor_texture_import_plugin.h"
@ -5361,6 +5362,8 @@ void EditorNode::_bind_methods() {
EditorNode::EditorNode() {
VisualServer::get_singleton()->textures_keep_original(true);
EditorHelp::generate_doc(); //before any editor classes are crated
SceneState::set_disable_placeholders(true);
editor_initialize_certificates(); //for asset sharing
@ -6567,6 +6570,7 @@ EditorNode::EditorNode() {
add_editor_plugin( memnew( SpriteFramesEditorPlugin(this) ) );
add_editor_plugin( memnew( TextureRegionEditorPlugin(this) ) );
add_editor_plugin( memnew( Particles2DEditorPlugin(this) ) );
add_editor_plugin( memnew( GIProbeEditorPlugin(this) ) );
add_editor_plugin( memnew( Path2DEditorPlugin(this) ) );
// add_editor_plugin( memnew( PathEditorPlugin(this) ) );
//add_editor_plugin( memnew( BakedLightEditorPlugin(this) ) );

View File

@ -0,0 +1,58 @@
#include "gi_probe_editor_plugin.h"
void GIProbeEditorPlugin::_bake() {
if (gi_probe) {
gi_probe->bake();
}
}
void GIProbeEditorPlugin::edit(Object *p_object) {
GIProbe * s = p_object->cast_to<GIProbe>();
if (!s)
return;
gi_probe=s;
}
bool GIProbeEditorPlugin::handles(Object *p_object) const {
return p_object->is_type("GIProbe");
}
void GIProbeEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
bake->show();
} else {
bake->hide();
}
}
void GIProbeEditorPlugin::_bind_methods() {
ObjectTypeDB::bind_method("_bake",&GIProbeEditorPlugin::_bake);
}
GIProbeEditorPlugin::GIProbeEditorPlugin(EditorNode *p_node) {
editor=p_node;
bake = memnew( Button );
bake->set_text("Bake GI!");
bake->set_icon(editor->get_gui_base()->get_icon("BakedLight","EditorIcons"));
bake->hide();;
bake->connect("pressed",this,"_bake");
add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU,bake);
gi_probe=NULL;
}
GIProbeEditorPlugin::~GIProbeEditorPlugin() {
memdelete(bake);
}

View File

@ -0,0 +1,37 @@
#ifndef GIPROBEEDITORPLUGIN_H
#define GIPROBEEDITORPLUGIN_H
#include "tools/editor/editor_plugin.h"
#include "tools/editor/editor_node.h"
#include "scene/resources/material.h"
#include "scene/3d/gi_probe.h"
class GIProbeEditorPlugin : public EditorPlugin {
OBJ_TYPE( GIProbeEditorPlugin, EditorPlugin );
GIProbe *gi_probe;
Button *bake;
EditorNode *editor;
void _bake();
protected:
static void _bind_methods();
public:
virtual String get_name() const { return "GIProbe"; }
bool has_main_screen() const { return false; }
virtual void edit(Object *p_node);
virtual bool handles(Object *p_node) const;
virtual void make_visible(bool p_visible);
GIProbeEditorPlugin(EditorNode *p_node);
~GIProbeEditorPlugin();
};
#endif // GIPROBEEDITORPLUGIN_H