Shader effects provide a visual effect for actors.
-For a Custom shader you can provide the vertex and fragment shader code as strings.
+You can create a type-registered shader effect by its type name.
+```
+// create a new shader effect
+var shader = new dali.ShaderEffect("BlindEffect");
+```
+
+Alternatively you can create a Custom shader by providing the vertex and fragment shader code as strings.
Each shader is provided with default uniforms and attributes.
For a vertex shader this part contains the following code:
```
// CLASS HEADER
#include "shader-effect-api.h"
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/type-registry.h>
+
// INTERNAL INCLUDES
#include <v8-utils.h>
#include <shader-effects/shader-effect-wrapper.h>
*/
ShaderEffect ShaderEffectApi::New( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
{
-
-
v8::HandleScope handleScope( isolate );
- ShaderParameters shaderParams;
-
if( args[0]->IsObject() )
{
+ ShaderParameters shaderParams;
+
v8::Local<v8::Object > obj = args[0]->ToObject();
v8::Local<v8::Value> geometryTypeValue = obj->Get(v8::String::NewFromUtf8( isolate, "geometryType"));
}
shaderParams.ProcessHintsArray( hintsArray );
}
+
+ return shaderParams.NewShader();
}
- return shaderParams.NewShader();
+ else
+ {
+ ShaderEffect effect;
+
+ bool found( false );
+ std::string typeName = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "string parameter missing" );
+ }
+ else
+ {
+ // create a new shader effect based on type, using the type registry.
+ Dali::TypeInfo typeInfo = Dali::TypeRegistry::Get().GetTypeInfo( typeName );
+ if( typeInfo ) // handle, check if it has a value
+ {
+ Dali::BaseHandle handle = typeInfo.CreateInstance();
+ if( handle )
+ {
+ effect = ShaderEffect::DownCast( handle );
+ }
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION(isolate,"Unknown shader effect type");
+ }
+ }
+ return effect;
+ }
}
ShaderEffect ShaderEffectApi::GetShaderEffectFromParams( int paramIndex,
}
Dali::ShaderEffect shaderEffect = ShaderEffectApi::New( isolate, args );
- v8::Local<v8::Object> localObject = WrapShaderEffect( isolate, shaderEffect );
- args.GetReturnValue().Set( localObject );
+ if(shaderEffect)
+ {
+ v8::Local<v8::Object> localObject = WrapShaderEffect( isolate, shaderEffect );
+ args.GetReturnValue().Set( localObject );
+ }
}