Class: Plane

Inherits:
Sprite show all
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

Attributes inherited from LiteRGSS::ShaderedSprite

#blendmode, #shader

Attributes inherited from LiteRGSS::Sprite

#__index__, #angle, #height, #mirror, #opacity, #src_rect, #viewport, #width, #x, #y, #z, #zoom

Class Method Summary collapse

Instance Method Summary collapse

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

new, #set_position

Methods inherited from LiteRGSS::Disposable

#dispose, #disposed?

Constructor Details

#initialize(viewport) ⇒ Plane

Create a new plane

Parameters:



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(viewport)
  super(viewport)
  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_typeInteger

Return the blend type

Returns:



155
156
157
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 155

def blend_type
  @blend_type
end

#colorColor

Return the color of the plane /!\ this is unlinked set() won't change the color

Returns:



147
148
149
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 147

def color
  @color
end

#textureTexture

Get the real texture

Returns:



139
140
141
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 139

def texture
  @texture
end

#toneTone

Return the tone of the plane /!\ this is unlinked set() won't change the color

Returns:



151
152
153
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 151

def tone
  @tone
end

#visibleBoolean

Return the visibility of the plane

Returns:

  • (Boolean)


143
144
145
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 143

def visible
  @visible
end

Class Method Details

.textureTexture

Get the generic plane texture

Returns:



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

#bitmapTexture Also known as: working_texture

Get the real texture

Returns:



188
189
190
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00003 Drawable.rb', line 188

def texture
  @texture
end

#oxFloat

Get the ox of the Plane

Returns:

  • (Float)


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

Parameters:

  • origin (Float)


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

#oyFloat

Get the oy of the Plane

Returns:

  • (Float)


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

Parameters:

  • origin (Float)


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

Parameters:

  • ox (Float)
  • oy (Float)


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

Parameters:

  • zoom (Float)


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_xFloat

Get the zoom_x of the Plane

Returns:

  • (Float)


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

Parameters:

  • zoom (Float)


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_yFloat

Get the zoom_y of the Plane

Returns:

  • (Float)


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

Parameters:

  • zoom (Float)


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