###############################################################################
+my %shaders=();
+
sub GenerateStringsFromFile
{
my($file) = shift;
my($dir) = shift;
- my($headerFile) = shift;
- my($sourceFile) = shift;
my $shadername = $file;
$shadername =~ s/-([a-z])/uc($1)/eg;
my $state = 0;
+ my $shader="";
open MEM, "$dir/$file" || die "Can't open $file for reading: $!\n";
while(<MEM>)
{
if (/<VertexShader>/)
{
$state = 1;
- print $headerFile "extern const char* const ${shadername}Vertex;\n";
- print $sourceFile "extern const char* const ${shadername}Vertex;\n";
- print $sourceFile "const char* const ${shadername}Vertex(\n";
+ $shader = "";
}
elsif (/<FragmentShader>/)
{
$state = 1;
- print $headerFile "extern const char* const ${shadername}Fragment;\n";
- print $sourceFile "extern const char* const ${shadername}Fragment;\n";
- print $sourceFile "const char* const ${shadername}Fragment(\n";
+ $shader = "";
}
}
elsif ($state == 1)
{
- if (m!</VertexShader>! || m!</FragmentShader>!)
+ if (m!</VertexShader>!)
{
$state = 0;
- print $sourceFile ");\n\n";
+ $shaders{$shadername}->{"vertex"} = $shader;
+ }
+ elsif( m!</FragmentShader>!)
+ {
+ $state = 0;
+ $shaders{$shadername}->{"fragment"} = $shader;
}
else
{
- print $sourceFile "\"$_\\n\"\n";
+ ## Accumulate
+ $shader .= "$_\n";
+# print $sourceFile "\"$_\\n\"\n";
}
}
}
###############################################################################
+sub PrintSourceLine
+{
+ my $sourceFile=shift;
+ my $line=shift;
+ chomp $line;
+ $line =~ s!//.*$!!; # Strip out comments
+ $line =~ s!\s*$!!; # Strip out trailing space
+ if( $line !~ m!^\s*$! )
+ {
+ print $sourceFile "\"$line\\n\"\n";
+ }
+}
+
+sub PrintMacroLine
+{
+ my $sourceFile=shift;
+ my $line=shift;
+ chomp $line;
+ $line =~ s!//.*$!!; # Strip out comments
+ $line =~ s!\s*$!!; # Strip out trailing space
+ if( $line !~ m!^\s*$! )
+ {
+ print $sourceFile "\"$line\\n\" \\\n";
+ }
+}
+
+
+sub PrintShaderProgramWithMacros
+{
+ my $sourceFile=shift;
+ my $shadername=shift;
+ my $SHADERNAME=$shadername;
+ $SHADERNAME =~ s/([A-Z])/_$1/g;
+ substr($SHADERNAME,0,1)="";
+ $SHADERNAME = uc($SHADERNAME);
+
+ my $program_type=shift;
+ my $ProgramType=ucfirst($program_type);
+ my $PROGRAM_TYPE=uc($program_type);
+ my $custom=shift;
+
+ my @lines=split(/\n/, $shaders{$shadername}->{$program_type} );
+
+ print $sourceFile "#define ${SHADERNAME}_PREFIX_${PROGRAM_TYPE} \\\n";
+ LINE: while( scalar(@lines) )
+ {
+ last LINE if $lines[0] =~ /main()/;
+ PrintMacroLine($sourceFile, shift(@lines));
+ }
+ print $sourceFile "\n\n";
+
+ print $sourceFile "#define ${SHADERNAME}_POSTFIX_${PROGRAM_TYPE} \\\n";
+ LINE: while( scalar(@lines) )
+ {
+ PrintMacroLine($sourceFile, shift(@lines));
+ }
+ print $sourceFile "\n\n";
+
+ if($custom)
+ {
+ print $sourceFile "extern const char* const Custom${shadername}Prefix${ProgramType};\n";
+ print $sourceFile "const char* const Custom${shadername}Prefix${ProgramType}(\n";
+ print $sourceFile " ${SHADERNAME}_PREFIX_${PROGRAM_TYPE}\n";
+ print $sourceFile ");\n\n";
+
+ print $sourceFile "extern const char* const Custom${shadername}Postfix${ProgramType};\n";
+ print $sourceFile "const char* const Custom${shadername}Postfix${ProgramType}(\n";
+ print $sourceFile " ${SHADERNAME}_POSTFIX_${PROGRAM_TYPE}\n";
+ print $sourceFile ");\n\n";
+ }
+ print $sourceFile "extern const char* const ${shadername}${ProgramType};\n";
+ print $sourceFile "const char* const ${shadername}${ProgramType}(\n";
+ print $sourceFile " ${SHADERNAME}_PREFIX_${PROGRAM_TYPE}\n";
+ print $sourceFile " ${SHADERNAME}_POSTFIX_${PROGRAM_TYPE}\n";
+ print $sourceFile ");\n\n";
+
+}
+
+sub PrintShaderProgram
+{
+ my $sourceFile=shift;
+ my $shadername=shift;
+ my $program_type=shift;
+ my $custom=shift;
+ my $ProgramType=ucfirst($program_type);
+
+ my @lines=split(/\n/, $shaders{$shadername}->{$program_type} );
+
+ print $sourceFile "const char* const ${shadername}${ProgramType}(\n";
+ for my $i (0..scalar(@lines)-1)
+ {
+ PrintSourceLine($sourceFile, $lines[$i]);
+ }
+ print $sourceFile ");\n\n";
+
+ if( $custom )
+ {
+ print $sourceFile "const char* const Custom${shadername}Prefix${ProgramType}(\n";
+ LINE:
+ while( scalar(@lines) )
+ {
+ last LINE if $lines[0] =~ /main()/;
+ PrintSourceLine($sourceFile, shift(@lines));
+ }
+ print $sourceFile ");\n\n";
+
+ print $sourceFile "const char* const Custom${shadername}Postfix${ProgramType}(\n";
+
+ while( scalar(@lines) )
+ {
+ PrintSourceLine($sourceFile, shift(@lines));
+ }
+ print $sourceFile ");\n\n";
+ }
+}
+
+
+sub PrintShaderSources
+{
+ my($headerFile) = shift;
+ my($sourceFile) = shift;
+ my $shadername;
+
+ # Strings are now in memory. Dump them back out again:
+ foreach $shadername (sort(keys(%shaders)))
+ {
+ print $headerFile "extern const char* const ${shadername}Vertex;\n";
+ print $headerFile "extern const char* const ${shadername}Fragment;\n";
+
+ my $custom = 0;
+ if( $shadername !~ /TextDistanceField/ || $shadername eq "TextDistanceField" )
+ {
+ print $headerFile "extern const char* const Custom${shadername}PrefixVertex;\n";
+ print $headerFile "extern const char* const Custom${shadername}PostfixVertex;\n";
+ print $headerFile "extern const char* const Custom${shadername}PrefixFragment;\n";
+ print $headerFile "extern const char* const Custom${shadername}PostfixFragment;\n";
+ $custom = 1;
+ }
+ PrintShaderProgramWithMacros($sourceFile, $shadername, "vertex", $custom);
+ PrintShaderProgramWithMacros($sourceFile, $shadername, "fragment", $custom);
+ }
+}
+
+###############################################################################
+
my($optHelp);
my($optMan);
my($shaderDir) = "";
-my($filePrefix) = "";
+my($fileName) = "";
GetOptions(
"help" => \$optHelp,
"man" => \$optMan,
"shader-dir=s" => \$shaderDir,
- "file-prefix=s" => \$filePrefix
+ "file-name=s" => \$fileName
) or pod2usage(2);
pod2usage(1) if $optHelp;
pod2usage(-exitstatus => 0, -verbose => 2) if $optMan;
-if ($shaderDir eq "" || $filePrefix eq "")
+if ($shaderDir eq "" || $fileName eq "")
{
pod2usage(1);
}
my $dir = $shaderDir;
my @shaderFiles = GetShaderFiles($dir);
- my $headerFile = OpenFileForWriting("$filePrefix.h");
- my $sourceFile = OpenFileForWriting("$filePrefix.cpp");
+ my $headerFile = OpenFileForWriting("$fileName.h");
+ my $sourceFile = OpenFileForWriting("$fileName.cpp");
GenerateHeaderFileHeader($headerFile);
GenerateSourceFileHeader($sourceFile);
my $file;
foreach $file (@shaderFiles)
{
- GenerateStringsFromFile($file, $dir, $headerFile, $sourceFile);
+ GenerateStringsFromFile($file, $dir);
}
+ PrintShaderSources($headerFile, $sourceFile);
+
GenerateHeaderFileFooter($headerFile);
GenerateSourceFileFooter($sourceFile);
=head1 NAME
-generate-shader-strings.pl - Given a shader directory and a file prefix, this script generates a header and source file where all the shaders in the directory are stored as vertex and fragment shader std::string(s).
+generate-shader-strings.pl - Given a shader directory and a file name, this script generates a header and source file where all the shaders in the directory are stored as vertex and fragment shader const char arrays.
=head1 SYNOPSIS
-generate-shader-strings.pl -s=<shader-dir> -f=<file-prefix>
+generate-shader-strings.pl -s=<shader-dir> -f=<file-name>
-generate-shader-strings.pl --shader-dir=<shader-dir> -file-prefix=<file-prefix>
+generate-shader-strings.pl -shader-dir=<shader-dir> -file-name=<file-name>
=head1 DESCRIPTION
-Given a shader directory and a file prefix, this script generates a header and source file where all the shaders in the directory are stored as vertex and fragment shader std::string(s).
+Given a shader directory and a file name, this script generates a header and source file where all the shaders in the directory are stored as vertex and fragment shader const char arrays.
The shader files in the specified directory should have the suffix ".txt" and the vertex and fragment shaders should be encapsulated within <VertexShader>*</VertexShader> and <FragmentShader>*</FragmentShader> respectively in this text file.
-The generated source files will be called <file-prefix>.h and <file-prefix>.cpp.
+The generated source files will be called <file-name>.h and <file-name>.cpp.
=head1 OPTIONS
The directory the shader files should be loaded from.
-=item B<-f|--file-prefix>
-
-The prefix of the output files.
+=item B<-f|--file-name>
+The name of the output files.
dali_shaders_src_file = dali-shaders.cpp
dali-shaders.cpp: $(dali_shaders_script) $(dali_shaders_dir)/*.txt
- $< --shader-dir=$(dali_shaders_dir) --file-prefix=dali-shaders
+ $< --shader-dir=$(dali_shaders_dir) --file-name=dali-shaders
dali_core_includes = \
-I../../..
CustomImagePostfixVertex, CustomImagePostfixFragment
},
{
- CustomFontPrefixVertex, CustomFontPrefixFragment,
- CustomFontPostfixVertex, CustomFontPostfixFragment
+ CustomTextDistanceFieldPrefixVertex, CustomTextDistanceFieldPrefixFragment,
+ CustomTextDistanceFieldPostfixVertex, CustomTextDistanceFieldPostfixFragment
},
{
- CustomMeshPrefixVertex, CustomMeshPrefixFragment,
- CustomMeshPostfixVertex, CustomMeshPostfixFragment
+ CustomUntexturedMeshPrefixVertex, CustomUntexturedMeshPrefixFragment,
+ CustomUntexturedMeshPostfixVertex, CustomUntexturedMeshPostfixFragment
+ },
+ {
+ CustomTexturedMeshPrefixVertex, CustomTexturedMeshPrefixFragment,
+ CustomTexturedMeshPostfixVertex, CustomTexturedMeshPostfixFragment
}
};
const string& textFragmentShader,
const string& texturedMeshVertexShader,
const string& texturedMeshFragmentShader,
- const string& meshVertexShader,
- const string& meshFragmentShader,
+ const string& untexturedMeshVertexShader,
+ const string& untexturedMeshFragmentShader,
Dali::ShaderEffect::GeometryHints hints )
{
ShaderEffectPtr shaderEffect( New(hints) );
shaderEffect->SetWrappedProgram( GEOMETRY_TYPE_IMAGE, SHADER_SUBTYPE_ALL, "", "", imageVertexShader, imageFragmentShader );
shaderEffect->SetWrappedProgram( GEOMETRY_TYPE_TEXT, SHADER_DEFAULT, "", "", textVertexShader, textFragmentShader );
shaderEffect->SetWrappedProgram( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_SUBTYPE_ALL, "", "", texturedMeshVertexShader, texturedMeshFragmentShader );
- shaderEffect->SetWrappedProgram( GEOMETRY_TYPE_MESH, SHADER_SUBTYPE_ALL, "", "", meshVertexShader, meshFragmentShader );
+ shaderEffect->SetWrappedProgram( GEOMETRY_TYPE_UNTEXTURED_MESH, SHADER_SUBTYPE_ALL, "", "", untexturedMeshVertexShader, untexturedMeshFragmentShader );
return shaderEffect;
}
{
geometryType = GEOMETRY_TYPE_TEXT;
}
- else if( s == "GEOMETRY_TYPE_MESH")
+ else if( s == "GEOMETRY_TYPE_UNTEXTURED_MESH")
{
- geometryType = GEOMETRY_TYPE_MESH;
+ geometryType = GEOMETRY_TYPE_UNTEXTURED_MESH;
}
else if( s == "GEOMETRY_TYPE_TEXTURED_MESH")
{
SetWrappedProgram( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_SUBTYPE_ALL, vertexShaderPrefix, fragmentShaderPrefix, vertexShader, fragmentShader );
}
- if( geometryTypes & GEOMETRY_TYPE_MESH )
+ if( geometryTypes & GEOMETRY_TYPE_UNTEXTURED_MESH )
{
- SetWrappedProgram( GEOMETRY_TYPE_MESH, SHADER_SUBTYPE_ALL, vertexShaderPrefix, fragmentShaderPrefix, vertexShader, fragmentShader );
+ SetWrappedProgram( GEOMETRY_TYPE_UNTEXTURED_MESH, SHADER_SUBTYPE_ALL, vertexShaderPrefix, fragmentShaderPrefix, vertexShader, fragmentShader );
}
}
index = 1;
break;
}
- case GEOMETRY_TYPE_MESH:
- case GEOMETRY_TYPE_TEXTURED_MESH:
+ case GEOMETRY_TYPE_UNTEXTURED_MESH:
{
index = 2;
break;
}
+ case GEOMETRY_TYPE_TEXTURED_MESH:
+ {
+ index = 3;
+ break;
+ }
case GEOMETRY_TYPE_LAST:
{
DALI_ASSERT_DEBUG(0 && "Wrong geometry type");
{
mDefaultShader = ShaderEffect::New();
- mDefaultShader->SetProgram( GEOMETRY_TYPE_IMAGE, SHADER_DEFAULT, FlatColorTextureVertex, FlatColorTextureFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_IMAGE, SHADER_DEFAULT, ImageVertex, ImageFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
- mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_DEFAULT, DistanceFieldFontVertex, DistanceFieldFontFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_DEFAULT, TextDistanceFieldVertex, TextDistanceFieldFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
- mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT, SHADER_DEF_USE_GRADIENT, SHADER_DEF_USE_GRADIENT, DistanceFieldFontVertex, DistanceFieldFontFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT, SHADER_DEF_USE_GRADIENT, SHADER_DEF_USE_GRADIENT, TextDistanceFieldVertex, TextDistanceFieldFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
- mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_GLOW, DistanceFieldFontGlowVertex, DistanceFieldFontGlowFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_GLOW, TextDistanceFieldGlowVertex, TextDistanceFieldGlowFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
- mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_SHADOW, DistanceFieldFontShadowVertex, DistanceFieldFontShadowFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_SHADOW, TextDistanceFieldShadowVertex, TextDistanceFieldShadowFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
- mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_OUTLINE, DistanceFieldFontOutlineVertex, DistanceFieldFontOutlineFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_OUTLINE, TextDistanceFieldOutlineVertex, TextDistanceFieldOutlineFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
- mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_OUTLINE_GLOW, DistanceFieldFontOutlineGlowVertex, DistanceFieldFontOutlineGlowFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_OUTLINE_GLOW, TextDistanceFieldOutlineGlowVertex, TextDistanceFieldOutlineGlowFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
// Untextured meshes
- mDefaultShader->SetProgram( GEOMETRY_TYPE_MESH, SHADER_DEFAULT,
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_UNTEXTURED_MESH, SHADER_DEFAULT,
"", // Vertex shader defs
SHADER_DEF_USE_LIGHTING, // fragment shader defs
- MeshColorNoTextureVertex,
- MeshColorNoTextureFragment,
+ UntexturedMeshVertex,
+ UntexturedMeshFragment,
ShaderEffect::DOESNT_MODIFY_GEOMETRY );
- mDefaultShader->SetProgram( GEOMETRY_TYPE_MESH, SHADER_EVENLY_LIT,
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_UNTEXTURED_MESH, SHADER_EVENLY_LIT,
"", // Vertex shader defs
"", // fragment shader defs
- MeshColorNoTextureVertex,
- MeshColorNoTextureFragment,
+ UntexturedMeshVertex,
+ UntexturedMeshFragment,
ShaderEffect::DOESNT_MODIFY_GEOMETRY );
- mDefaultShader->SetProgram( GEOMETRY_TYPE_MESH, SHADER_RIGGED_AND_LIT,
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_UNTEXTURED_MESH, SHADER_RIGGED_AND_LIT,
SHADER_DEF_USE_BONES, // vertex shader defs
SHADER_DEF_USE_LIGHTING, // fragment shader defs
- MeshColorNoTextureVertex,
- MeshColorNoTextureFragment,
+ UntexturedMeshVertex,
+ UntexturedMeshFragment,
ShaderEffect::MODIFIES_GEOMETRY );
- mDefaultShader->SetProgram( GEOMETRY_TYPE_MESH, SHADER_RIGGED_AND_EVENLY_LIT,
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_UNTEXTURED_MESH, SHADER_RIGGED_AND_EVENLY_LIT,
SHADER_DEF_USE_BONES, // Vertex shader defs
"", // Fragment shader defs
- MeshColorNoTextureVertex,
- MeshColorNoTextureFragment,
+ UntexturedMeshVertex,
+ UntexturedMeshFragment,
ShaderEffect::MODIFIES_GEOMETRY );
- mDefaultShader->SetProgram( GEOMETRY_TYPE_MESH, SHADER_RIGGED_AND_VERTEX_COLOR,
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_UNTEXTURED_MESH, SHADER_RIGGED_AND_VERTEX_COLOR,
(SHADER_DEF_USE_BONES SHADER_DEF_USE_COLOR), // Vertex shader defs
SHADER_DEF_USE_COLOR, // Fragment shader defs
- MeshColorNoTextureVertex,
- MeshColorNoTextureFragment,
+ UntexturedMeshVertex,
+ UntexturedMeshFragment,
ShaderEffect::MODIFIES_GEOMETRY );
- mDefaultShader->SetProgram( GEOMETRY_TYPE_MESH, SHADER_VERTEX_COLOR,
+ mDefaultShader->SetProgram( GEOMETRY_TYPE_UNTEXTURED_MESH, SHADER_VERTEX_COLOR,
SHADER_DEF_USE_COLOR, // Vertex shader defs
SHADER_DEF_USE_COLOR, // Fragment shader defs
- MeshColorNoTextureVertex,
- MeshColorNoTextureFragment,
+ UntexturedMeshVertex,
+ UntexturedMeshFragment,
ShaderEffect::DOESNT_MODIFY_GEOMETRY );
// Textured meshes
mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_DEFAULT,
"", // Vertex shader defs
SHADER_DEF_USE_LIGHTING, // fragment shader defs
- MeshVertex,
- MeshFragment,
+ TexturedMeshVertex,
+ TexturedMeshFragment,
ShaderEffect::DOESNT_MODIFY_GEOMETRY );
mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_EVENLY_LIT,
"", // Vertex shader defs
"", // Fragment shader defs
- MeshVertex,
- MeshFragment,
+ TexturedMeshVertex,
+ TexturedMeshFragment,
ShaderEffect::DOESNT_MODIFY_GEOMETRY );
mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_RIGGED_AND_LIT,
SHADER_DEF_USE_BONES, // Vertex shader defs
SHADER_DEF_USE_LIGHTING, // Fragment shader defs
- MeshVertex,
- MeshFragment,
+ TexturedMeshVertex,
+ TexturedMeshFragment,
ShaderEffect::MODIFIES_GEOMETRY );
mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_RIGGED_AND_EVENLY_LIT,
SHADER_DEF_USE_BONES, // Vertex shader defs
"", // Fragment shader defs
- MeshVertex,
- MeshFragment,
+ TexturedMeshVertex,
+ TexturedMeshFragment,
ShaderEffect::MODIFIES_GEOMETRY );
}
outType = GEOMETRY_TYPE_TEXTURED_MESH;
if( ! material.HasTexture() )
{
- outType = GEOMETRY_TYPE_MESH;
+ outType = GEOMETRY_TYPE_UNTEXTURED_MESH;
}
outSubType = SHADER_DEFAULT;
+++ /dev/null
-<VertexShader>
-
- void main()
- {
- gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
- vTexCoord = aTexCoord;
-
-#ifdef USE_GRADIENT
- lowp float f = dot( aPosition.xy * uInvTextSize - uGradientLine.xy, uGradientLine.zw );
- vColor = mix(uTextColor, uGradientColor, f);
-#endif
- }
-
-</VertexShader>
-
-<FragmentShader>
-
- void main()
- {
- // sample distance field
- highp float distance = texture2D(sTexture, vTexCoord).a;
-
-#ifdef USE_GRADIENT
- lowp vec4 color = clamp(vColor, 0., 1.); // gradiant calculation can overflow.
-#else
- lowp vec4 color = uTextColor;
-#endif
-
- // adjust fragment alpha by sampled distance
- color.a *= smoothstep(uSmoothing[0], uSmoothing[1], distance );
-
- // final color multiplied by Actor color
- gl_FragColor = uColor * color;
- }
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
-
- attribute mediump vec3 aPosition;
- attribute mediump vec2 aTexCoord;
-
- uniform mediump mat4 uModelView;
- uniform mediump mat4 uProjection;
- uniform mediump mat4 uMvpMatrix;
- uniform mediump mat3 uNormalMatrix;
- uniform lowp vec4 uColor;
- uniform lowp vec4 uTextColor;
-
- varying mediump vec2 vTexCoord;
-
-#ifdef USE_GRADIENT
- uniform lowp vec4 uGradientColor;
- uniform mediump vec4 uGradientLine;
- uniform mediump vec2 uInvTextSize;
-
- varying lowp vec4 vColor;
-#endif
-
-</VertexShader>
-
-<FragmentShader>
- uniform mediump sampler2D sTexture;
- uniform highp vec4 sTextureRect;
- uniform lowp vec4 uColor;
- uniform highp vec2 uSmoothing;
-
- varying highp vec2 vTexCoord;
-
-#ifdef USE_GRADIENT
- varying lowp vec4 vColor;
-#else
- uniform lowp vec4 uTextColor;
-#endif
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
-
- void main()
- {
- gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);
- vTexCoord = aTexCoord;
- }
-
-</VertexShader>
-
-<FragmentShader>
-
- void main()
- {
- gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
- }
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
- precision mediump float;
-
- attribute vec3 aPosition;
- attribute vec2 aTexCoord;
-
- uniform mat4 uModelView;
- uniform mat4 uProjection;
- uniform mat4 uMvpMatrix;
- uniform mat3 uNormalMatrix;
- uniform mat4 uModelMatrix;
- uniform mat4 uViewMatrix;
-
- uniform vec4 uColor;
-
- varying vec2 vTexCoord;
-
- uniform vec4 sTextureRect;
- uniform vec4 sEffectRect;
-
-</VertexShader>
-
-<FragmentShader>
- precision mediump float;
-
- uniform sampler2D sTexture;
- uniform sampler2D sEffect;
-
- uniform vec4 sTextureRect;
- uniform vec4 sEffectRect;
-
- uniform vec4 uColor;
-
- varying vec2 vTexCoord;
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
-#define USE_TEXTURES
-#define USE_NORMALS
-#define MAX_BONES_PER_MESH 12
-
-#ifdef USE_BONES
- uniform int uBoneCount;
- uniform mediump mat4 uBoneMatrices[MAX_BONES_PER_MESH];
- uniform mediump mat3 uBoneMatricesIT[MAX_BONES_PER_MESH];
- attribute mediump vec4 aBoneWeights;
- attribute mediump vec4 aBoneIndices;
-#endif
-
- void main()
- {
- mediump vec4 vertexPosition = vec4(aPosition, 1.0);
- mediump float lightIntensity;
-
-#ifdef USE_BONES
- if(uBoneCount > 0)
- {
- mediump vec4 boneWeights = aBoneWeights;
- mediump ivec4 boneIndices = ivec4(aBoneIndices);
- mediump vec3 vertexNormal;
-
- // re-calculate the final weight
- boneWeights.w = 1.0 - dot(boneWeights.xyz, vec3(1.0, 1.0, 1.0));
-
- vec4 bonePos = (uBoneMatrices[boneIndices.x] * vertexPosition) * boneWeights.x;
- bonePos += (uBoneMatrices[boneIndices.y] * vertexPosition) * boneWeights.y;
- bonePos += (uBoneMatrices[boneIndices.z] * vertexPosition) * boneWeights.z;
- bonePos += (uBoneMatrices[boneIndices.w] * vertexPosition) * boneWeights.w;
-
- vertexNormal = (uBoneMatricesIT[boneIndices.x] * aNormal) * boneWeights.x;
- vertexNormal += (uBoneMatricesIT[boneIndices.y] * aNormal) * boneWeights.y;
- vertexNormal += (uBoneMatricesIT[boneIndices.z] * aNormal) * boneWeights.z;
- vertexNormal += (uBoneMatricesIT[boneIndices.w] * aNormal) * boneWeights.w;
- vertexNormal = normalize(vertexNormal);
-
- vertexPosition = uProjection * bonePos;
- vVertex = bonePos;
- vNormal = vertexNormal;
- }
- else
- {
-#endif
- vertexPosition = uMvpMatrix * vec4(aPosition, 1.0);
- vVertex = uModelView * vec4(aPosition, 1.0);
- vNormal = uModelViewIT * aNormal;
-#ifdef USE_BONES
- }
-#endif
- gl_Position = vertexPosition;
-
- mediump vec2 start = uCustomTextureCoords.xy;
- mediump vec2 scale = uCustomTextureCoords.zw;
- vTexCoord = vec2(start.x + aTexCoord.x * scale.x, start.y + aTexCoord.y * scale.y);
- }
-
-</VertexShader>
-
-<FragmentShader>
-
-#ifdef USE_LIGHTING
- struct Light
- {
- int mType; // 0=AMBIENT,1=DIRECTIONAL,2=SPOT,3=POINT
- highp vec2 mFallOff; // x,y = falloff start, falloff end
- mediump vec2 mSpotAngle; // x,y = inner cone and outer cone
- mediump vec3 mLightPos; // position
- mediump vec3 mLightDir; // directional (for direction/spot lights)
- lowp vec3 mAmbient; // ambient component of the light's color
- lowp vec3 mDiffuse; // diffuse component of the light's color
- lowp vec3 mSpecular; // specular component of the light's color
- };
-
- uniform int uNumberOfLights;
- uniform Light uLight0;
-
- lowp vec3 lightColor;
- lowp vec3 specularColor;
-
- void calculateLight(Light light)
- {
- // Ensure that the varying vertex position doesn't lose precision
- highp vec3 lightVector = light.mLightPos - vVertex.xyz;
- vec3 N = normalize(vNormal);
- vec3 L = normalize(lightVector);
- // TODO: for directional light, should use mLightDir for light direction not lightVector
- float NdotL = dot(N, L);
-
- vec3 color = light.mAmbient * uMaterial.mAmbient.rgb;
- color += light.mDiffuse * uMaterial.mDiffuse.rgb * abs(NdotL);
-
- // Attenuation
- highp float attenuation = 1.0; // requires highp
- if (light.mType >= 2)
- {
- attenuation -= smoothstep(light.mFallOff.x, light.mFallOff.y, length(lightVector));
- }
-
- // TODO spotlights
-
- // add color to cumulative light total. TODO: don't attenuate directional light
- lightColor += color * attenuation;
-
- if (light.mType != 0 && NdotL > 0.0 && light.mType != 0)
- {
- // Specular highlight
- vec3 E = normalize(vVertex.xyz);
- vec3 R = reflect(L, N);
- float specular = pow(max(dot(R, E), 0.0), uMaterial.mShininess);
- specularColor += uMaterial.mSpecular.rgb * light.mSpecular * specular * attenuation;
- }
- }
-#endif
-
- void main()
- {
- // sample the texture for the initial color
- vec4 fragColor = texture2D(sTexture, vTexCoord);
-
-#ifdef USE_LIGHTING
-
- // apply lighting and material properties
- specularColor = vec3(0.0);
- lightColor = vec3(0.0);
-
- // @TODO conditionally compile different shaders for different number of lights
- if( uNumberOfLights > 0 )
- {
- calculateLight(uLight0);
- }
-
- fragColor.rgb *= lightColor;
- fragColor.rgb += specularColor;
-
-#else
-
- // apply material properties
- fragColor.rgb *= (uMaterial.mAmbient + uMaterial.mDiffuse).rgb;
-
-#endif
-
- // apply material alpha/opacity to alpha channel
- fragColor.a *= uMaterial.mOpacity * uMaterial.mDiffuse.a;
-
- // and finally, apply Actor color
- fragColor *= uColor;
-
-// Next line useful for visualizing the normals
-// fragColor = vec4(normalize(vNormal), 1.0);
- gl_FragColor = fragColor;
- }
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
- precision mediump float;
-
- uniform mediump mat4 uProjection;
- uniform mediump mat4 uModelView;
- uniform mediump mat4 uMvpMatrix;
-
- uniform bool uTextureMapped;
- uniform mediump vec4 uCustomTextureCoords;
- attribute mediump vec2 aTexCoord;
- varying mediump vec2 vTexCoord;
-
- uniform mat3 uModelViewIT;
- attribute mediump vec3 aNormal;
- varying mediump vec3 vNormal;
-
- attribute mediump vec3 aPosition;
- varying mediump vec4 vVertex;
-
-</VertexShader>
-
-<FragmentShader>
- precision mediump float;
-
- struct Material
- {
- mediump float mOpacity;
- mediump float mShininess;
- lowp vec4 mAmbient;
- lowp vec4 mDiffuse;
- lowp vec4 mSpecular;
- lowp vec4 mEmissive;
- };
-
- uniform sampler2D sTexture;
- uniform sampler2D sOpacityTexture;
- uniform sampler2D sNormalMapTexture;
- uniform sampler2D sEffect;
- varying vec2 vTexCoord;
-
- uniform Material uMaterial;
-
- uniform lowp vec4 uColor;
- varying highp vec4 vVertex;
- varying highp vec3 vNormal;
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
-
- attribute mediump vec3 aPosition;
- attribute mediump vec2 aTexCoord;
-
- uniform mediump mat4 uMvpMatrix;
- uniform lowp vec4 uColor;
- uniform lowp vec4 uTextColor;
- uniform lowp vec4 uGradientColor;
- uniform mediump vec4 uGradientLine;
- uniform mediump vec2 uInvTextSize;
-
- varying mediump vec2 vTexCoord;
- varying lowp vec4 vColor;
-
- void main()
- {
- gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
- vTexCoord = aTexCoord;
-
- lowp float f = dot( aPosition.xy * uInvTextSize - uGradientLine.xy, uGradientLine.zw );
-
- vColor = mix(uTextColor, uGradientColor, f);
- }
-
-</VertexShader>
-
-<FragmentShader>
-
- uniform mediump sampler2D sTexture;
- uniform lowp vec4 uColor;
- uniform highp vec2 uSmoothing;
- uniform highp float uGlow;
- uniform lowp vec4 uGlowColor;
-
- varying mediump vec2 vTexCoord;
- varying lowp vec4 vColor;
-
- void main()
- {
- // sample distance field
- mediump float distance = texture2D(sTexture, vTexCoord).a;
-
- mediump float glowBlend = smoothstep(uSmoothing[0], uSmoothing[1], distance);
-
- // blend fragment color between glow color and text color
- lowp vec4 clampedColor = clamp( vColor, 0.0, 1.0 );
- lowp vec4 glowColor = vec4( uGlowColor.rgb, uGlowColor.a * clampedColor.a );
- lowp vec4 color = mix(glowColor, clampedColor, glowBlend);
-
- // fade out glow between uSmoothing and uGlow
- color.a *= smoothstep(uGlow, uSmoothing[0], distance);
-
- // final color multiplied by Actor color
- gl_FragColor = uColor * color;
- }
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
-
- attribute mediump vec3 aPosition;
- attribute mediump vec2 aTexCoord;
-
- uniform mediump mat4 uMvpMatrix;
- uniform lowp vec4 uColor;
- uniform lowp vec4 uTextColor;
- uniform lowp vec4 uGradientColor;
- uniform mediump vec4 uGradientLine;
- uniform mediump vec2 uInvTextSize;
-
- varying mediump vec2 vTexCoord;
- varying lowp vec4 vColor;
-
- void main()
- {
- gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
- vTexCoord = aTexCoord;
-
- lowp float f = dot( aPosition.xy * uInvTextSize - uGradientLine.xy, uGradientLine.zw );
-
- vColor = mix(uTextColor, uGradientColor, f);
- }
-
-</VertexShader>
-
-<FragmentShader>
-
- uniform mediump sampler2D sTexture;
- uniform lowp vec4 uColor;
- uniform highp vec2 uSmoothing;
- uniform highp vec2 uOutline;
- uniform lowp vec4 uOutlineColor;
- uniform highp float uGlow;
- uniform lowp vec4 uGlowColor;
-
- varying mediump vec2 vTexCoord;
- varying lowp vec4 vColor;
-
- void main()
- {
- // sample distance field
- mediump float distance = texture2D(sTexture, vTexCoord).a;
-
- // blend fragment color between outline color and text color
- mediump float outlineBlend = smoothstep(uOutline[0], uOutline[1], distance);
-
- lowp vec4 clampedColor = clamp( vColor, 0.0, 1.0 );
-
- // create blend between text color and outline color using outlineBlend
- lowp vec4 outlineColor = vec4( uOutlineColor.rgb, uOutlineColor.a * clampedColor.a );
- lowp vec4 color = mix(outlineColor, clampedColor, outlineBlend);
-
- mediump float glowBlend = smoothstep(uSmoothing[0], uSmoothing[1], distance);
-
- // blend fragment color between glow color and text color
- lowp vec4 glowColor = vec4( uGlowColor.rgb, uGlowColor.a * clampedColor.a );
- color = mix(glowColor, color, glowBlend);
-
- // fade out glow between uSmoothing and uGlow
- color.a *= smoothstep(uGlow, uSmoothing[0], distance);
-
- // final color multiplied by Actor color
- gl_FragColor = uColor * color;
- }
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
-
- attribute mediump vec3 aPosition;
- attribute mediump vec2 aTexCoord;
-
- uniform mediump mat4 uMvpMatrix;
- uniform lowp vec4 uColor;
- uniform lowp vec4 uTextColor;
- uniform lowp vec4 uGradientColor;
- uniform mediump vec4 uGradientLine;
- uniform mediump vec2 uInvTextSize;
-
- varying mediump vec2 vTexCoord;
- varying lowp vec4 vColor;
-
- void main()
- {
- gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
- vTexCoord = aTexCoord;
-
- lowp float f = dot( aPosition.xy * uInvTextSize - uGradientLine.xy, uGradientLine.zw );
-
- vColor = mix(uTextColor, uGradientColor, f);
- }
-
-</VertexShader>
-
-<FragmentShader>
-
- uniform mediump sampler2D sTexture;
- uniform lowp vec4 uColor;
- uniform highp vec2 uSmoothing;
- uniform mediump vec2 uOutline;
- uniform lowp vec4 uOutlineColor;
-
- varying highp vec2 vTexCoord;
- varying lowp vec4 vColor;
-
- void main()
- {
- // sample distance field
- highp float distance = texture2D(sTexture, vTexCoord).a;
-
- // blend fragment color between outline color and text color
- highp float outlineBlend = smoothstep(uOutline[0], uOutline[1], distance);
- lowp vec4 clampedColor = clamp( vColor, 0.0, 1.0 );
- lowp vec4 outlineColor = vec4( uOutlineColor.rgb, uOutlineColor.a * clampedColor.a );
- lowp vec4 color = mix(outlineColor, clampedColor, outlineBlend);
-
- // adjust fragment alpha by sampled distance
- color.a *= smoothstep(uSmoothing[0], uSmoothing[1], distance);
-
- // final color multiplied by Actor color
- gl_FragColor = uColor * color;
- }
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
-
- attribute mediump vec3 aPosition;
- attribute highp vec4 aTexCoord;
-
- uniform mediump mat4 uMvpMatrix;
- uniform lowp vec4 uColor;
- uniform lowp vec4 uTextColor;
- uniform highp vec2 uShadow;
- uniform lowp vec4 uGradientColor;
- uniform mediump vec4 uGradientLine;
- uniform mediump vec2 uInvTextSize;
-
- varying highp vec2 vTexCoord;
- varying highp vec2 vShadowCoord;
- varying lowp vec4 vColor;
-
- void main()
- {
- gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
- vTexCoord = aTexCoord.xy;
- vShadowCoord = vTexCoord - (uShadow * aTexCoord.zw);
-
- lowp float f = dot( aPosition.xy * uInvTextSize - uGradientLine.xy, uGradientLine.zw );
- vColor = mix(uTextColor, uGradientColor, f);
- }
-
-</VertexShader>
-
-<FragmentShader>
-
- uniform mediump sampler2D sTexture;
- uniform lowp vec4 uColor;
- uniform highp vec2 uSmoothing;
- uniform highp vec2 uShadowSmoothing;
- uniform lowp vec4 uShadowColor;
-
- varying highp vec2 vTexCoord;
- varying highp vec2 vShadowCoord;
- varying lowp vec4 vColor;
-
- void main()
- {
- // sample distance field
- mediump float distance = texture2D(sTexture, vTexCoord).a;
- mediump float shadow_distance = texture2D(sTexture, vShadowCoord).a;
-
- mediump float inText = smoothstep(uSmoothing[0], uSmoothing[1], distance);
- mediump float inShadow = smoothstep(uShadowSmoothing[0], uShadowSmoothing[1], shadow_distance);
-
- lowp vec4 color;
-
- mediump float oneMinusSrcAlpha = (1.0 - inText) * inShadow;
-
- lowp vec4 clampedColor = clamp( vColor, 0.0, 1.0 );
- lowp vec4 cText = vec4( clampedColor.rgb, clampedColor.a * inText );
- lowp vec4 cShadow = vec4(uShadowColor.rgb, uShadowColor.a * clampedColor.a * inShadow);
-
- // completely outside shadow, maybe inside text
- if( inShadow <= 0.0 )
- {
- color = cText;
- }
- // completely outside text, definitely inside shadow
- else if( inText <= 0.0 )
- {
- color = cShadow;
- }
- // inside text and/or shadow border(s)
- else
- {
- color.rgb = mix( cText.rgb, cShadow.rgb, oneMinusSrcAlpha );
- color.a = max(cText.a, cShadow.a);
- }
-
- // final color multiplied by Actor color
- gl_FragColor = uColor * color;
- }
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
-
- attribute mediump vec3 aPosition;
- attribute mediump vec2 aTexCoord;
-
- uniform mediump mat4 uModelView;
- uniform mediump mat4 uProjection;
- uniform mediump mat4 uMvpMatrix;
- uniform mediump mat3 uNormalMatrix;
- uniform lowp vec4 uColor;
- uniform lowp vec4 uTextColor;
-
- varying mediump vec2 vTexCoord;
-
-#ifdef USE_GRADIENT
- uniform lowp vec4 uGradientColor;
- uniform mediump vec4 uGradientLine;
- uniform mediump vec2 uInvTextSize;
-
- varying lowp vec4 vColor;
-#endif
-
- void main()
- {
- gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
- vTexCoord = aTexCoord;
-
-#ifdef USE_GRADIENT
- lowp float f = dot( aPosition.xy * uInvTextSize - uGradientLine.xy, uGradientLine.zw );
- vColor = mix(uTextColor, uGradientColor, f);
-#endif
- }
-
-</VertexShader>
-
-<FragmentShader>
-
- uniform mediump sampler2D sTexture;
- uniform highp vec4 sTextureRect;
- uniform lowp vec4 uColor;
- uniform highp vec2 uSmoothing;
-
- varying highp vec2 vTexCoord;
-
-#ifdef USE_GRADIENT
- varying lowp vec4 vColor;
-#else
- uniform lowp vec4 uTextColor;
-#endif
-
- void main()
- {
- // sample distance field
- highp float distance = texture2D(sTexture, vTexCoord).a;
-
-#ifdef USE_GRADIENT
- lowp vec4 color = clamp(vColor, 0., 1.); // gradiant calculation can overflow.
-#else
- lowp vec4 color = uTextColor;
-#endif
-
- // adjust fragment alpha by sampled distance
- color.a *= smoothstep(uSmoothing[0], uSmoothing[1], distance );
-
- // final color multiplied by Actor color
- gl_FragColor = uColor * color;
- }
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
-
- attribute mediump vec3 aPosition;
- attribute mediump vec2 aTexCoord;
-
- uniform mediump mat4 uMvpMatrix;
- uniform lowp vec4 uColor;
-
- varying mediump vec2 vTexCoord;
-
- void main()
- {
- gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
- vTexCoord = aTexCoord;
- }
-
-</VertexShader>
-
-<FragmentShader>
-
- uniform sampler2D sTexture;
- uniform lowp vec4 uColor;
-
- varying mediump vec2 vTexCoord;
-
- void main()
- {
- gl_FragColor = texture2D(sTexture, vTexCoord) * uColor;
- }
-
-</FragmentShader>
--- /dev/null
+<VertexShader>
+
+attribute mediump vec3 aPosition;
+attribute mediump vec2 aTexCoord;
+
+uniform mediump mat4 uModelView;
+uniform mediump mat4 uProjection;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat3 uNormalMatrix;
+uniform mediump mat4 uModelMatrix;
+uniform mediump mat4 uViewMatrix;
+
+uniform mediump vec4 uColor;
+
+varying mediump vec2 vTexCoord;
+
+uniform mediump vec4 sTextureRect;
+uniform mediump vec4 sEffectRect;
+
+void main()
+{
+ gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
+ vTexCoord = aTexCoord;
+}
+
+</VertexShader>
+
+<FragmentShader>
+
+uniform sampler2D sTexture;
+uniform sampler2D sEffect;
+
+uniform mediump vec4 sTextureRect;
+uniform mediump vec4 sEffectRect;
+
+uniform mediump vec4 uColor;
+varying mediump vec2 vTexCoord;
+
+void main()
+{
+ gl_FragColor = texture2D(sTexture, vTexCoord) * uColor;
+}
+
+</FragmentShader>
+++ /dev/null
-<VertexShader>
- precision mediump float;
-
- uniform mediump mat4 uProjection;
- uniform mediump mat4 uModelView;
- uniform mediump mat4 uMvpMatrix;
-
- uniform bool uTextureMapped;
- uniform mediump vec4 uCustomTextureCoords;
- attribute mediump vec2 aTexCoord;
- varying mediump vec2 vTexCoord;
-
- uniform mat3 uModelViewIT;
- attribute mediump vec3 aNormal;
- varying mediump vec3 vNormal;
-
- attribute mediump vec3 aPosition;
- varying mediump vec4 vVertex;
-#define USE_NORMALS
-#define MAX_BONES_PER_MESH 12
-
-#ifdef USE_BONES
- uniform int uBoneCount;
- uniform mediump mat4 uBoneMatrices[MAX_BONES_PER_MESH];
- uniform mediump mat3 uBoneMatricesIT[MAX_BONES_PER_MESH];
- attribute mediump vec4 aBoneWeights;
- attribute mediump vec4 aBoneIndices;
-#endif
-
-#ifdef USE_COLOR
- attribute lowp vec3 aColor;
- varying mediump vec3 vColor;
-#endif
-
- void main()
- {
- mediump vec4 vertexPosition = vec4(aPosition, 1.0);
-
-#ifdef USE_BONES
- if(uBoneCount > 0)
- {
- mediump vec4 boneWeights = aBoneWeights;
- mediump ivec4 boneIndices = ivec4(aBoneIndices);
- mediump vec3 vertexNormal;
-
- // re-calculate the final weight
- boneWeights.w = 1.0 - dot(boneWeights.xyz, vec3(1.0, 1.0, 1.0));
-
- vec4 bonePos = (uBoneMatrices[boneIndices.x] * vertexPosition) * boneWeights.x;
- bonePos += (uBoneMatrices[boneIndices.y] * vertexPosition) * boneWeights.y;
- bonePos += (uBoneMatrices[boneIndices.z] * vertexPosition) * boneWeights.z;
- bonePos += (uBoneMatrices[boneIndices.w] * vertexPosition) * boneWeights.w;
-
- vertexNormal = (uBoneMatricesIT[boneIndices.x] * aNormal) * boneWeights.x;
- vertexNormal += (uBoneMatricesIT[boneIndices.y] * aNormal) * boneWeights.y;
- vertexNormal += (uBoneMatricesIT[boneIndices.z] * aNormal) * boneWeights.z;
- vertexNormal += (uBoneMatricesIT[boneIndices.w] * aNormal) * boneWeights.w;
- vertexNormal = normalize(vertexNormal);
-
- vertexPosition = uProjection * bonePos;
- vVertex = bonePos;
- vNormal = vertexNormal;
- }
- else
- {
-#endif
- vertexPosition = uMvpMatrix * vec4(aPosition, 1.0);
- vVertex = uModelView * vec4(aPosition, 1.0);
- vNormal = uModelViewIT * aNormal;
-#ifdef USE_BONES
- }
-#endif
- gl_Position = vertexPosition;
-
-#ifdef USE_COLOR
- vColor = aColor;
-#endif
- }
-
-</VertexShader>
-
-<FragmentShader>
- precision mediump float;
-
- struct Material
- {
- mediump float mOpacity;
- mediump float mShininess;
- lowp vec4 mAmbient;
- lowp vec4 mDiffuse;
- lowp vec4 mSpecular;
- lowp vec4 mEmissive;
- };
-
- uniform sampler2D sTexture;
- uniform sampler2D sOpacityTexture;
- uniform sampler2D sNormalMapTexture;
- uniform sampler2D sEffect;
- varying vec2 vTexCoord;
-
- uniform Material uMaterial;
-
- uniform lowp vec4 uColor;
- varying highp vec4 vVertex;
- varying highp vec3 vNormal;
-
-#ifdef USE_LIGHTING
- struct Light
- {
- int mType; // 0=AMBIENT,1=DIRECTIONAL,2=SPOT,3=POINT
- highp vec2 mFallOff; // x,y = falloff start, falloff end
- mediump vec2 mSpotAngle; // x,y = inner cone and outer cone
- mediump vec3 mLightPos; // position
- mediump vec3 mLightDir; // directional (for direction/spot lights)
- lowp vec3 mAmbient; // ambient component of the light's color
- lowp vec3 mDiffuse; // diffuse component of the light's color
- lowp vec3 mSpecular; // specular component of the light's color
- };
-#endif
-
-#ifdef USE_LIGHTING
- uniform int uNumberOfLights;
- uniform Light uLight0;
- uniform Light uLight1;
- uniform Light uLight2;
-#endif
-
-#ifdef USE_COLOR
- varying mediump vec3 vColor;
-#endif
-
-#ifdef USE_LIGHTING
- lowp vec3 lightColor;
- lowp vec3 specularColor;
-
- void calculateLight(Light light)
- {
- highp vec3 lightVector = light.mLightPos - vVertex.xyz;
- vec3 N = normalize(vNormal);
- vec3 L = normalize(lightVector);
- // TODO: for directional light, should use mLightDir for light direction not lightVector
- float NdotL = dot(N, L);
-
- vec3 color = light.mAmbient * uMaterial.mAmbient.rgb;
- color += light.mDiffuse * uMaterial.mDiffuse.rgb * abs(NdotL);
-
- // Attenuation
- highp float attenuation = 1.0; // requires highp
- if (light.mType >= 2)
- {
- attenuation -= smoothstep(light.mFallOff.x, light.mFallOff.y, length(lightVector));
- }
-
- // TODO spotlights
-
- // add color to cumulative light total. TODO: don't attenuate directional light
- lightColor += color * attenuation;
-
- if (light.mType > 1 && NdotL > 0.0 && uMaterial.mShininess > 0.0)
- {
- // Specular highlight
- vec3 E = normalize(vVertex.xyz);
- vec3 R = reflect(L, N);
- float specular = pow(max(dot(R, E), 0.0), uMaterial.mShininess);
- specularColor += uMaterial.mSpecular.rgb * light.mSpecular * specular * attenuation;
- }
- }
-#endif
-
- void main()
- {
-#ifdef USE_COLOR
-
- // set initial color to vertex color
- vec4 fragColor = vec4(vColor, 1.0);
-
-#else
-
- // set initial color to material color
- vec4 fragColor = uMaterial.mAmbient + uMaterial.mDiffuse;
-
-#endif
-
-#ifdef USE_LIGHTING
-
- // apply lighting and material properties
- specularColor = vec3(0.0);
- lightColor = vec3(0.0);
-
- // @TODO conditionally compile different shaders for different number of lights
- if (uNumberOfLights > 0)
- {
- calculateLight(uLight0);
- }
-
- fragColor.rgb *= lightColor;
- fragColor.rgb += specularColor;
-
-#endif
-
- // apply material alpha/opacity to alpha channel
- fragColor.a *= uMaterial.mOpacity * uMaterial.mDiffuse.a;
-
- // and finally, apply Actor color
- fragColor *= uColor;
-
-// Next line useful for visualizing the normals
-// vertexColor = vec4(normalize(vNormal), 1.0);
- gl_FragColor = fragColor;
- }
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
- precision mediump float;
-
- uniform mediump mat4 uProjection;
- uniform mediump mat4 uModelView;
- uniform mediump mat4 uMvpMatrix;
-
- uniform bool uTextureMapped;
- uniform mediump vec4 uCustomTextureCoords;
- attribute mediump vec2 aTexCoord;
- varying mediump vec2 vTexCoord;
-
- uniform mat3 uModelViewIT;
- attribute mediump vec3 aNormal;
- varying mediump vec3 vNormal;
-
- attribute mediump vec3 aPosition;
- varying mediump vec4 vVertex;
-
-#define MAX_BONES_PER_MESH 12
-
-#ifdef USE_BONES
- uniform int uBoneCount;
- uniform mediump mat4 uBoneMatrices[MAX_BONES_PER_MESH];
- uniform mediump mat3 uBoneMatricesIT[MAX_BONES_PER_MESH];
- attribute mediump vec4 aBoneWeights;
- attribute mediump vec4 aBoneIndices;
-#endif
-
- void main()
- {
- mediump vec4 vertexPosition = vec4(aPosition, 1.0);
- mediump float lightIntensity;
-
-#ifdef USE_BONES
- if(uBoneCount > 0)
- {
- mediump vec4 boneWeights = aBoneWeights;
- mediump ivec4 boneIndices = ivec4(aBoneIndices);
- mediump vec3 vertexNormal;
-
- // re-calculate the final weight
- boneWeights.w = 1.0 - dot(boneWeights.xyz, vec3(1.0, 1.0, 1.0));
-
- vec4 bonePos = (uBoneMatrices[boneIndices.x] * vertexPosition) * boneWeights.x;
- bonePos += (uBoneMatrices[boneIndices.y] * vertexPosition) * boneWeights.y;
- bonePos += (uBoneMatrices[boneIndices.z] * vertexPosition) * boneWeights.z;
- bonePos += (uBoneMatrices[boneIndices.w] * vertexPosition) * boneWeights.w;
-
- vertexNormal = (uBoneMatricesIT[boneIndices.x] * aNormal) * boneWeights.x;
- vertexNormal += (uBoneMatricesIT[boneIndices.y] * aNormal) * boneWeights.y;
- vertexNormal += (uBoneMatricesIT[boneIndices.z] * aNormal) * boneWeights.z;
- vertexNormal += (uBoneMatricesIT[boneIndices.w] * aNormal) * boneWeights.w;
- vertexNormal = normalize(vertexNormal);
-
- vertexPosition = uProjection * bonePos;
- vVertex = bonePos;
- vNormal = vertexNormal;
- }
- else
- {
-#endif
- vertexPosition = uMvpMatrix * vec4(aPosition, 1.0);
- vVertex = uModelView * vec4(aPosition, 1.0);
- vNormal = uModelViewIT * aNormal;
-#ifdef USE_BONES
- }
-#endif
- gl_Position = vertexPosition;
-
- mediump vec2 start = uCustomTextureCoords.xy;
- mediump vec2 scale = uCustomTextureCoords.zw;
- vTexCoord = vec2(start.x + aTexCoord.x * scale.x, start.y + aTexCoord.y * scale.y);
- }
-
-</VertexShader>
-
-<FragmentShader>
- precision mediump float;
-
- struct Material
- {
- mediump float mOpacity;
- mediump float mShininess;
- lowp vec4 mAmbient;
- lowp vec4 mDiffuse;
- lowp vec4 mSpecular;
- lowp vec4 mEmissive;
- };
-
- uniform sampler2D sTexture;
- uniform sampler2D sOpacityTexture;
- uniform sampler2D sNormalMapTexture;
- uniform sampler2D sEffect;
- varying vec2 vTexCoord;
-
- uniform Material uMaterial;
-
- uniform lowp vec4 uColor;
- varying highp vec4 vVertex;
- varying highp vec3 vNormal;
-
-#ifdef USE_LIGHTING
- struct Light
- {
- int mType; // 0=AMBIENT,1=DIRECTIONAL,2=SPOT,3=POINT
- highp vec2 mFallOff; // x,y = falloff start, falloff end
- mediump vec2 mSpotAngle; // x,y = inner cone and outer cone
- mediump vec3 mLightPos; // position
- mediump vec3 mLightDir; // directional (for direction/spot lights)
- lowp vec3 mAmbient; // ambient component of the light's color
- lowp vec3 mDiffuse; // diffuse component of the light's color
- lowp vec3 mSpecular; // specular component of the light's color
- };
-
- uniform int uNumberOfLights;
- uniform Light uLight0;
-
- lowp vec3 lightColor;
- lowp vec3 specularColor;
-
- void calculateLight(Light light)
- {
- // Ensure that the varying vertex position doesn't lose precision
- highp vec3 lightVector = light.mLightPos - vVertex.xyz;
- vec3 N = normalize(vNormal);
- vec3 L = normalize(lightVector);
- // TODO: for directional light, should use mLightDir for light direction not lightVector
- float NdotL = dot(N, L);
-
- vec3 color = light.mAmbient * uMaterial.mAmbient.rgb;
- color += light.mDiffuse * uMaterial.mDiffuse.rgb * abs(NdotL);
-
- // Attenuation
- highp float attenuation = 1.0; // requires highp
- if (light.mType >= 2)
- {
- attenuation -= smoothstep(light.mFallOff.x, light.mFallOff.y, length(lightVector));
- }
-
- // TODO spotlights
-
- // add color to cumulative light total. TODO: don't attenuate directional light
- lightColor += color * attenuation;
-
- if (light.mType != 0 && NdotL > 0.0 && light.mType != 0)
- {
- // Specular highlight
- vec3 E = normalize(vVertex.xyz);
- vec3 R = reflect(L, N);
- float specular = pow(max(dot(R, E), 0.0), uMaterial.mShininess);
- specularColor += uMaterial.mSpecular.rgb * light.mSpecular * specular * attenuation;
- }
- }
-#endif
-
- void main()
- {
- // sample the texture for the initial color
- vec4 fragColor = texture2D(sTexture, vTexCoord);
-
-#ifdef USE_LIGHTING
-
- // apply lighting and material properties
- specularColor = vec3(0.0);
- lightColor = vec3(0.0);
-
- // @TODO conditionally compile different shaders for different number of lights
- if( uNumberOfLights > 0 )
- {
- calculateLight(uLight0);
- }
-
- fragColor.rgb *= lightColor;
- fragColor.rgb += specularColor;
-
-#else
-
- // apply material properties
- fragColor.rgb *= (uMaterial.mAmbient + uMaterial.mDiffuse).rgb;
-
-#endif
-
- // apply material alpha/opacity to alpha channel
- fragColor.a *= uMaterial.mOpacity * uMaterial.mDiffuse.a;
-
- // and finally, apply Actor color
- fragColor *= uColor;
-
-// Next line useful for visualizing the normals
-// fragColor = vec4(normalize(vNormal), 1.0);
- gl_FragColor = fragColor;
- }
-
-</FragmentShader>
--- /dev/null
+<VertexShader>
+
+attribute mediump vec3 aPosition;
+attribute mediump vec2 aTexCoord;
+
+uniform mediump mat4 uMvpMatrix;
+uniform lowp vec4 uColor;
+uniform lowp vec4 uTextColor;
+uniform lowp vec4 uGradientColor;
+uniform mediump vec4 uGradientLine;
+uniform mediump vec2 uInvTextSize;
+
+varying mediump vec2 vTexCoord;
+varying lowp vec4 vColor;
+
+void main()
+{
+ gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
+ vTexCoord = aTexCoord;
+
+ lowp float f = dot( aPosition.xy * uInvTextSize - uGradientLine.xy, uGradientLine.zw );
+
+ vColor = mix(uTextColor, uGradientColor, f);
+}
+
+</VertexShader>
+
+<FragmentShader>
+
+uniform mediump sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform highp vec2 uSmoothing;
+uniform highp float uGlow;
+uniform lowp vec4 uGlowColor;
+
+varying mediump vec2 vTexCoord;
+varying lowp vec4 vColor;
+
+void main()
+{
+ // sample distance field
+ mediump float distance = texture2D(sTexture, vTexCoord).a;
+
+ mediump float glowBlend = smoothstep(uSmoothing[0], uSmoothing[1], distance);
+
+ // blend fragment color between glow color and text color
+ lowp vec4 clampedColor = clamp( vColor, 0.0, 1.0 );
+ lowp vec4 glowColor = vec4( uGlowColor.rgb, uGlowColor.a * clampedColor.a );
+ lowp vec4 color = mix(glowColor, clampedColor, glowBlend);
+
+ // fade out glow between uSmoothing and uGlow
+ color.a *= smoothstep(uGlow, uSmoothing[0], distance);
+
+ // final color multiplied by Actor color
+ gl_FragColor = uColor * color;
+}
+
+</FragmentShader>
--- /dev/null
+<VertexShader>
+
+attribute mediump vec3 aPosition;
+attribute mediump vec2 aTexCoord;
+
+uniform mediump mat4 uMvpMatrix;
+uniform lowp vec4 uColor;
+uniform lowp vec4 uTextColor;
+uniform lowp vec4 uGradientColor;
+uniform mediump vec4 uGradientLine;
+uniform mediump vec2 uInvTextSize;
+
+varying mediump vec2 vTexCoord;
+varying lowp vec4 vColor;
+
+void main()
+{
+ gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
+ vTexCoord = aTexCoord;
+
+ lowp float f = dot( aPosition.xy * uInvTextSize - uGradientLine.xy, uGradientLine.zw );
+
+ vColor = mix(uTextColor, uGradientColor, f);
+}
+
+</VertexShader>
+
+<FragmentShader>
+
+uniform mediump sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform highp vec2 uSmoothing;
+uniform highp vec2 uOutline;
+uniform lowp vec4 uOutlineColor;
+uniform highp float uGlow;
+uniform lowp vec4 uGlowColor;
+
+varying mediump vec2 vTexCoord;
+varying lowp vec4 vColor;
+
+void main()
+{
+ // sample distance field
+ mediump float distance = texture2D(sTexture, vTexCoord).a;
+
+ // blend fragment color between outline color and text color
+ mediump float outlineBlend = smoothstep(uOutline[0], uOutline[1], distance);
+
+ lowp vec4 clampedColor = clamp( vColor, 0.0, 1.0 );
+
+ // create blend between text color and outline color using outlineBlend
+ lowp vec4 outlineColor = vec4( uOutlineColor.rgb, uOutlineColor.a * clampedColor.a );
+ lowp vec4 color = mix(outlineColor, clampedColor, outlineBlend);
+
+ mediump float glowBlend = smoothstep(uSmoothing[0], uSmoothing[1], distance);
+
+ // blend fragment color between glow color and text color
+ lowp vec4 glowColor = vec4( uGlowColor.rgb, uGlowColor.a * clampedColor.a );
+ color = mix(glowColor, color, glowBlend);
+
+ // fade out glow between uSmoothing and uGlow
+ color.a *= smoothstep(uGlow, uSmoothing[0], distance);
+
+ // final color multiplied by Actor color
+ gl_FragColor = uColor * color;
+}
+
+</FragmentShader>
--- /dev/null
+<VertexShader>
+
+attribute mediump vec3 aPosition;
+attribute mediump vec2 aTexCoord;
+
+uniform mediump mat4 uMvpMatrix;
+uniform lowp vec4 uColor;
+uniform lowp vec4 uTextColor;
+uniform lowp vec4 uGradientColor;
+uniform mediump vec4 uGradientLine;
+uniform mediump vec2 uInvTextSize;
+
+varying mediump vec2 vTexCoord;
+varying lowp vec4 vColor;
+
+void main()
+{
+ gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
+ vTexCoord = aTexCoord;
+
+ lowp float f = dot( aPosition.xy * uInvTextSize - uGradientLine.xy, uGradientLine.zw );
+
+ vColor = mix(uTextColor, uGradientColor, f);
+}
+
+</VertexShader>
+
+<FragmentShader>
+
+uniform mediump sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform highp vec2 uSmoothing;
+uniform mediump vec2 uOutline;
+uniform lowp vec4 uOutlineColor;
+
+varying highp vec2 vTexCoord;
+varying lowp vec4 vColor;
+
+void main()
+{
+ // sample distance field
+ highp float distance = texture2D(sTexture, vTexCoord).a;
+
+ // blend fragment color between outline color and text color
+ highp float outlineBlend = smoothstep(uOutline[0], uOutline[1], distance);
+ lowp vec4 clampedColor = clamp( vColor, 0.0, 1.0 );
+ lowp vec4 outlineColor = vec4( uOutlineColor.rgb, uOutlineColor.a * clampedColor.a );
+ lowp vec4 color = mix(outlineColor, clampedColor, outlineBlend);
+
+ // adjust fragment alpha by sampled distance
+ color.a *= smoothstep(uSmoothing[0], uSmoothing[1], distance);
+
+ // final color multiplied by Actor color
+ gl_FragColor = uColor * color;
+}
+
+</FragmentShader>
--- /dev/null
+<VertexShader>
+
+attribute mediump vec3 aPosition;
+attribute highp vec4 aTexCoord;
+
+uniform mediump mat4 uMvpMatrix;
+uniform lowp vec4 uColor;
+uniform lowp vec4 uTextColor;
+uniform highp vec2 uShadow;
+uniform lowp vec4 uGradientColor;
+uniform mediump vec4 uGradientLine;
+uniform mediump vec2 uInvTextSize;
+
+varying highp vec2 vTexCoord;
+varying highp vec2 vShadowCoord;
+varying lowp vec4 vColor;
+
+void main()
+{
+ gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
+ vTexCoord = aTexCoord.xy;
+ vShadowCoord = vTexCoord - (uShadow * aTexCoord.zw);
+
+ lowp float f = dot( aPosition.xy * uInvTextSize - uGradientLine.xy, uGradientLine.zw );
+ vColor = mix(uTextColor, uGradientColor, f);
+}
+
+</VertexShader>
+
+<FragmentShader>
+
+uniform mediump sampler2D sTexture;
+uniform lowp vec4 uColor;
+uniform highp vec2 uSmoothing;
+uniform highp vec2 uShadowSmoothing;
+uniform lowp vec4 uShadowColor;
+
+varying highp vec2 vTexCoord;
+varying highp vec2 vShadowCoord;
+varying lowp vec4 vColor;
+
+void main()
+{
+ // sample distance field
+ mediump float distance = texture2D(sTexture, vTexCoord).a;
+ mediump float shadow_distance = texture2D(sTexture, vShadowCoord).a;
+
+ mediump float inText = smoothstep(uSmoothing[0], uSmoothing[1], distance);
+ mediump float inShadow = smoothstep(uShadowSmoothing[0], uShadowSmoothing[1], shadow_distance);
+
+ lowp vec4 color;
+
+ mediump float oneMinusSrcAlpha = (1.0 - inText) * inShadow;
+
+ lowp vec4 clampedColor = clamp( vColor, 0.0, 1.0 );
+ lowp vec4 cText = vec4( clampedColor.rgb, clampedColor.a * inText );
+ lowp vec4 cShadow = vec4(uShadowColor.rgb, uShadowColor.a * clampedColor.a * inShadow);
+
+ // completely outside shadow, maybe inside text
+ if( inShadow <= 0.0 )
+ {
+ color = cText;
+ }
+ // completely outside text, definitely inside shadow
+ else if( inText <= 0.0 )
+ {
+ color = cShadow;
+ }
+ // inside text and/or shadow border(s)
+ else
+ {
+ color.rgb = mix( cText.rgb, cShadow.rgb, oneMinusSrcAlpha );
+ color.a = max(cText.a, cShadow.a);
+ }
+
+ // final color multiplied by Actor color
+ gl_FragColor = uColor * color;
+}
+
+</FragmentShader>
--- /dev/null
+<VertexShader>
+
+attribute mediump vec3 aPosition;
+attribute mediump vec2 aTexCoord;
+
+uniform mediump mat4 uModelView;
+uniform mediump mat4 uProjection;
+uniform mediump mat4 uMvpMatrix;
+uniform mediump mat3 uNormalMatrix;
+uniform lowp vec4 uColor;
+uniform lowp vec4 uTextColor;
+
+varying mediump vec2 vTexCoord;
+
+#ifdef USE_GRADIENT
+uniform lowp vec4 uGradientColor;
+uniform mediump vec4 uGradientLine;
+uniform mediump vec2 uInvTextSize;
+
+varying lowp vec4 vColor;
+#endif
+
+void main()
+{
+ gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
+ vTexCoord = aTexCoord;
+
+#ifdef USE_GRADIENT
+ lowp float f = dot( aPosition.xy * uInvTextSize - uGradientLine.xy, uGradientLine.zw );
+ vColor = mix(uTextColor, uGradientColor, f);
+#endif
+}
+
+</VertexShader>
+
+<FragmentShader>
+
+uniform mediump sampler2D sTexture;
+uniform highp vec4 sTextureRect;
+uniform lowp vec4 uColor;
+uniform highp vec2 uSmoothing;
+
+varying highp vec2 vTexCoord;
+
+#ifdef USE_GRADIENT
+varying lowp vec4 vColor;
+#else
+uniform lowp vec4 uTextColor;
+#endif
+
+void main()
+{
+ // sample distance field
+ highp float distance = texture2D(sTexture, vTexCoord).a;
+
+#ifdef USE_GRADIENT
+ lowp vec4 color = clamp(vColor, 0., 1.); // gradiant calculation can overflow.
+#else
+ lowp vec4 color = uTextColor;
+#endif
+
+ // adjust fragment alpha by sampled distance
+ color.a *= smoothstep(uSmoothing[0], uSmoothing[1], distance );
+
+ // final color multiplied by Actor color
+ gl_FragColor = uColor * color;
+}
+
+</FragmentShader>
--- /dev/null
+<VertexShader>
+
+uniform mediump mat4 uProjection;
+uniform mediump mat4 uModelView;
+uniform mediump mat4 uMvpMatrix;
+
+uniform bool uTextureMapped;
+uniform mediump vec4 uCustomTextureCoords;
+attribute mediump vec2 aTexCoord;
+varying mediump vec2 vTexCoord;
+
+uniform mat3 uModelViewIT;
+attribute mediump vec3 aNormal;
+varying mediump vec3 vNormal;
+
+attribute mediump vec3 aPosition;
+varying mediump vec4 vVertex;
+
+#define MAX_BONES_PER_MESH 12
+
+#ifdef USE_BONES
+uniform int uBoneCount;
+uniform mediump mat4 uBoneMatrices[MAX_BONES_PER_MESH];
+uniform mediump mat3 uBoneMatricesIT[MAX_BONES_PER_MESH];
+attribute mediump vec4 aBoneWeights;
+attribute mediump vec4 aBoneIndices;
+#endif
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 1.0);
+ mediump float lightIntensity;
+
+#ifdef USE_BONES
+ if(uBoneCount > 0)
+ {
+ mediump vec4 boneWeights = aBoneWeights;
+ mediump ivec4 boneIndices = ivec4(aBoneIndices);
+ mediump vec3 vertexNormal;
+
+ // re-calculate the final weight
+ boneWeights.w = 1.0 - dot(boneWeights.xyz, vec3(1.0, 1.0, 1.0));
+
+ mediump vec4 bonePos = (uBoneMatrices[boneIndices.x] * vertexPosition) * boneWeights.x;
+ bonePos += (uBoneMatrices[boneIndices.y] * vertexPosition) * boneWeights.y;
+ bonePos += (uBoneMatrices[boneIndices.z] * vertexPosition) * boneWeights.z;
+ bonePos += (uBoneMatrices[boneIndices.w] * vertexPosition) * boneWeights.w;
+
+ vertexNormal = (uBoneMatricesIT[boneIndices.x] * aNormal) * boneWeights.x;
+ vertexNormal += (uBoneMatricesIT[boneIndices.y] * aNormal) * boneWeights.y;
+ vertexNormal += (uBoneMatricesIT[boneIndices.z] * aNormal) * boneWeights.z;
+ vertexNormal += (uBoneMatricesIT[boneIndices.w] * aNormal) * boneWeights.w;
+ vertexNormal = normalize(vertexNormal);
+
+ vertexPosition = uProjection * bonePos;
+ vVertex = bonePos;
+ vNormal = vertexNormal;
+ }
+ else
+ {
+#endif
+ vertexPosition = uMvpMatrix * mediump vec4(aPosition, 1.0);
+ vVertex = uModelView * mediump vec4(aPosition, 1.0);
+ vNormal = uModelViewIT * aNormal;
+#ifdef USE_BONES
+ }
+#endif
+ gl_Position = vertexPosition;
+
+ mediump vec2 start = uCustomTextureCoords.xy;
+ mediump vec2 scale = uCustomTextureCoords.zw;
+ vTexCoord = mediump vec2(start.x + aTexCoord.x * scale.x, start.y + aTexCoord.y * scale.y);
+}
+
+</VertexShader>
+
+<FragmentShader>
+
+struct Material
+{
+ mediump float mOpacity;
+ mediump float mShininess;
+ lowp vec4 mAmbient;
+ lowp vec4 mDiffuse;
+ lowp vec4 mSpecular;
+ lowp vec4 mEmissive;
+};
+
+uniform sampler2D sTexture;
+uniform sampler2D sOpacityTexture;
+uniform sampler2D sNormalMapTexture;
+uniform sampler2D sEffect;
+varying mediump vec2 vTexCoord;
+
+uniform Material uMaterial;
+
+uniform lowp vec4 uColor;
+varying highp vec4 vVertex;
+varying highp vec3 vNormal;
+
+#ifdef USE_LIGHTING
+struct Light
+{
+ int mType; // 0=AMBIENT,1=DIRECTIONAL,2=SPOT,3=POINT
+ highp vec2 mFallOff; // x,y = falloff start, falloff end
+ mediump vec2 mSpotAngle; // x,y = inner cone and outer cone
+ mediump vec3 mLightPos; // position
+ mediump vec3 mLightDir; // directional (for direction/spot lights)
+ lowp vec3 mAmbient; // ambient component of the light's color
+ lowp vec3 mDiffuse; // diffuse component of the light's color
+ lowp vec3 mSpecular; // specular component of the light's color
+};
+
+uniform int uNumberOfLights;
+uniform Light uLight0;
+
+lowp vec3 lightColor;
+lowp vec3 specularColor;
+
+void calculateLight(Light light)
+{
+ // Ensure that the varying vertex position doesn't lose precision
+ highp vec3 lightVector = light.mLightPos - vVertex.xyz;
+ mediump vec3 N = normalize(vNormal);
+ mediump vec3 L = normalize(lightVector);
+ // TODO: for directional light, should use mLightDir for light direction not lightVector
+ mediump float NdotL = dot(N, L);
+
+ mediump vec3 color = light.mAmbient * uMaterial.mAmbient.rgb;
+ color += light.mDiffuse * uMaterial.mDiffuse.rgb * abs(NdotL);
+
+ // Attenuation
+ highp float attenuation = 1.0; // requires highp
+ if (light.mType >= 2)
+ {
+ attenuation -= smoothstep(light.mFallOff.x, light.mFallOff.y, length(lightVector));
+ }
+
+ // TODO spotlights
+
+ // add color to cumulative light total. TODO: don't attenuate directional light
+ lightColor += color * attenuation;
+
+ if (light.mType != 0 && NdotL > 0.0 && light.mType != 0)
+ {
+ // Specular highlight
+ highp vec3 E = normalize(vVertex.xyz);
+ highp vec3 R = reflect(L, N);
+ highp float specular = pow(max(dot(R, E), 0.0), uMaterial.mShininess);
+ specularColor += uMaterial.mSpecular.rgb * light.mSpecular * specular * attenuation;
+ }
+}
+#endif
+
+void main()
+{
+ // sample the texture for the initial color
+ mediump vec4 fragColor = texture2D(sTexture, vTexCoord);
+
+#ifdef USE_LIGHTING
+
+ // apply lighting and material properties
+ specularColor = vec3(0.0);
+ lightColor = vec3(0.0);
+
+ // @TODO conditionally compile different shaders for different number of lights
+ if( uNumberOfLights > 0 )
+ {
+ calculateLight(uLight0);
+ }
+
+ fragColor.rgb *= lightColor;
+ fragColor.rgb += specularColor;
+
+#else
+
+ // apply material properties
+ fragColor.rgb *= (uMaterial.mAmbient + uMaterial.mDiffuse).rgb;
+
+#endif
+
+ // apply material alpha/opacity to alpha channel
+ fragColor.a *= uMaterial.mOpacity * uMaterial.mDiffuse.a;
+
+ // and finally, apply Actor color
+ fragColor *= uColor;
+
+ gl_FragColor = fragColor;
+}
+
+</FragmentShader>
--- /dev/null
+<VertexShader>
+uniform mediump mat4 uProjection;
+uniform mediump mat4 uModelView;
+uniform mediump mat4 uMvpMatrix;
+
+uniform bool uTextureMapped;
+uniform mediump vec4 uCustomTextureCoords;
+attribute mediump vec2 aTexCoord;
+varying mediump vec2 vTexCoord;
+
+uniform mat3 uModelViewIT;
+attribute mediump vec3 aNormal;
+varying mediump vec3 vNormal;
+
+attribute mediump vec3 aPosition;
+varying mediump vec4 vVertex;
+#define USE_NORMALS
+#define MAX_BONES_PER_MESH 12
+
+#ifdef USE_BONES
+uniform int uBoneCount;
+uniform mediump mat4 uBoneMatrices[MAX_BONES_PER_MESH];
+uniform mediump mat3 uBoneMatricesIT[MAX_BONES_PER_MESH];
+attribute mediump vec4 aBoneWeights;
+attribute mediump vec4 aBoneIndices;
+#endif
+
+#ifdef USE_COLOR
+attribute lowp vec3 aColor;
+varying mediump vec3 vColor;
+#endif
+
+void main()
+{
+ mediump vec4 vertexPosition = vec4(aPosition, 1.0);
+
+#ifdef USE_BONES
+ if(uBoneCount > 0)
+ {
+ mediump vec4 boneWeights = aBoneWeights;
+ mediump ivec4 boneIndices = ivec4(aBoneIndices);
+ mediump vec3 vertexNormal;
+
+ // re-calculate the final weight
+ boneWeights.w = 1.0 - dot(boneWeights.xyz, vec3(1.0, 1.0, 1.0));
+
+ vec4 bonePos = (uBoneMatrices[boneIndices.x] * vertexPosition) * boneWeights.x;
+ bonePos += (uBoneMatrices[boneIndices.y] * vertexPosition) * boneWeights.y;
+ bonePos += (uBoneMatrices[boneIndices.z] * vertexPosition) * boneWeights.z;
+ bonePos += (uBoneMatrices[boneIndices.w] * vertexPosition) * boneWeights.w;
+
+ vertexNormal = (uBoneMatricesIT[boneIndices.x] * aNormal) * boneWeights.x;
+ vertexNormal += (uBoneMatricesIT[boneIndices.y] * aNormal) * boneWeights.y;
+ vertexNormal += (uBoneMatricesIT[boneIndices.z] * aNormal) * boneWeights.z;
+ vertexNormal += (uBoneMatricesIT[boneIndices.w] * aNormal) * boneWeights.w;
+ vertexNormal = normalize(vertexNormal);
+
+ vertexPosition = uProjection * bonePos;
+ vVertex = bonePos;
+ vNormal = vertexNormal;
+ }
+ else
+ {
+#endif
+ vertexPosition = uMvpMatrix * vec4(aPosition, 1.0);
+ vVertex = uModelView * vec4(aPosition, 1.0);
+ vNormal = uModelViewIT * aNormal;
+#ifdef USE_BONES
+ }
+#endif
+ gl_Position = vertexPosition;
+
+#ifdef USE_COLOR
+ vColor = aColor;
+#endif
+}
+
+</VertexShader>
+
+<FragmentShader>
+
+struct Material
+{
+ mediump float mOpacity;
+ mediump float mShininess;
+ lowp vec4 mAmbient;
+ lowp vec4 mDiffuse;
+ lowp vec4 mSpecular;
+ lowp vec4 mEmissive;
+};
+
+uniform sampler2D sTexture;
+uniform sampler2D sOpacityTexture;
+uniform sampler2D sNormalMapTexture;
+uniform sampler2D sEffect;
+varying mediump vec2 vTexCoord;
+
+uniform Material uMaterial;
+
+uniform lowp vec4 uColor;
+varying highp vec4 vVertex;
+varying highp vec3 vNormal;
+
+#ifdef USE_LIGHTING
+struct Light
+{
+ int mType; // 0=AMBIENT,1=DIRECTIONAL,2=SPOT,3=POINT
+ highp vec2 mFallOff; // x,y = falloff start, falloff end
+ mediump vec2 mSpotAngle; // x,y = inner cone and outer cone
+ mediump vec3 mLightPos; // position
+ mediump vec3 mLightDir; // directional (for direction/spot lights)
+ lowp vec3 mAmbient; // ambient component of the light's color
+ lowp vec3 mDiffuse; // diffuse component of the light's color
+ lowp vec3 mSpecular; // specular component of the light's color
+};
+#endif
+
+#ifdef USE_LIGHTING
+uniform int uNumberOfLights;
+uniform Light uLight0;
+uniform Light uLight1;
+uniform Light uLight2;
+#endif
+
+#ifdef USE_COLOR
+varying mediump vec3 vColor;
+#endif
+
+#ifdef USE_LIGHTING
+lowp vec3 lightColor;
+lowp vec3 specularColor;
+
+void calculateLight(Light light)
+{
+ highp vec3 lightVector = light.mLightPos - vVertex.xyz;
+ vec3 N = normalize(vNormal);
+ vec3 L = normalize(lightVector);
+ // TODO: for directional light, should use mLightDir for light direction not lightVector
+ float NdotL = dot(N, L);
+
+ vec3 color = light.mAmbient * uMaterial.mAmbient.rgb;
+ color += light.mDiffuse * uMaterial.mDiffuse.rgb * abs(NdotL);
+
+ // Attenuation
+ highp float attenuation = 1.0; // requires highp
+ if (light.mType >= 2)
+ {
+ attenuation -= smoothstep(light.mFallOff.x, light.mFallOff.y, length(lightVector));
+ }
+
+ // TODO spotlights
+
+ // add color to cumulative light total. TODO: don't attenuate directional light
+ lightColor += color * attenuation;
+
+ if (light.mType > 1 && NdotL > 0.0 && uMaterial.mShininess > 0.0)
+ {
+ // Specular highlight
+ vec3 E = normalize(vVertex.xyz);
+ vec3 R = reflect(L, N);
+ float specular = pow(max(dot(R, E), 0.0), uMaterial.mShininess);
+ specularColor += uMaterial.mSpecular.rgb * light.mSpecular * specular * attenuation;
+ }
+}
+#endif
+
+void main()
+{
+#ifdef USE_COLOR
+
+ // set initial color to vertex color
+ mediump vec4 fragColor = vec4(vColor, 1.0);
+
+#else
+
+ // set initial color to material color
+ mediump vec4 fragColor = uMaterial.mAmbient + uMaterial.mDiffuse;
+
+#endif
+
+#ifdef USE_LIGHTING
+ // apply lighting and material properties
+ specularColor = vec3(0.0);
+ lightColor = vec3(0.0);
+
+ // @TODO conditionally compile different shaders for different number of lights
+ if (uNumberOfLights > 0)
+ {
+ calculateLight(uLight0);
+ }
+
+ fragColor.rgb *= lightColor;
+ fragColor.rgb += specularColor;
+
+#endif
+
+ // apply material alpha/opacity to alpha channel
+ fragColor.a *= uMaterial.mOpacity * uMaterial.mDiffuse.a;
+
+ // and finally, apply Actor color
+ fragColor *= uColor;
+
+ gl_FragColor = fragColor;
+}
+
+</FragmentShader>
{
index = Log<GEOMETRY_TYPE_TEXT>::value;
}
- else if ( type & GEOMETRY_TYPE_MESH )
+ else if ( type & GEOMETRY_TYPE_UNTEXTURED_MESH )
{
- index = Log<GEOMETRY_TYPE_MESH>::value;
+ index = Log<GEOMETRY_TYPE_UNTEXTURED_MESH>::value;
}
else if ( type & GEOMETRY_TYPE_TEXTURED_MESH )
{
{
GEOMETRY_TYPE_IMAGE = 0x01, ///< image, with flat color or texture
GEOMETRY_TYPE_TEXT = 0x02, ///< text, with flat color or texture
- GEOMETRY_TYPE_MESH = 0x04, ///< Complex meshes, with flat color
+ GEOMETRY_TYPE_UNTEXTURED_MESH = 0x04,///< Complex meshes, with flat color
GEOMETRY_TYPE_TEXTURED_MESH = 0x08, ///< Complex meshes, with texture
GEOMETRY_TYPE_LAST = 0x10
};