New Demo, Screen Space Shaders

-Fixes to screen space shaders.
-Fixes to isometric light demo.
This commit is contained in:
Juan Linietsky 2015-03-10 00:53:09 -03:00
parent 3fc9017fbb
commit 91744e9ed3
17 changed files with 76 additions and 8 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 KiB

View file

@ -0,0 +1 @@
repeat=true

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 906 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

View file

@ -0,0 +1,4 @@
[application]
name="Screen-Space Shaders"
main_scene="res://screen_shaders.scn"

View file

@ -0,0 +1,32 @@
extends Control
# member variables here, example:
# var a=2
# var b="textvar"
func _ready():
# Initialization here
for c in get_node("pictures").get_children():
get_node("picture").add_item("PIC: "+c.get_name())
for c in get_node("effects").get_children():
get_node("effect").add_item("FX: "+c.get_name())
pass
func _on_picture_item_selected( ID ):
for c in range(get_node("pictures").get_child_count()):
if (ID==c):
get_node("pictures").get_child(c).show()
else:
get_node("pictures").get_child(c).hide()
func _on_effect_item_selected( ID ):
for c in range(get_node("effects").get_child_count()):
if (ID==c):
get_node("effects").get_child(c).show()
else:
get_node("effects").get_child(c).hide()

Binary file not shown.

View file

@ -61,6 +61,7 @@ static String _typestr(SL::DataType p_type) {
case SL::TYPE_VEC2: return "vec2";
case SL::TYPE_VEC3: return "vec3";
case SL::TYPE_VEC4: return "vec4";
case SL::TYPE_MAT2: return "mat2";
case SL::TYPE_MAT3: return "mat3";
case SL::TYPE_MAT4: return "mat4";
case SL::TYPE_TEXTURE: return "sampler2D";
@ -284,6 +285,7 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
case SL::TYPE_VEC2: { Vector2 v = cnode->value; code="vec2("+_mknum(v.x)+", "+_mknum(v.y)+")"; } break;
case SL::TYPE_VEC3: { Vector3 v = cnode->value; code="vec3("+_mknum(v.x)+", "+_mknum(v.y)+", "+_mknum(v.z)+")"; } break;
case SL::TYPE_VEC4: { Plane v = cnode->value; code="vec4("+_mknum(v.normal.x)+", "+_mknum(v.normal.y)+", "+_mknum(v.normal.z)+", "+_mknum(v.d)+")"; } break;
case SL::TYPE_MAT2: { Matrix32 x = cnode->value; code="mat2( vec2("+_mknum(x[0][0])+", "+_mknum(x[0][1])+"), vec2("+_mknum(x[1][0])+", "+_mknum(x[1][1])+"))"; } break;
case SL::TYPE_MAT3: { Matrix3 x = cnode->value; code="mat3( vec3("+_mknum(x.get_axis(0).x)+", "+_mknum(x.get_axis(0).y)+", "+_mknum(x.get_axis(0).z)+"), vec3("+_mknum(x.get_axis(1).x)+", "+_mknum(x.get_axis(1).y)+", "+_mknum(x.get_axis(1).z)+"), vec3("+_mknum(x.get_axis(2).x)+", "+_mknum(x.get_axis(2).y)+", "+_mknum(x.get_axis(2).z)+"))"; } break;
case SL::TYPE_MAT4: { Transform x = cnode->value; code="mat4( vec4("+_mknum(x.basis.get_axis(0).x)+", "+_mknum(x.basis.get_axis(0).y)+", "+_mknum(x.basis.get_axis(0).z)+",0.0), vec4("+_mknum(x.basis.get_axis(1).x)+", "+_mknum(x.basis.get_axis(1).y)+", "+_mknum(x.basis.get_axis(1).z)+",0.0), vec4("+_mknum(x.basis.get_axis(2).x)+", "+_mknum(x.basis.get_axis(2).y)+", "+_mknum(x.basis.get_axis(2).z)+",0.0), vec4("+_mknum(x.origin.x)+", "+_mknum(x.origin.y)+", "+_mknum(x.origin.z)+",1.0))"; } break;
default: code="<error: "+Variant::get_type_name(cnode->value.get_type())+" ("+itos(cnode->datatype)+">";
@ -476,6 +478,11 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
m="[2]";
else if (mnode->name=="w")
m="[3]";
} else if (mnode->basetype==SL::TYPE_MAT2) {
if (mnode->name=="x")
m="[0]";
else if (mnode->name=="y")
m="[1]";
} else if (mnode->basetype==SL::TYPE_MAT3) {
if (mnode->name=="x")
@ -657,6 +664,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
replace_table["vec2" ]= "vec2";
replace_table["vec3" ]= "vec3";
replace_table["vec4" ]= "vec4";
replace_table["mat2" ]= "mat2";
replace_table["mat3" ]= "mat3";
replace_table["mat4" ]= "mat4";
replace_table["texture" ]= "sampler2D";

View file

@ -56,6 +56,7 @@ const char * ShaderLanguage::token_names[TK_MAX]={
"TYPE_VEC2",
"TYPE_VEC3",
"TYPE_VEC4",
"TYPE_MAT2",
"TYPE_MAT3",
"TYPE_MAT4",
"TYPE_TEXTURE",
@ -403,9 +404,9 @@ ShaderLanguage::Token ShaderLanguage::read_token(const CharType* p_text,int p_le
{TK_TYPE_TEXTURE,"texture"},
{TK_TYPE_CUBEMAP,"cubemap"},
{TK_TYPE_COLOR,"color"},
/*
{TK_TYPE_MAT2,"mat2"},
{TK_TYPE_MAT3,"mat3"},
/*{TK_TYPE_MAT3,"mat3"},
{TK_TYPE_MAT4,"mat3"},*/
{TK_TYPE_MAT3,"mat3"},
{TK_TYPE_MAT4,"mat4"},
@ -511,6 +512,7 @@ bool ShaderLanguage::is_token_datatype(TokenType p_type) {
(p_type==TK_TYPE_VEC3) ||
(p_type==TK_TYPE_VEC4) ||
(p_type==TK_TYPE_COLOR) ||
(p_type==TK_TYPE_MAT2) ||
(p_type==TK_TYPE_MAT3) ||
(p_type==TK_TYPE_MAT4) ||
(p_type==TK_TYPE_CUBEMAP) ||
@ -529,6 +531,7 @@ ShaderLanguage::DataType ShaderLanguage::get_token_datatype(TokenType p_type) {
case TK_TYPE_VEC3: return TYPE_VEC3;
case TK_TYPE_VEC4: return TYPE_VEC4;
case TK_TYPE_COLOR: return TYPE_VEC4;
case TK_TYPE_MAT2: return TYPE_MAT2;
case TK_TYPE_MAT3: return TYPE_MAT3;
case TK_TYPE_MAT4: return TYPE_MAT4;
case TK_TYPE_TEXTURE: return TYPE_TEXTURE;
@ -550,6 +553,7 @@ String ShaderLanguage::get_datatype_name(DataType p_type) {
case TYPE_VEC2: return "vec2";
case TYPE_VEC3: return "vec3";
case TYPE_VEC4: return "vec4";
case TYPE_MAT2: return "mat2";
case TYPE_MAT3: return "mat3";
case TYPE_MAT4: return "mat4";
case TYPE_TEXTURE: return "texture";
@ -570,6 +574,7 @@ bool ShaderLanguage::is_token_nonvoid_datatype(TokenType p_type) {
(p_type==TK_TYPE_VEC3) ||
(p_type==TK_TYPE_VEC4) ||
(p_type==TK_TYPE_COLOR) ||
(p_type==TK_TYPE_MAT2) ||
(p_type==TK_TYPE_MAT3) ||
(p_type==TK_TYPE_MAT4) ||
(p_type==TK_TYPE_TEXTURE) ||
@ -782,6 +787,7 @@ const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
{"vec4",TYPE_VEC4,{TYPE_FLOAT,TYPE_VEC3,TYPE_VOID}},
{"vec4",TYPE_VEC4,{TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
{"vec4",TYPE_VEC4,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
{"mat2",TYPE_MAT2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
{"mat3",TYPE_MAT3,{TYPE_VEC3,TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
{"mat4",TYPE_MAT4,{TYPE_VEC4,TYPE_VEC4,TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
//intrinsics - trigonometry
@ -918,6 +924,7 @@ const ShaderLanguage::OperatorDef ShaderLanguage::operator_defs[]={
{OP_ASSIGN,TYPE_VOID,{TYPE_VEC2,TYPE_VEC2}},
{OP_ASSIGN,TYPE_VOID,{TYPE_VEC3,TYPE_VEC3}},
{OP_ASSIGN,TYPE_VOID,{TYPE_VEC4,TYPE_VEC4}},
{OP_ASSIGN,TYPE_VOID,{TYPE_MAT2,TYPE_MAT2}},
{OP_ASSIGN,TYPE_VOID,{TYPE_MAT3,TYPE_MAT3}},
{OP_ASSIGN,TYPE_VOID,{TYPE_MAT4,TYPE_MAT4}},
{OP_ADD,TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT}},
@ -933,6 +940,8 @@ const ShaderLanguage::OperatorDef ShaderLanguage::operator_defs[]={
{OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_FLOAT}},
{OP_MUL,TYPE_VEC2,{TYPE_FLOAT,TYPE_VEC2}},
{OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_MAT3}},
{OP_MUL,TYPE_VEC2,{TYPE_MAT2,TYPE_VEC2}},
{OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_MAT2}},
{OP_MUL,TYPE_VEC2,{TYPE_MAT3,TYPE_VEC2}},
{OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_MAT4}},
{OP_MUL,TYPE_VEC2,{TYPE_MAT4,TYPE_VEC2}},
@ -947,6 +956,7 @@ const ShaderLanguage::OperatorDef ShaderLanguage::operator_defs[]={
{OP_MUL,TYPE_VEC4,{TYPE_FLOAT,TYPE_VEC4}},
{OP_MUL,TYPE_VEC4,{TYPE_MAT4,TYPE_VEC4}},
{OP_MUL,TYPE_VEC4,{TYPE_VEC4,TYPE_MAT4}},
{OP_MUL,TYPE_MAT2,{TYPE_MAT2,TYPE_MAT2}},
{OP_MUL,TYPE_MAT3,{TYPE_MAT3,TYPE_MAT3}},
{OP_MUL,TYPE_MAT4,{TYPE_MAT4,TYPE_MAT4}},
{OP_DIV,TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT}},
@ -976,15 +986,15 @@ const ShaderLanguage::OperatorDef ShaderLanguage::operator_defs[]={
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_FLOAT,TYPE_FLOAT}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC2,TYPE_VEC2}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC2,TYPE_FLOAT}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_MAT3,TYPE_VEC2}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_MAT4,TYPE_VEC2}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC2,TYPE_MAT2}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_MAT2,TYPE_MAT2}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC3,TYPE_MAT3}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC3,TYPE_VEC3}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC3,TYPE_FLOAT}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_MAT3,TYPE_VEC3}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_MAT4,TYPE_VEC3}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC3,TYPE_MAT4}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC4,TYPE_VEC4}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC4,TYPE_FLOAT}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_MAT4,TYPE_VEC4}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_VEC4,TYPE_MAT4}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_MAT3,TYPE_MAT3}},
{OP_ASSIGN_MUL,TYPE_VOID,{TYPE_MAT4,TYPE_MAT4}},
{OP_ASSIGN_DIV,TYPE_VOID,{TYPE_FLOAT,TYPE_FLOAT}},
@ -1566,6 +1576,7 @@ Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_ex
case TYPE_VEC2: name="vec2"; break;
case TYPE_VEC3: name="vec3"; break;
case TYPE_VEC4: name="vec4"; break;
case TYPE_MAT2: name="mat2"; break;
case TYPE_MAT3: name="mat3"; break;
case TYPE_MAT4: name="mat4"; break;
default: ERR_FAIL_V(ERR_BUG);
@ -1860,6 +1871,7 @@ Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_ex
}
} break;
case TYPE_MAT2: ok=(ident=="x" || ident=="y"); member_type=TYPE_VEC2; break;
case TYPE_MAT3: ok=(ident=="x" || ident=="y" || ident=="z" ); member_type=TYPE_VEC3; break;
case TYPE_MAT4: ok=(ident=="x" || ident=="y" || ident=="z" || ident=="w"); member_type=TYPE_VEC4; break;
default: {}
@ -2246,6 +2258,7 @@ Error ShaderLanguage::parse_variable_declaration(Parser& parser,BlockNode *p_blo
case TYPE_VEC2: con->value=Vector2(); break;
case TYPE_VEC3: con->value=Vector3(); break;
case TYPE_VEC4: con->value=iscolor?Variant(Color()):Variant(Plane()); break;
case TYPE_MAT2: con->value=Matrix32(); break;
case TYPE_MAT3: con->value=Matrix3(); break;
case TYPE_MAT4: con->value=Transform(); break;
case TYPE_TEXTURE:
@ -2628,12 +2641,20 @@ void ShaderLanguage::get_keyword_list(ShaderType p_type, List<String> *p_keyword
int idx=0;
p_keywords->push_back("uniform");
p_keywords->push_back("texture");
p_keywords->push_back("cubemap");
p_keywords->push_back("color");
p_keywords->push_back("if");
p_keywords->push_back("else");
while(intrinsic_func_defs[idx].name) {
p_keywords->push_back(intrinsic_func_defs[idx].name);
idx++;
}
switch(p_type) {
case SHADER_MATERIAL_VERTEX: {
idx=0;

View file

@ -56,6 +56,7 @@ public:
TK_TYPE_VEC2,
TK_TYPE_VEC3,
TK_TYPE_VEC4,
TK_TYPE_MAT2,
TK_TYPE_MAT3,
TK_TYPE_MAT4,
TK_TYPE_TEXTURE,
@ -118,6 +119,7 @@ public:
TYPE_VEC2,
TYPE_VEC3,
TYPE_VEC4,
TYPE_MAT2,
TYPE_MAT3,
TYPE_MAT4,
TYPE_TEXTURE,

View file

@ -1233,7 +1233,7 @@ float BakedLightBaker::_throw_ray(ThreadStack& thread_stack,bool p_bake_direct,c
if (dist<r) {
//avoid accumulaiton of light on corners
//plot_light=plot_light.linear_interpolate(Color(0,0,0,0),1.0-sd/plot_size*plot_size);
skip-true;
skip=true;
} else {