summaryrefslogtreecommitdiff
path: root/servers/visual
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-06-27 23:21:45 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-06-27 23:21:45 -0300
commit2af2a84a03fd707cfa4c682aff34d722343d8985 (patch)
tree50d064e8bba7d5efb5974e3fa3a67e076fb5ef8b /servers/visual
parent1cc96a4d7440d9e8a20f7dbf17cf5771170de83d (diff)
Misc Fixes
========== -NOTIFICATION_WM_QUIT fixed on android (seems tha way this is reported changed in newer sdk) -WIP implementation of APK Expansion APIs for publishing games larger than 50mb in Play Store -Feaures in the new tutorials are all present in the sourcecode -This (hopefully) should get rid of the animation list order getting corrupted -Improved 3D Scene Importer (Skeletons, Animations and other stuff were not being merged). Anything missing? -In code editor, the automatic syntax checker will only use file_exists() to check preload() else it might freeze the editor too much while typing if the preload is a big resource -Fixed bugs in PolygonPathFinder, stil pending to do a node and a demo
Diffstat (limited to 'servers/visual')
-rw-r--r--servers/visual/rasterizer.cpp127
-rw-r--r--servers/visual/rasterizer.h24
-rw-r--r--servers/visual/rasterizer_dummy.cpp42
-rw-r--r--servers/visual/rasterizer_dummy.h22
-rw-r--r--servers/visual/shader_language.cpp55
-rw-r--r--servers/visual/shader_language.h4
-rw-r--r--servers/visual/visual_server_raster.cpp51
-rw-r--r--servers/visual/visual_server_raster.h18
-rw-r--r--servers/visual/visual_server_wrap_mt.h15
9 files changed, 218 insertions, 140 deletions
diff --git a/servers/visual/rasterizer.cpp b/servers/visual/rasterizer.cpp
index e21848eac2..e242744867 100644
--- a/servers/visual/rasterizer.cpp
+++ b/servers/visual/rasterizer.cpp
@@ -134,23 +134,8 @@ RID Rasterizer::_create_shader(const FixedMaterialShaderKey& p_key) {
dcode+="uniform texture fmp_detail_tex;\n";
dcode+="uniform float fmp_detail;\n";
dcode+="color detail=tex( fmp_detail_tex,"+_TEXUVSTR(VS::FIXED_MATERIAL_PARAM_DETAIL)+");\n";
-
- switch(p_key.detail_blend) {
-
- case VS::MATERIAL_BLEND_MODE_MIX:
-
- dcode+="diffuse=vec4(mix(diffuse.rgb,detail.rgb,detail.a*fmp_detail),diffuse.a);\n";
- break;
- case VS::MATERIAL_BLEND_MODE_ADD:
- dcode+="diffuse=vec4(diffuse.rgb+detail.rgb*fmp_detail,diffuse.a);\n";
- break;
- case VS::MATERIAL_BLEND_MODE_SUB:
- dcode+="diffuse=vec4(diffuse.rgb+detail.rgb*fmp_detail,diffuse.a);\n";
- break;
- case VS::MATERIAL_BLEND_MODE_MUL:
- dcode+="diffuse=diffuse*mix(vec4(1,1,1,1),detail,fmp_detail);\n";
- break;
- }
+ //aways mix
+ dcode+="diffuse=vec4(mix(diffuse.rgb,detail.rgb,detail.a*fmp_detail),diffuse.a);\n";
code+=dcode;
}
@@ -223,6 +208,22 @@ RID Rasterizer::_create_shader(const FixedMaterialShaderKey& p_key) {
code+="GLOW=glow;\n";
+ if (p_key.texture_mask&(1<<VS::FIXED_MATERIAL_PARAM_SHADE_PARAM)) {
+
+ String scode;
+ scode+="uniform texture fmp_shade_param_tex;\n";
+ scode+="SHADE_PARAM=tex( fmp_shade_param_tex,"+_TEXUVSTR(VS::FIXED_MATERIAL_PARAM_SHADE_PARAM)+").r;\n";
+ code+=scode;
+ } else {
+
+ String scode;
+ scode+="uniform float fmp_shade_param;\n";
+ scode+="SHADE_PARAM=fmp_shade_param;\n";
+ code+=scode;
+
+ }
+
+
//print_line("**FRAGMENT SHADER GENERATED code: \n"+code);
String vcode;
@@ -235,12 +236,58 @@ RID Rasterizer::_create_shader(const FixedMaterialShaderKey& p_key) {
// vcode+="POINT_SIZE=10.0;\n";
}
+ String lcode;
+
+ switch(p_key.light_shader) {
+
+ case VS::FIXED_MATERIAL_LIGHT_SHADER_LAMBERT: {
+ //do nothing
+
+ } break;
+ case VS::FIXED_MATERIAL_LIGHT_SHADER_WRAP: {
+
+ lcode+="float NdotL = max(0.0,((dot( NORMAL, LIGHT_DIR )+SHADE_PARAM)/(1.0+SHADE_PARAM)));";
+ lcode+="vec3 half_vec = normalize(LIGHT_DIR + EYE_VEC);";
+ lcode+="float eye_light = max(dot(NORMAL, half_vec),0.0);";
+ lcode+="LIGHT = LIGHT_DIFFUSE * DIFFUSE * NdotL;";
+ lcode+="if (NdotL > 0.0) {";
+ lcode+="\tLIGHT+=LIGHT_SPECULAR * SPECULAR * pow( eye_light, SPECULAR_EXP );";
+ lcode+="};";
+
+ } break;
+ case VS::FIXED_MATERIAL_LIGHT_SHADER_VELVET: {
+ lcode+="float NdotL = max(0.0,dot( NORMAL, LIGHT_DIR ));";
+ lcode+="vec3 half_vec = normalize(LIGHT_DIR + EYE_VEC);";
+ lcode+="float eye_light = max(dot(NORMAL, half_vec),0.0);";
+ lcode+="LIGHT = LIGHT_DIFFUSE * DIFFUSE * NdotL;";
+ lcode+="float rim = (1.0-abs(dot(NORMAL,vec3(0,0,1))))*SHADE_PARAM;";
+ lcode+="LIGHT += LIGHT_DIFFUSE * DIFFUSE * rim;";
+ lcode+="if (NdotL > 0.0) {";
+ lcode+="\tLIGHT+=LIGHT_SPECULAR * SPECULAR * pow( eye_light, SPECULAR_EXP );";
+ lcode+="};";
+
+
+ } break;
+ case VS::FIXED_MATERIAL_LIGHT_SHADER_TOON: {
+
+ lcode+="float NdotL = dot( NORMAL, LIGHT_DIR );";
+ lcode+="vec3 light_ref = reflect( LIGHT_DIR, NORMAL );";
+ lcode+="float eye_light = clamp( dot( light_ref, vec3(0,0,0)-EYE_VEC), 0.0, 1.0 );";
+ lcode+="float NdotL_diffuse = smoothstep( max( SHADE_PARAM-0.05, 0.0-1.0), min( SHADE_PARAM+0.05, 1.0), NdotL );";
+ lcode+="float spec_radius=clamp((1.0-(SPECULAR_EXP/64.0)),0.0,1.0);";
+ lcode+="float NdotL_specular = smoothstep( max( spec_radius-0.05, 0.0), min( spec_radius+0.05, 1.0), eye_light )*max(NdotL,0);";
+ lcode+="LIGHT = NdotL_diffuse * LIGHT_DIFFUSE*DIFFUSE + NdotL_specular * LIGHT_SPECULAR*SPECULAR;";
+
+ } break;
+
+ }
+
//print_line("**VERTEX SHADER GENERATED code: \n"+vcode);
double tf = (OS::get_singleton()->get_ticks_usec()-t)/1000.0;
// print_line("generate: "+rtos(tf));
- shader_set_code(fms.shader,vcode,code,0,0);
+ shader_set_code(fms.shader,vcode,code,lcode,0,0);
fixed_material_shaders[p_key]=fms;
return fms.shader;
@@ -389,28 +436,6 @@ RID Rasterizer::fixed_material_get_texture(RID p_material,VS::FixedMaterialParam
return fm.texture[p_parameter];
}
-void Rasterizer::fixed_material_set_detail_blend_mode(RID p_material,VS::MaterialBlendMode p_mode){
-
- Map<RID,FixedMaterial*>::Element *E = fixed_materials.find(p_material);
- ERR_FAIL_COND(!E);
- FixedMaterial &fm=*E->get();
-
-
- fm.get_key();
- ERR_FAIL_INDEX(p_mode,4);
- fm.detail_blend=p_mode;
- if (!fm.dirty_list.in_list())
- fixed_material_dirty_list.add( &fm.dirty_list );
-
-}
-VS::MaterialBlendMode Rasterizer::fixed_material_get_detail_blend_mode(RID p_material) const{
-
- const Map<RID,FixedMaterial*>::Element *E = fixed_materials.find(p_material);
- ERR_FAIL_COND_V(!E,VS::MATERIAL_BLEND_MODE_MIX);
- const FixedMaterial &fm=*E->get();
-
- return fm.detail_blend;
-}
void Rasterizer::fixed_material_set_texcoord_mode(RID p_material,VS::FixedMaterialParam p_parameter, VS::FixedMaterialTexCoordMode p_mode) {
@@ -462,6 +487,28 @@ Transform Rasterizer::fixed_material_get_uv_transform(RID p_material) const {
return fm.uv_xform;
}
+void Rasterizer::fixed_material_set_light_shader(RID p_material,VS::FixedMaterialLightShader p_shader) {
+
+ Map<RID,FixedMaterial*>::Element *E = fixed_materials.find(p_material);
+ ERR_FAIL_COND(!E);
+ FixedMaterial &fm=*E->get();
+
+ fm.light_shader=p_shader;
+
+ if (!fm.dirty_list.in_list())
+ fixed_material_dirty_list.add( &fm.dirty_list );
+
+}
+
+VS::FixedMaterialLightShader Rasterizer::fixed_material_get_light_shader(RID p_material) const {
+
+ const Map<RID,FixedMaterial*>::Element *E = fixed_materials.find(p_material);
+ ERR_FAIL_COND_V(!E,VS::FIXED_MATERIAL_LIGHT_SHADER_LAMBERT);
+ const FixedMaterial &fm=*E->get();
+
+ return fm.light_shader;
+}
+
void Rasterizer::fixed_material_set_point_size(RID p_material,float p_size) {
Map<RID,FixedMaterial*>::Element *E = fixed_materials.find(p_material);
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h
index dc43a78984..2b02a81a44 100644
--- a/servers/visual/rasterizer.h
+++ b/servers/visual/rasterizer.h
@@ -51,7 +51,7 @@ protected:
struct {
uint16_t texcoord_mask;
uint8_t texture_mask;
- uint8_t detail_blend:2;
+ uint8_t light_shader:2;
bool use_alpha:1;
bool use_color_array:1;
bool use_pointsize:1;
@@ -85,7 +85,7 @@ protected:
bool use_pointsize;
float point_size;
Transform uv_xform;
- VS::MaterialBlendMode detail_blend;
+ VS::FixedMaterialLightShader light_shader;
RID texture[VS::FIXED_MATERIAL_PARAM_MAX];
Variant param[VS::FIXED_MATERIAL_PARAM_MAX];
VS::FixedMaterialTexCoordMode texture_tc[VS::FIXED_MATERIAL_PARAM_MAX];
@@ -103,7 +103,7 @@ protected:
k.use_color_array=use_color_array;
k.use_pointsize=use_pointsize;
k.discard_alpha=discard_alpha;
- k.detail_blend=detail_blend;
+ k.light_shader=light_shader;
k.valid=true;
for(int i=0;i<VS::FIXED_MATERIAL_PARAM_MAX;i++) {
if (texture[i].is_valid()) {
@@ -124,7 +124,7 @@ protected:
use_pointsize=false;
discard_alpha=false;
point_size=1.0;
- detail_blend=VS::MATERIAL_BLEND_MODE_MIX;
+ light_shader=VS::FIXED_MATERIAL_LIGHT_SHADER_LAMBERT;
for(int i=0;i<VS::FIXED_MATERIAL_PARAM_MAX;i++) {
texture_tc[i]=VS::FIXED_MATERIAL_TEXCOORD_UV;
}
@@ -192,9 +192,10 @@ public:
virtual void shader_set_mode(RID p_shader,VS::ShaderMode p_mode)=0;
virtual VS::ShaderMode shader_get_mode(RID p_shader) const=0;
- virtual void shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,int p_vertex_ofs=0,int p_fragment_ofs=0)=0;
+ virtual void shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,const String& p_light,int p_vertex_ofs=0,int p_fragment_ofs=0,int p_light_ofs=0)=0;
virtual String shader_get_fragment_code(RID p_shader) const=0;
virtual String shader_get_vertex_code(RID p_shader) const=0;
+ virtual String shader_get_light_code(RID p_shader) const=0;
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const=0;
@@ -211,11 +212,8 @@ public:
virtual void material_set_flag(RID p_material, VS::MaterialFlag p_flag,bool p_enabled)=0;
virtual bool material_get_flag(RID p_material,VS::MaterialFlag p_flag) const=0;
- virtual void material_set_hint(RID p_material, VS::MaterialHint p_hint,bool p_enabled)=0;
- virtual bool material_get_hint(RID p_material,VS::MaterialHint p_hint) const=0;
-
- virtual void material_set_shade_model(RID p_material, VS::MaterialShadeModel p_model)=0;
- virtual VS::MaterialShadeModel material_get_shade_model(RID p_material) const=0;
+ virtual void material_set_depth_draw_mode(RID p_material, VS::MaterialDepthDrawMode p_mode)=0;
+ virtual VS::MaterialDepthDrawMode material_get_depth_draw_mode(RID p_material) const=0;
virtual void material_set_blend_mode(RID p_material,VS::MaterialBlendMode p_mode)=0;
virtual VS::MaterialBlendMode material_get_blend_mode(RID p_material) const=0;
@@ -237,15 +235,15 @@ public:
virtual void fixed_material_set_texture(RID p_material,VS::FixedMaterialParam p_parameter, RID p_texture);
virtual RID fixed_material_get_texture(RID p_material,VS::FixedMaterialParam p_parameter) const;
- virtual void fixed_material_set_detail_blend_mode(RID p_material,VS::MaterialBlendMode p_mode);
- virtual VS::MaterialBlendMode fixed_material_get_detail_blend_mode(RID p_material) const;
-
virtual void fixed_material_set_texcoord_mode(RID p_material,VS::FixedMaterialParam p_parameter, VS::FixedMaterialTexCoordMode p_mode);
virtual VS::FixedMaterialTexCoordMode fixed_material_get_texcoord_mode(RID p_material,VS::FixedMaterialParam p_parameter) const;
virtual void fixed_material_set_uv_transform(RID p_material,const Transform& p_transform);
virtual Transform fixed_material_get_uv_transform(RID p_material) const;
+ virtual void fixed_material_set_light_shader(RID p_material,VS::FixedMaterialLightShader p_shader);
+ virtual VS::FixedMaterialLightShader fixed_material_get_light_shader(RID p_material) const;
+
virtual void fixed_material_set_point_size(RID p_material,float p_size);
virtual float fixed_material_get_point_size(RID p_material) const;
diff --git a/servers/visual/rasterizer_dummy.cpp b/servers/visual/rasterizer_dummy.cpp
index 3a04ba7504..e0c1932589 100644
--- a/servers/visual/rasterizer_dummy.cpp
+++ b/servers/visual/rasterizer_dummy.cpp
@@ -151,6 +151,7 @@ RID RasterizerDummy::shader_create(VS::ShaderMode p_mode) {
shader->mode=p_mode;
shader->fragment_line=0;
shader->vertex_line=0;
+ shader->light_line=0;
RID rid = shader_owner.make_rid(shader);
return rid;
@@ -174,16 +175,17 @@ VS::ShaderMode RasterizerDummy::shader_get_mode(RID p_shader) const {
return shader->mode;
}
+void RasterizerDummy::shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,const String& p_light,int p_vertex_ofs,int p_fragment_ofs,int p_light_ofs) {
-void RasterizerDummy::shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,int p_vertex_ofs,int p_fragment_ofs) {
-
Shader *shader=shader_owner.get(p_shader);
ERR_FAIL_COND(!shader);
shader->fragment_code=p_fragment;
shader->vertex_code=p_vertex;
+ shader->light_code=p_light;
shader->fragment_line=p_fragment_ofs;
shader->vertex_line=p_vertex_ofs;
+ shader->light_line=p_vertex_ofs;
}
@@ -204,6 +206,14 @@ String RasterizerDummy::shader_get_fragment_code(RID p_shader) const {
}
+String RasterizerDummy::shader_get_light_code(RID p_shader) const {
+
+ Shader *shader=shader_owner.get(p_shader);
+ ERR_FAIL_COND_V(!shader,String());
+ return shader->light_code;
+
+}
+
void RasterizerDummy::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const {
Shader *shader=shader_owner.get(p_shader);
@@ -274,39 +284,21 @@ bool RasterizerDummy::material_get_flag(RID p_material,VS::MaterialFlag p_flag)
}
-void RasterizerDummy::material_set_hint(RID p_material, VS::MaterialHint p_hint,bool p_enabled) {
+void RasterizerDummy::material_set_depth_draw_mode(RID p_material, VS::MaterialDepthDrawMode p_mode) {
Material *material = material_owner.get(p_material);
ERR_FAIL_COND(!material);
- ERR_FAIL_INDEX(p_hint,VS::MATERIAL_HINT_MAX);
- material->hints[p_hint]=p_enabled;
-
+ material->depth_draw_mode=p_mode;
}
-bool RasterizerDummy::material_get_hint(RID p_material,VS::MaterialHint p_hint) const {
+VS::MaterialDepthDrawMode RasterizerDummy::material_get_depth_draw_mode(RID p_material) const{
Material *material = material_owner.get(p_material);
- ERR_FAIL_COND_V(!material,false);
- ERR_FAIL_INDEX_V(p_hint,VS::MATERIAL_HINT_MAX,false);
- return material->hints[p_hint];
+ ERR_FAIL_COND_V(!material,VS::MATERIAL_DEPTH_DRAW_ALWAYS);
+ return material->depth_draw_mode;
}
-void RasterizerDummy::material_set_shade_model(RID p_material, VS::MaterialShadeModel p_model) {
-
- Material *material = material_owner.get(p_material);
- ERR_FAIL_COND(!material);
- material->shade_model=p_model;
-
-};
-
-VS::MaterialShadeModel RasterizerDummy::material_get_shade_model(RID p_material) const {
-
- Material *material = material_owner.get(p_material);
- ERR_FAIL_COND_V(!material,VS::MATERIAL_SHADE_MODEL_LAMBERT);
- return material->shade_model;
-};
-
void RasterizerDummy::material_set_blend_mode(RID p_material,VS::MaterialBlendMode p_mode) {
diff --git a/servers/visual/rasterizer_dummy.h b/servers/visual/rasterizer_dummy.h
index a837d54b9b..01ae6c7644 100644
--- a/servers/visual/rasterizer_dummy.h
+++ b/servers/visual/rasterizer_dummy.h
@@ -71,10 +71,12 @@ class RasterizerDummy : public Rasterizer {
String vertex_code;
String fragment_code;
+ String light_code;
VS::ShaderMode mode;
Map<StringName,Variant> params;
int fragment_line;
int vertex_line;
+ int light_line;
bool valid;
bool has_alpha;
bool use_world_transform;
@@ -87,9 +89,8 @@ class RasterizerDummy : public Rasterizer {
struct Material {
bool flags[VS::MATERIAL_FLAG_MAX];
- bool hints[VS::MATERIAL_HINT_MAX];
- VS::MaterialShadeModel shade_model;
+ VS::MaterialDepthDrawMode depth_draw_mode;
VS::MaterialBlendMode blend_mode;
@@ -107,9 +108,8 @@ class RasterizerDummy : public Rasterizer {
for(int i=0;i<VS::MATERIAL_FLAG_MAX;i++)
flags[i]=false;
flags[VS::MATERIAL_FLAG_VISIBLE]=true;
- for(int i=0;i<VS::MATERIAL_HINT_MAX;i++)
- hints[i]=false;
+ depth_draw_mode=VS::MATERIAL_DEPTH_DRAW_OPAQUE_ONLY;
line_width=1;
blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
point_size = 1.0;
@@ -296,7 +296,7 @@ class RasterizerDummy : public Rasterizer {
vars[VS::LIGHT_PARAM_ENERGY]=1.0;
vars[VS::LIGHT_PARAM_RADIUS]=1.0;
vars[VS::LIGHT_PARAM_SHADOW_Z_OFFSET]=0.05;
- colors[VS::LIGHT_COLOR_AMBIENT]=Color(0,0,0);
+
colors[VS::LIGHT_COLOR_DIFFUSE]=Color(1,1,1);
colors[VS::LIGHT_COLOR_SPECULAR]=Color(1,1,1);
shadow_enabled=false;
@@ -331,7 +331,7 @@ class RasterizerDummy : public Rasterizer {
fx_param[VS::ENV_FX_PARAM_DOF_BLUR_BEGIN]=100.0;
fx_param[VS::ENV_FX_PARAM_DOF_BLUR_RANGE]=10.0;
fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE]=0.4;
- fx_param[VS::ENV_FX_PARAM_HDR_SCALAR]=1.0;
+ fx_param[VS::ENV_FX_PARAM_HDR_WHITE]=1.0;
fx_param[VS::ENV_FX_PARAM_HDR_GLOW_TRESHOLD]=0.95;
fx_param[VS::ENV_FX_PARAM_HDR_GLOW_SCALE]=0.2;
fx_param[VS::ENV_FX_PARAM_HDR_MIN_LUMINANCE]=0.4;
@@ -415,9 +415,10 @@ public:
virtual void shader_set_mode(RID p_shader,VS::ShaderMode p_mode);
virtual VS::ShaderMode shader_get_mode(RID p_shader) const;
- virtual void shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,int p_vertex_ofs=0,int p_fragment_ofs=0);
+ virtual void shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,const String& p_light,int p_vertex_ofs=0,int p_fragment_ofs=0,int p_light_ofs=0);
virtual String shader_get_fragment_code(RID p_shader) const;
virtual String shader_get_vertex_code(RID p_shader) const;
+ virtual String shader_get_light_code(RID p_shader) const;
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
@@ -434,11 +435,8 @@ public:
virtual void material_set_flag(RID p_material, VS::MaterialFlag p_flag,bool p_enabled);
virtual bool material_get_flag(RID p_material,VS::MaterialFlag p_flag) const;
- virtual void material_set_hint(RID p_material, VS::MaterialHint p_hint,bool p_enabled);
- virtual bool material_get_hint(RID p_material,VS::MaterialHint p_hint) const;
-
- virtual void material_set_shade_model(RID p_material, VS::MaterialShadeModel p_model);
- virtual VS::MaterialShadeModel material_get_shade_model(RID p_material) const;
+ virtual void material_set_depth_draw_mode(RID p_material, VS::MaterialDepthDrawMode p_mode);
+ virtual VS::MaterialDepthDrawMode material_get_depth_draw_mode(RID p_material) const;
virtual void material_set_blend_mode(RID p_material,VS::MaterialBlendMode p_mode);
virtual VS::MaterialBlendMode material_get_blend_mode(RID p_material) const;
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index cdc1f678e7..16a725010d 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -859,7 +859,20 @@ const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
{"mix",TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_FLOAT,TYPE_VOID}},
{"mix",TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
{"step",TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
+ {"step",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
{"step",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+ {"step",TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
+ {"step",TYPE_VEC2,{TYPE_FLOAT,TYPE_VEC2,TYPE_VOID}},
+ {"step",TYPE_VEC3,{TYPE_FLOAT,TYPE_VEC3,TYPE_VOID}},
+ {"step",TYPE_VEC4,{TYPE_FLOAT,TYPE_VEC4,TYPE_VOID}},
+ {"smoothstep",TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
+ {"smoothstep",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"smoothstep",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
+ {"smoothstep",TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
+ {"smoothstep",TYPE_VEC2,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VEC2,TYPE_VOID}},
+ {"smoothstep",TYPE_VEC3,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VEC3,TYPE_VOID}},
+ {"smoothstep",TYPE_VEC4,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VEC4,TYPE_VOID}},
+
//intrinsics - geometric
{"length",TYPE_FLOAT,{TYPE_VEC2,TYPE_VOID}},
{"length",TYPE_FLOAT,{TYPE_VEC3,TYPE_VOID}},
@@ -1045,6 +1058,27 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::fragment_builtins_defs[]={
{ NULL, TYPE_VOID}
};
+
+const ShaderLanguage::BuiltinsDef ShaderLanguage::light_builtins_defs[]={
+
+ { "NORMAL", TYPE_VEC3},
+ { "LIGHT_DIR", TYPE_VEC3},
+ { "LIGHT_DIFFUSE", TYPE_VEC3},
+ { "LIGHT_SPECULAR", TYPE_VEC3},
+ { "EYE_VEC", TYPE_VEC3},
+ { "DIFFUSE", TYPE_VEC3},
+ { "SPECULAR", TYPE_VEC3},
+ { "SPECULAR_EXP", TYPE_FLOAT},
+ { "SHADE_PARAM", TYPE_FLOAT},
+ { "LIGHT", TYPE_VEC3},
+ { "POINT_COORD", TYPE_VEC2},
+// { "SCREEN_POS", TYPE_VEC2},
+// { "SCREEN_TEXEL_SIZE", TYPE_VEC2},
+ { "TIME", TYPE_FLOAT},
+ { NULL, TYPE_VOID}
+
+};
+
const ShaderLanguage::BuiltinsDef ShaderLanguage::postprocess_fragment_builtins_defs[]={
{ "IN_COLOR", TYPE_VEC3},
@@ -2286,6 +2320,13 @@ Error ShaderLanguage::parse(const Vector<Token>& p_tokens,ShaderType p_type,Comp
idx++;
}
} break;
+ case SHADER_MATERIAL_LIGHT: {
+ int idx=0;
+ while (light_builtins_defs[idx].name) {
+ parser.program->builtin_variables[light_builtins_defs[idx].name]=light_builtins_defs[idx].type;
+ idx++;
+ }
+ } break;
case SHADER_POST_PROCESS: {
int idx=0;
while (postprocess_fragment_builtins_defs[idx].name) {
@@ -2306,8 +2347,9 @@ Error ShaderLanguage::parse(const Vector<Token>& p_tokens,ShaderType p_type,Comp
t = OS::get_singleton()->get_ticks_usec();
- if (p_compile_func)
- p_compile_func(p_userdata,parser.program);
+ if (p_compile_func) {
+ err = p_compile_func(p_userdata,parser.program);
+ }
tf = (OS::get_singleton()->get_ticks_usec()-t)/1000.0;
//print_line("compile time: "+rtos(tf));
@@ -2318,7 +2360,7 @@ Error ShaderLanguage::parse(const Vector<Token>& p_tokens,ShaderType p_type,Comp
memdelete( parser.nodegc.front()->get() );
parser.nodegc.pop_front();
}
- return OK;
+ return err;
}
Error ShaderLanguage::compile(const String& p_code,ShaderType p_type,CompileFunc p_compile_func,void *p_userdata,String *r_error,int *r_err_line,int *r_err_column) {
@@ -2372,6 +2414,13 @@ void ShaderLanguage::get_keyword_list(ShaderType p_type, List<String> *p_keyword
idx++;
}
} break;
+ case SHADER_MATERIAL_LIGHT: {
+ idx=0;
+ while (light_builtins_defs[idx].name) {
+ p_keywords->push_back(light_builtins_defs[idx].name);
+ idx++;
+ }
+ } break;
case SHADER_POST_PROCESS: {
idx=0;
while (postprocess_fragment_builtins_defs[idx].name) {
diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h
index 9455e677cf..36f5bd64c7 100644
--- a/servers/visual/shader_language.h
+++ b/servers/visual/shader_language.h
@@ -46,6 +46,7 @@ public:
enum ShaderType {
SHADER_MATERIAL_VERTEX,
SHADER_MATERIAL_FRAGMENT,
+ SHADER_MATERIAL_LIGHT,
SHADER_POST_PROCESS,
};
@@ -215,7 +216,7 @@ public:
ProgramNode() { type=TYPE_PROGRAM; }
};
- typedef void (*CompileFunc)(void*,ProgramNode*);
+ typedef Error (*CompileFunc)(void*,ProgramNode*);
struct VarInfo {
@@ -360,6 +361,7 @@ private:
static const BuiltinsDef vertex_builtins_defs[];
static const BuiltinsDef fragment_builtins_defs[];
+ static const BuiltinsDef light_builtins_defs[];
static const BuiltinsDef postprocess_fragment_builtins_defs[];
static DataType get_token_datatype(TokenType p_type);
diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp
index 4e14e8b26c..f171b47e9c 100644
--- a/servers/visual/visual_server_raster.cpp
+++ b/servers/visual/visual_server_raster.cpp
@@ -130,10 +130,10 @@ VisualServer::ShaderMode VisualServerRaster::shader_get_mode(RID p_shader) const
}
-void VisualServerRaster::shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,int p_vertex_ofs,int p_fragment_ofs) {
+void VisualServerRaster::shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,const String& p_light,int p_vertex_ofs,int p_fragment_ofs,int p_light_ofs) {
VS_CHANGED;
- rasterizer->shader_set_code(p_shader,p_vertex,p_fragment,p_vertex_ofs,p_fragment_ofs);
+ rasterizer->shader_set_code(p_shader,p_vertex,p_fragment,p_light,p_vertex_ofs,p_fragment_ofs,p_light_ofs);
}
String VisualServerRaster::shader_get_vertex_code(RID p_shader) const{
@@ -146,6 +146,11 @@ String VisualServerRaster::shader_get_fragment_code(RID p_shader) const{
return rasterizer->shader_get_fragment_code(p_shader);
}
+String VisualServerRaster::shader_get_light_code(RID p_shader) const{
+
+ return rasterizer->shader_get_fragment_code(p_shader);
+}
+
void VisualServerRaster::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const {
return rasterizer->shader_get_param_list(p_shader,p_param_list);
@@ -187,27 +192,16 @@ void VisualServerRaster::material_set_flag(RID p_material, MaterialFlag p_flag,b
rasterizer->material_set_flag(p_material,p_flag,p_enabled);
}
-void VisualServerRaster::material_set_hint(RID p_material, MaterialHint p_hint,bool p_enabled) {
+void VisualServerRaster::material_set_depth_draw_mode(RID p_material, MaterialDepthDrawMode p_mode) {
VS_CHANGED;
- rasterizer->material_set_hint(p_material,p_hint,p_enabled);
-}
-
-bool VisualServerRaster::material_get_hint(RID p_material,MaterialHint p_hint) const {
-
- return rasterizer->material_get_hint(p_material,p_hint);
+ rasterizer->material_set_depth_draw_mode(p_material,p_mode);
}
-void VisualServerRaster::material_set_shade_model(RID p_material, MaterialShadeModel p_model) {
- VS_CHANGED;
- rasterizer->material_set_shade_model(p_material,p_model);
-}
-
-VisualServer::MaterialShadeModel VisualServerRaster::material_get_shade_model(RID p_material) const {
-
- return rasterizer->material_get_shade_model(p_material);
+VS::MaterialDepthDrawMode VisualServerRaster::material_get_depth_draw_mode(RID p_material) const {
+ return rasterizer->material_get_depth_draw_mode(p_material);
}
@@ -273,17 +267,6 @@ RID VisualServerRaster::fixed_material_get_texture(RID p_material,FixedMaterialP
}
-void VisualServerRaster::fixed_material_set_detail_blend_mode(RID p_material,MaterialBlendMode p_mode) {
- VS_CHANGED;
- rasterizer->fixed_material_set_detail_blend_mode(p_material,p_mode);
-}
-
-VS::MaterialBlendMode VisualServerRaster::fixed_material_get_detail_blend_mode(RID p_material) const {
-
- return rasterizer->fixed_material_get_detail_blend_mode(p_material);
-}
-
-
void VisualServerRaster::fixed_material_set_texcoord_mode(RID p_material,FixedMaterialParam p_parameter, FixedMaterialTexCoordMode p_mode) {
@@ -318,6 +301,18 @@ Transform VisualServerRaster::fixed_material_get_uv_transform(RID p_material) co
return rasterizer->fixed_material_get_uv_transform(p_material);
}
+void VisualServerRaster::fixed_material_set_light_shader(RID p_material,FixedMaterialLightShader p_shader) {
+
+ VS_CHANGED;
+ rasterizer->fixed_material_set_light_shader(p_material,p_shader);
+
+}
+
+VisualServerRaster::FixedMaterialLightShader VisualServerRaster::fixed_material_get_light_shader(RID p_material) const{
+
+ return rasterizer->fixed_material_get_light_shader(p_material);
+}
+
/* MESH API */
diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h
index ddc30bb2ee..0368780bfb 100644
--- a/servers/visual/visual_server_raster.h
+++ b/servers/visual/visual_server_raster.h
@@ -691,9 +691,10 @@ public:
virtual void shader_set_mode(RID p_shader,ShaderMode p_mode);
virtual ShaderMode shader_get_mode(RID p_shader) const;
- virtual void shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,int p_vertex_ofs=0,int p_fragment_ofs=0);
+ virtual void shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,const String& p_light,int p_vertex_ofs=0,int p_fragment_ofs=0,int p_light_ofs=0);
virtual String shader_get_vertex_code(RID p_shader) const;
virtual String shader_get_fragment_code(RID p_shader) const;
+ virtual String shader_get_light_code(RID p_shader) const;
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
@@ -710,11 +711,8 @@ public:
virtual void material_set_flag(RID p_material, MaterialFlag p_flag,bool p_enabled);
virtual bool material_get_flag(RID p_material,MaterialFlag p_flag) const;
- virtual void material_set_hint(RID p_material, MaterialHint p_hint,bool p_enabled);
- virtual bool material_get_hint(RID p_material,MaterialHint p_hint) const;
-
- virtual void material_set_shade_model(RID p_material, MaterialShadeModel p_model);
- virtual MaterialShadeModel material_get_shade_model(RID p_material) const;
+ virtual void material_set_depth_draw_mode(RID p_material, MaterialDepthDrawMode p_mode);
+ virtual MaterialDepthDrawMode material_get_depth_draw_mode(RID p_material) const;
virtual void material_set_blend_mode(RID p_material,MaterialBlendMode p_mode);
virtual MaterialBlendMode material_get_blend_mode(RID p_material) const;
@@ -736,16 +734,16 @@ public:
virtual void fixed_material_set_texture(RID p_material,FixedMaterialParam p_parameter, RID p_texture);
virtual RID fixed_material_get_texture(RID p_material,FixedMaterialParam p_parameter) const;
- virtual void fixed_material_set_detail_blend_mode(RID p_material,MaterialBlendMode p_mode);
- virtual MaterialBlendMode fixed_material_get_detail_blend_mode(RID p_material) const;
-
-
virtual void fixed_material_set_texcoord_mode(RID p_material,FixedMaterialParam p_parameter, FixedMaterialTexCoordMode p_mode);
virtual FixedMaterialTexCoordMode fixed_material_get_texcoord_mode(RID p_material,FixedMaterialParam p_parameter) const;
+
virtual void fixed_material_set_uv_transform(RID p_material,const Transform& p_transform);
virtual Transform fixed_material_get_uv_transform(RID p_material) const;
+ virtual void fixed_material_set_light_shader(RID p_material,FixedMaterialLightShader p_shader);
+ virtual FixedMaterialLightShader fixed_material_get_light_shader(RID p_material) const;
+
virtual void fixed_material_set_point_size(RID p_material,float p_size);
virtual float fixed_material_get_point_size(RID p_material) const;
diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h
index f807a4b3a9..d577ca0c59 100644
--- a/servers/visual/visual_server_wrap_mt.h
+++ b/servers/visual/visual_server_wrap_mt.h
@@ -647,9 +647,10 @@ public:
FUNC1R(RID,shader_create,ShaderMode);
FUNC2(shader_set_mode,RID,ShaderMode);
FUNC1RC(ShaderMode,shader_get_mode,RID);
- FUNC5(shader_set_code,RID,const String&,const String&,int,int);
+ FUNC7(shader_set_code,RID,const String&,const String&,const String&,int,int,int);
FUNC1RC(String,shader_get_vertex_code,RID);
FUNC1RC(String,shader_get_fragment_code,RID);
+ FUNC1RC(String,shader_get_light_code,RID);
FUNC2SC(shader_get_param_list,RID,List<PropertyInfo>*);
/*virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) {
@@ -675,11 +676,8 @@ public:
FUNC3(material_set_flag,RID,MaterialFlag,bool);
FUNC2RC(bool,material_get_flag,RID,MaterialFlag);
- FUNC3(material_set_hint,RID,MaterialHint,bool);
- FUNC2RC(bool,material_get_hint,RID,MaterialHint);
-
- FUNC2(material_set_shade_model,RID,MaterialShadeModel);
- FUNC1RC(MaterialShadeModel,material_get_shade_model,RID);
+ FUNC2(material_set_depth_draw_mode,RID,MaterialDepthDrawMode);
+ FUNC1RC(MaterialDepthDrawMode,material_get_depth_draw_mode,RID);
FUNC2(material_set_blend_mode,RID,MaterialBlendMode);
FUNC1RC(MaterialBlendMode,material_get_blend_mode,RID);
@@ -701,13 +699,14 @@ public:
FUNC3(fixed_material_set_texture,RID ,FixedMaterialParam, RID );
FUNC2RC(RID, fixed_material_get_texture,RID,FixedMaterialParam);
- FUNC2(fixed_material_set_detail_blend_mode,RID ,MaterialBlendMode );
- FUNC1RC(MaterialBlendMode, fixed_material_get_detail_blend_mode,RID);
FUNC3(fixed_material_set_texcoord_mode,RID,FixedMaterialParam, FixedMaterialTexCoordMode );
FUNC2RC(FixedMaterialTexCoordMode, fixed_material_get_texcoord_mode,RID,FixedMaterialParam);
+ FUNC2(fixed_material_set_light_shader,RID,FixedMaterialLightShader);
+ FUNC1RC(FixedMaterialLightShader, fixed_material_get_light_shader,RID);
+
FUNC2(fixed_material_set_uv_transform,RID,const Transform&);
FUNC1RC(Transform, fixed_material_get_uv_transform,RID);