Merge pull request #13341 from scayze/interp_v2

Added interpolation qualifiers to shaderlang
This commit is contained in:
Rémi Verschelde 2017-12-09 18:12:14 +01:00 committed by GitHub
commit ccef401700
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 2 deletions

View File

@ -81,6 +81,16 @@ static int _get_datatype_size(SL::DataType p_type) {
ERR_FAIL_V(0); ERR_FAIL_V(0);
} }
static String _interpstr(SL::DataInterpolation p_interp) {
switch (p_interp) {
case SL::INTERPOLATION_FLAT: return "flat ";
case SL::INTERPOLATION_NO_PERSPECTIVE: return "noperspective ";
case SL::INTERPOLATION_SMOOTH: return "smooth ";
}
return "";
}
static String _prestr(SL::DataPrecision p_pres) { static String _prestr(SL::DataPrecision p_pres) {
switch (p_pres) { switch (p_pres) {
@ -383,12 +393,13 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
for (Map<StringName, SL::ShaderNode::Varying>::Element *E = pnode->varyings.front(); E; E = E->next()) { for (Map<StringName, SL::ShaderNode::Varying>::Element *E = pnode->varyings.front(); E; E = E->next()) {
String vcode; String vcode;
String interp_mode = _interpstr(E->get().interpolation);
vcode += _prestr(E->get().precission); vcode += _prestr(E->get().precission);
vcode += _typestr(E->get().type); vcode += _typestr(E->get().type);
vcode += " " + _mkid(E->key()); vcode += " " + _mkid(E->key());
vcode += ";\n"; vcode += ";\n";
r_gen_code.vertex_global += "out " + vcode; r_gen_code.vertex_global += interp_mode + "out " + vcode;
r_gen_code.fragment_global += "in " + vcode; r_gen_code.fragment_global += interp_mode + "in " + vcode;
} }
Map<StringName, String> function_code; Map<StringName, String> function_code;

View File

@ -254,6 +254,9 @@ const ShaderLanguage::KeyWord ShaderLanguage::keyword_list[] = {
{ TK_TYPE_ISAMPLER2D, "isampler2D" }, { TK_TYPE_ISAMPLER2D, "isampler2D" },
{ TK_TYPE_USAMPLER2D, "usampler2D" }, { TK_TYPE_USAMPLER2D, "usampler2D" },
{ TK_TYPE_SAMPLERCUBE, "samplerCube" }, { TK_TYPE_SAMPLERCUBE, "samplerCube" },
{ TK_INTERPOLATION_FLAT, "flat" },
{ TK_INTERPOLATION_NO_PERSPECTIVE, "noperspective" },
{ TK_INTERPOLATION_SMOOTH, "smooth" },
{ TK_PRECISION_LOW, "lowp" }, { TK_PRECISION_LOW, "lowp" },
{ TK_PRECISION_MID, "mediump" }, { TK_PRECISION_MID, "mediump" },
{ TK_PRECISION_HIGH, "highp" }, { TK_PRECISION_HIGH, "highp" },
@ -658,6 +661,24 @@ ShaderLanguage::DataType ShaderLanguage::get_token_datatype(TokenType p_type) {
return DataType(p_type - TK_TYPE_VOID); return DataType(p_type - TK_TYPE_VOID);
} }
bool ShaderLanguage::is_token_interpolation(TokenType p_type) {
return (
p_type == TK_INTERPOLATION_FLAT ||
p_type == TK_INTERPOLATION_NO_PERSPECTIVE ||
p_type == TK_INTERPOLATION_SMOOTH);
}
ShaderLanguage::DataInterpolation ShaderLanguage::get_token_interpolation(TokenType p_type) {
if (p_type == TK_INTERPOLATION_FLAT)
return INTERPOLATION_FLAT;
else if (p_type == TK_INTERPOLATION_NO_PERSPECTIVE)
return INTERPOLATION_NO_PERSPECTIVE;
else
return INTERPOLATION_SMOOTH;
}
bool ShaderLanguage::is_token_precision(TokenType p_type) { bool ShaderLanguage::is_token_precision(TokenType p_type) {
return ( return (
@ -3576,10 +3597,16 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
bool uniform = tk.type == TK_UNIFORM; bool uniform = tk.type == TK_UNIFORM;
DataPrecision precision = PRECISION_DEFAULT; DataPrecision precision = PRECISION_DEFAULT;
DataInterpolation interpolation = INTERPOLATION_SMOOTH;
DataType type; DataType type;
StringName name; StringName name;
tk = _get_token(); tk = _get_token();
if (is_token_interpolation(tk.type)) {
interpolation = get_token_interpolation(tk.type);
tk = _get_token();
}
if (is_token_precision(tk.type)) { if (is_token_precision(tk.type)) {
precision = get_token_precision(tk.type); precision = get_token_precision(tk.type);
tk = _get_token(); tk = _get_token();
@ -3777,6 +3804,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
ShaderNode::Varying varying; ShaderNode::Varying varying;
varying.type = type; varying.type = type;
varying.precission = precision; varying.precission = precision;
varying.interpolation = interpolation;
shader->varyings[name] = varying; shader->varyings[name] = varying;
tk = _get_token(); tk = _get_token();

View File

@ -72,6 +72,9 @@ public:
TK_TYPE_ISAMPLER2D, TK_TYPE_ISAMPLER2D,
TK_TYPE_USAMPLER2D, TK_TYPE_USAMPLER2D,
TK_TYPE_SAMPLERCUBE, TK_TYPE_SAMPLERCUBE,
TK_INTERPOLATION_FLAT,
TK_INTERPOLATION_NO_PERSPECTIVE,
TK_INTERPOLATION_SMOOTH,
TK_PRECISION_LOW, TK_PRECISION_LOW,
TK_PRECISION_MID, TK_PRECISION_MID,
TK_PRECISION_HIGH, TK_PRECISION_HIGH,
@ -192,6 +195,12 @@ public:
PRECISION_DEFAULT, PRECISION_DEFAULT,
}; };
enum DataInterpolation {
INTERPOLATION_FLAT,
INTERPOLATION_NO_PERSPECTIVE,
INTERPOLATION_SMOOTH,
};
enum Operator { enum Operator {
OP_EQUAL, OP_EQUAL,
OP_NOT_EQUAL, OP_NOT_EQUAL,
@ -431,6 +440,7 @@ public:
struct Varying { struct Varying {
DataType type; DataType type;
DataInterpolation interpolation;
DataPrecision precission; DataPrecision precission;
}; };
@ -511,6 +521,8 @@ public:
static bool is_token_datatype(TokenType p_type); static bool is_token_datatype(TokenType p_type);
static DataType get_token_datatype(TokenType p_type); static DataType get_token_datatype(TokenType p_type);
static bool is_token_interpolation(TokenType p_type);
static DataInterpolation get_token_interpolation(TokenType p_type);
static bool is_token_precision(TokenType p_type); static bool is_token_precision(TokenType p_type);
static DataPrecision get_token_precision(TokenType p_type); static DataPrecision get_token_precision(TokenType p_type);
static String get_datatype_name(DataType p_type); static String get_datatype_name(DataType p_type);