Class: Plane
- Inherits:
-
Sprite
- Object
- LiteRGSS::Disposable
- LiteRGSS::Drawable
- LiteRGSS::Sprite
- LiteRGSS::ShaderedSprite
- Sprite
- Plane
- Defined in:
- scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb
Overview
Class simulating repeating texture
Constant Summary collapse
- SHADER =
<<~ENDOFSHADER // Viewport tone (required) uniform vec4 tone; // Viewport color (required) uniform vec4 color; // Zoom configuration uniform vec2 zoom; // Origin configuration uniform vec2 origin; // Texture size configuration uniform vec2 textureSize; // Texture source uniform sampler2D texture; // Plane Texture (what's zoomed origined etc...) uniform sampler2D planeTexture; // Screen size uniform vec2 screenSize; // Gray scale transformation vector const vec3 lumaF = vec3(.299, .587, .114); // Main process void main() { // Coordinate on the screen in pixel vec2 screenCoord = gl_TexCoord[0].xy * screenSize; // Coordinaet in the texture in pixel (including zoom) vec2 bmpCoord = mod(origin + screenCoord / zoom, textureSize) / textureSize; vec4 frag = texture2D(planeTexture, bmpCoord); // Tone&Color process frag.rgb = mix(frag.rgb, color.rgb, color.a); float luma = dot(frag.rgb, lumaF); frag.rgb += tone.rgb; frag.rgb = mix(frag.rgb, vec3(luma), tone.w); frag.a *= gl_Color.a; // Result gl_FragColor = frag * texture2D(texture, gl_TexCoord[0].xy); } ENDOFSHADER
Instance Attribute Summary collapse
-
#blend_type ⇒ Integer
Return the blend type.
-
#color ⇒ Color
Return the color of the plane /!\ this is unlinked set() won't change the color.
-
#texture ⇒ Texture
Get the real texture.
-
#tone ⇒ Tone
Return the tone of the plane /!\ this is unlinked set() won't change the color.
-
#visible ⇒ Boolean
Return the visibility of the plane.
Attributes inherited from LiteRGSS::ShaderedSprite
Attributes inherited from LiteRGSS::Sprite
#__index__, #angle, #height, #mirror, #opacity, #src_rect, #viewport, #width, #x, #y, #z, #zoom
Class Method Summary collapse
-
.texture ⇒ Texture
Get the generic plane texture.
Instance Method Summary collapse
-
#bitmap ⇒ Texture
(also: #working_texture)
Get the real texture.
-
#initialize(viewport) ⇒ Plane
constructor
Create a new plane.
-
#ox ⇒ Float
Get the ox of the Plane.
-
#ox=(origin)
Set the ox of the Plane.
-
#oy ⇒ Float
Get the oy of the Plane.
-
#oy=(origin)
Set the oy of the Plane.
-
#set_origin(ox, oy)
Set the origin of the Plane.
-
#zoom=(zoom)
Set the zoom of the Plane.
-
#zoom_x ⇒ Float
Get the zoom_x of the Plane.
-
#zoom_x=(zoom)
Set the zoom_x of the Plane.
-
#zoom_y ⇒ Float
Get the zoom_y of the Plane.
-
#zoom_y=(zoom)
Set the zoom_y of the Plane.
Methods inherited from Sprite
#load, #mouse_in?, #set_origin_div, #set_rect, #set_rect_div, #set_z, #simple_mouse_in?, #translate_mouse_coords, #update
Methods inherited from LiteRGSS::Sprite
Methods inherited from LiteRGSS::Disposable
Constructor Details
#initialize(viewport) ⇒ Plane
Create a new plane
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 159 def initialize() super() self.shader = Shader.new(SHADER) self.working_texture = Plane.texture self.tone = Tone.new(0, 0, 0, 0) self.color = Color.new(255, 255, 255, 0) @blend_type = 0 @texture = nil @origin = [0, 0] self.visible = true set_origin(0, 0) @zoom = [1, 1] self.zoom = 1 shader.set_float_uniform('screenSize', [width, height]) end |
Instance Attribute Details
#blend_type ⇒ Integer
Return the blend type
155 156 157 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 155 def blend_type @blend_type end |
#color ⇒ Color
Return the color of the plane /!\ this is unlinked set() won't change the color
147 148 149 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 147 def color @color end |
#texture ⇒ Texture
Get the real texture
139 140 141 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 139 def texture @texture end |
#tone ⇒ Tone
Return the tone of the plane /!\ this is unlinked set() won't change the color
151 152 153 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 151 def tone @tone end |
#visible ⇒ Boolean
Return the visibility of the plane
143 144 145 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 143 def visible @visible end |
Class Method Details
.texture ⇒ Texture
Get the generic plane texture
295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 295 def texture if !@texture || @texture.disposed? @texture = Texture.new(Graphics.width, Graphics.height) image = Image.new(Graphics.width, Graphics.height) # TODO: revert to image.fill_rect(0, 0, Graphics.width, Graphics.height, Color.new(255, 255, 255, 255)) # once liteRGSS2 gets fixed on this function Graphics.height.times do |y| image.fill_rect(0, y, Graphics.width, 1, Color.new(255, 255, 255, 255)) end image.copy_to_bitmap(@texture) image.dispose end return @texture end |
Instance Method Details
#bitmap ⇒ Texture Also known as: working_texture
Get the real texture
188 189 190 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 188 def texture @texture end |
#ox ⇒ Float
Get the ox of the Plane
248 249 250 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 248 def ox @origin[0] end |
#ox=(origin)
Set the ox of the Plane
241 242 243 244 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 241 def ox=(origin) @origin[0] = origin shader.set_float_uniform('origin', @origin) end |
#oy ⇒ Float
Get the oy of the Plane
261 262 263 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 261 def oy @origin[1] end |
#oy=(origin)
Set the oy of the Plane
254 255 256 257 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 254 def oy=(origin) @origin[1] = origin shader.set_float_uniform('origin', @origin) end |
#set_origin(ox, oy)
Set the origin of the Plane
233 234 235 236 237 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 233 def set_origin(ox, oy) @origin[0] = ox @origin[1] = oy shader.set_float_uniform('origin', @origin) end |
#zoom=(zoom)
Set the zoom of the Plane
199 200 201 202 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 199 def zoom=(zoom) @zoom[0] = @zoom[1] = zoom shader.set_float_uniform('zoom', @zoom) end |
#zoom_x ⇒ Float
Get the zoom_x of the Plane
213 214 215 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 213 def zoom_x @zoom[0] end |
#zoom_x=(zoom)
Set the zoom_x of the Plane
206 207 208 209 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 206 def zoom_x=(zoom) @zoom[0] = zoom shader.set_float_uniform('zoom', @zoom) end |
#zoom_y ⇒ Float
Get the zoom_y of the Plane
226 227 228 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 226 def zoom_y @zoom[1] end |
#zoom_y=(zoom)
Set the zoom_y of the Plane
219 220 221 222 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 219 def zoom_y=(zoom) @zoom[1] = zoom shader.set_float_uniform('zoom', @zoom) end |