-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sprite material vertex color example
- Loading branch information
Showing
14 changed files
with
235 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
embedded_components { | ||
id: "sprite" | ||
type: "sprite" | ||
data: "default_animation: \"defold-logo\"\n" | ||
"material: \"/examples/material/vertexcolor/vertexcolor.material\"\n" | ||
"blend_mode: BLEND_MODE_ALPHA\n" | ||
"textures {\n" | ||
" sampler: \"texture_sampler\"\n" | ||
" texture: \"/examples/material/vertexcolor/images.atlas\"\n" | ||
"}\n" | ||
"" | ||
position { | ||
x: 0.0 | ||
y: 0.0 | ||
z: 0.0 | ||
} | ||
rotation { | ||
x: 0.0 | ||
y: 0.0 | ||
z: 0.0 | ||
w: 1.0 | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
images { | ||
image: "/examples/material/vertexcolor/defold-logo.png" | ||
sprite_trim_mode: SPRITE_TRIM_MODE_OFF | ||
} | ||
margin: 0 | ||
extrude_borders: 0 | ||
inner_padding: 0 | ||
max_page_width: 0 | ||
max_page_height: 0 | ||
rename_patterns: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: "vertexcolor" | ||
scale_along_z: 0 | ||
embedded_instances { | ||
id: "go" | ||
data: "components {\n" | ||
" id: \"main\"\n" | ||
" component: \"/examples/material/vertexcolor/vertexcolor.script\"\n" | ||
" position {\n" | ||
" x: 0.0\n" | ||
" y: 0.0\n" | ||
" z: 0.0\n" | ||
" }\n" | ||
" rotation {\n" | ||
" x: 0.0\n" | ||
" y: 0.0\n" | ||
" z: 0.0\n" | ||
" w: 1.0\n" | ||
" }\n" | ||
" property_decls {\n" | ||
" }\n" | ||
"}\n" | ||
"embedded_components {\n" | ||
" id: \"factory\"\n" | ||
" type: \"factory\"\n" | ||
" data: \"prototype: \\\"/examples/material/vertexcolor/defold-logo.go\\\"\\n" | ||
"load_dynamically: false\\n" | ||
"dynamic_prototype: false\\n" | ||
"\"\n" | ||
" position {\n" | ||
" x: 0.0\n" | ||
" y: 0.0\n" | ||
" z: 0.0\n" | ||
" }\n" | ||
" rotation {\n" | ||
" x: 0.0\n" | ||
" y: 0.0\n" | ||
" z: 0.0\n" | ||
" w: 1.0\n" | ||
" }\n" | ||
"}\n" | ||
"" | ||
position { | ||
x: 0.0 | ||
y: 0.0 | ||
z: 0.0 | ||
} | ||
rotation { | ||
x: 0.0 | ||
y: 0.0 | ||
z: 0.0 | ||
w: 1.0 | ||
} | ||
scale3 { | ||
x: 1.0 | ||
y: 1.0 | ||
z: 1.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
varying mediump vec2 var_texcoord0; | ||
varying mediump vec4 var_mycolor; | ||
|
||
uniform lowp sampler2D texture_sampler; | ||
uniform lowp vec4 tint; | ||
|
||
void main() | ||
{ | ||
// Pre-multiply alpha since all runtime textures already are | ||
lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w); | ||
gl_FragColor = texture2D(texture_sampler, var_texcoord0.xy) * tint_pm * var_mycolor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: "sprite" | ||
tags: "tile" | ||
vertex_program: "/examples/material/vertexcolor/vertexcolor.vp" | ||
fragment_program: "/examples/material/vertexcolor/vertexcolor.fp" | ||
vertex_space: VERTEX_SPACE_WORLD | ||
vertex_constants { | ||
name: "view_proj" | ||
type: CONSTANT_TYPE_VIEWPROJ | ||
} | ||
fragment_constants { | ||
name: "tint" | ||
type: CONSTANT_TYPE_USER | ||
value { | ||
x: 1.0 | ||
y: 1.0 | ||
z: 1.0 | ||
w: 1.0 | ||
} | ||
} | ||
samplers { | ||
name: "texture_sampler" | ||
wrap_u: WRAP_MODE_CLAMP_TO_EDGE | ||
wrap_v: WRAP_MODE_CLAMP_TO_EDGE | ||
filter_min: FILTER_MODE_MIN_DEFAULT | ||
filter_mag: FILTER_MODE_MAG_DEFAULT | ||
max_anisotropy: 1.0 | ||
} | ||
max_page_count: 0 | ||
attributes { | ||
name: "mycolor" | ||
semantic_type: SEMANTIC_TYPE_NONE | ||
element_count: 4 | ||
normalize: false | ||
data_type: TYPE_FLOAT | ||
coordinate_space: COORDINATE_SPACE_LOCAL | ||
double_values { | ||
v: 1.0 | ||
v: 1.0 | ||
v: 1.0 | ||
v: 1.0 | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function init(self) | ||
msg.post(".", "acquire_input_focus") | ||
|
||
local scale = 0.75 | ||
local spacingx = 160 * scale + 10 | ||
local spacingy = 190 * scale + 10 | ||
local startx = 40 + spacingx*0.5 | ||
local starty = 40 + spacingy*0.5 | ||
|
||
local maxy = 3 | ||
local maxx = 4 | ||
|
||
self.urls = {} | ||
for y = 0, maxy do | ||
for x = 0, maxx do | ||
local p = vmath.vector3(startx + x*spacingx, starty + y*spacingy, 0.5) | ||
local id = factory.create("#factory", p, nil, nil, vmath.vector3(0.8, 0.8, 1)) | ||
local url = msg.url(nil, id, "sprite") | ||
table.insert(self.urls, url) | ||
|
||
go.set(url, "mycolor", vmath.vector4(x/maxx, y/maxy, 0, 1)) | ||
end | ||
end | ||
end | ||
|
||
function on_input(self, action_id, action) | ||
if action_id == hash("touch") and action.released then | ||
for _, url in ipairs(self.urls) do | ||
-- crash: go.animate(url, "mycolor", go.PLAYBACK_ONCE_PINGPONG, vmath.vector4(0, 0, 1, 1), go.EASING_OUTELASTIC, 1) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
uniform highp mat4 view_proj; | ||
|
||
// positions are in world space | ||
attribute highp vec4 position; | ||
attribute mediump vec2 texcoord0; | ||
attribute mediump vec4 mycolor; | ||
|
||
varying mediump vec2 var_texcoord0; | ||
varying mediump vec4 var_mycolor; | ||
|
||
void main() | ||
{ | ||
gl_Position = view_proj * vec4(position.xyz, 1.0); | ||
var_texcoord0 = texcoord0; | ||
var_mycolor = mycolor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters