Browse Source

reduced color vector from 4 elements to 3

master
Bergmann89 4 years ago
parent
commit
ae9f57b993
15 changed files with 39 additions and 37 deletions
  1. +1
    -1
      space-crush-app/resources/shader/asteroid/frag.glsl
  2. +4
    -3
      space-crush-app/resources/shader/asteroid/shared.glsl
  3. +1
    -1
      space-crush-app/resources/shader/asteroid/vert.glsl
  4. +1
    -1
      space-crush-app/resources/shader/planet/frag.glsl
  5. +4
    -3
      space-crush-app/resources/shader/planet/shared.glsl
  6. +4
    -4
      space-crush-app/resources/shader/planet/vert.glsl
  7. +1
    -1
      space-crush-app/resources/shader/ship/frag.glsl
  8. +3
    -3
      space-crush-app/resources/shader/ship/shared.glsl
  9. +1
    -1
      space-crush-app/resources/shader/ship/vert.glsl
  10. +2
    -2
      space-crush-app/src/constants.rs
  11. +2
    -2
      space-crush-app/src/main.rs
  12. +4
    -4
      space-crush-app/src/render/asteroids.rs
  13. +3
    -3
      space-crush-app/src/render/planets.rs
  14. +4
    -4
      space-crush-app/src/render/ships.rs
  15. +4
    -4
      space-crush-common/src/components/player.rs

+ 1
- 1
space-crush-app/resources/shader/asteroid/frag.glsl View File

@@ -21,7 +21,7 @@ out vec4 outColor;

void main() {
float alpha = glow(GLOW_ARGS, fragmentData.texCoords, uGlobal.time);
vec4 glow = vec4(fragmentData.color.rgb, fragmentData.color.a * alpha);
vec4 glow = vec4(fragmentData.color, GLOW_ALPHA * alpha);
vec4 tex = texture(uTexture[textureId], 0.5 * GLOW_SIZE * fragmentData.texCoords + vec2(0.5));

outColor = tex * tex.a + glow * (1.0 - tex.a);


+ 4
- 3
space-crush-app/resources/shader/asteroid/shared.glsl View File

@@ -1,13 +1,14 @@
struct FragmentData {
vec2 texCoords;
vec4 color;
vec3 color;
};

struct VertexData {
vec2 pos;
float size;
vec4 color;
vec3 color;
int texture;
};

const float GLOW_SIZE = 2.0; // relative to planet size
const float GLOW_SIZE = 2.0; // relative to planet size
const float GLOW_ALPHA = 0.2;

+ 1
- 1
space-crush-app/resources/shader/asteroid/vert.glsl View File

@@ -5,7 +5,7 @@

layout (location = 0) in vec2 inPosition;
layout (location = 1) in float inSize;
layout (location = 2) in vec4 inColor;
layout (location = 2) in vec3 inColor;
layout (location = 3) in int inTexture;

out VertexData vertexData;


+ 1
- 1
space-crush-app/resources/shader/planet/frag.glsl View File

@@ -20,7 +20,7 @@ out vec4 outColor;

void main() {
float alpha = glow(GLOW_ARGS, fragmentData.texCoords, uGlobal.time);
vec4 glow = vec4(fragmentData.color.rgb, fragmentData.color.a * alpha);
vec4 glow = vec4(fragmentData.color, GLOW_ALPHA * alpha);
vec4 tex = texture(uTexture, 0.5 * GLOW_SIZE * fragmentData.texCoords + vec2(0.5));

outColor = tex * tex.a + glow * (1.0 - tex.a);


+ 4
- 3
space-crush-app/resources/shader/planet/shared.glsl View File

@@ -1,12 +1,13 @@
struct FragmentData {
vec2 texCoords;
vec4 color;
vec3 color;
};

struct VertexData {
vec2 pos;
float size;
vec4 color;
vec3 color;
};

const float GLOW_SIZE = 2.0; // relative to planet size
const float GLOW_SIZE = 2.0; // relative to planet size
const float GLOW_ALPHA = 0.2;

+ 4
- 4
space-crush-app/resources/shader/planet/vert.glsl View File

@@ -5,12 +5,12 @@

layout (location = 0) in vec2 inPosition;
layout (location = 1) in float inSize;
layout (location = 2) in vec4 inColor;
layout (location = 2) in vec3 inColor;

out VertexData vertexData;

void main() {
vertexData.pos = inPosition;
vertexData.size = inSize;
vertexData.color = inColor;
vertexData.pos = inPosition;
vertexData.size = inSize;
vertexData.color = inColor;
}

+ 1
- 1
space-crush-app/resources/shader/ship/frag.glsl View File

@@ -21,7 +21,7 @@ out vec4 outColor;

void main() {
float alpha = glow(GLOW_ARGS, fragmentData.texCoords, uGlobal.time);
vec4 glow = vec4(fragmentData.color.rgb, fragmentData.color.a * alpha * GLOW_ALPHA);
vec4 glow = vec4(fragmentData.color, GLOW_ALPHA * alpha);
vec4 tex = texture(uTexture[textureId], 0.5 * GLOW_SIZE * fragmentData.texCoords + vec2(0.5));

outColor = tex * tex.a + glow * (1.0 - tex.a);


+ 3
- 3
space-crush-app/resources/shader/ship/shared.glsl View File

@@ -1,15 +1,15 @@
struct FragmentData {
vec2 texCoords;
vec4 color;
vec3 color;
};

struct VertexData {
vec2 pos;
vec2 dir;
vec4 color;
vec3 color;
int texture;
};

const float SHIP_SIZE = 25.0; // absolute ship size
const float GLOW_SIZE = 4.0; // relative to ship size
const float GLOW_ALPHA = 0.5;
const float GLOW_ALPHA = 0.1;

+ 1
- 1
space-crush-app/resources/shader/ship/vert.glsl View File

@@ -4,7 +4,7 @@

layout (location = 0) in vec2 inPosition;
layout (location = 1) in vec2 inDirection;
layout (location = 2) in vec4 inColor;
layout (location = 2) in vec3 inColor;
layout (location = 3) in int inTexture;

out VertexData vertexData;


+ 2
- 2
space-crush-app/src/constants.rs View File

@@ -1,6 +1,6 @@
use std::time::Duration;

use glc::vector::Vector4f;
use glc::vector::Vector3f;

pub const UNIFORM_BUFFER_INDEX_CAMERA: gl::GLuint = 0;
pub const UNIFORM_BUFFER_INDEX_UNIFORM: gl::GLuint = 1;
@@ -15,4 +15,4 @@ pub const FLEET_SELECT_TEXT_OFFSET: f32 = 40.0;
pub const FLEET_SELECT_ANIMATION_TIME: f32 = 0.400;
pub const FLEET_SELECT_TEXT_SIZE: f32 = 24.0;

pub const PLAYER_COLOR_DEFAULT: Vector4f = Vector4f::new(1.0, 1.0, 1.0, 0.1);
pub const PLAYER_COLOR_DEFAULT: Vector3f = Vector3f::new(1.0, 1.0, 1.0);

+ 2
- 2
space-crush-app/src/main.rs View File

@@ -1,4 +1,4 @@
use glc::vector::Vector4f;
use glc::vector::Vector3f;
use log::{error, info};
use rand::random;
use space_crush_app::{App, Error};
@@ -38,7 +38,7 @@ fn run(vfs: Vfs) -> Result<(), Error> {
let mut common = Dispatcher::new(&mut world)?;
let player1 = world
.create_entity()
.with(Player::new(Vector4f::new(0.0, 0.5, 1.0, 0.1)))
.with(Player::new(Vector3f::new(0.0, 0.5, 1.0)))
.build();
let mut app = App::new(&mut world, player1)?;



+ 4
- 4
space-crush-app/src/render/asteroids.rs View File

@@ -5,7 +5,7 @@ use glc::{
misc::{BindGuard, Bindable},
shader::{Program, Type, Uniform},
texture::Texture,
vector::{Vector2f, Vector4f},
vector::{Vector2f, Vector3f},
vertex_array::{DataType, VertexArray},
};
use space_crush_common::{
@@ -36,7 +36,7 @@ pub struct Asteroids {
struct VertexData {
pos: Vector2f,
size: gl::GLfloat,
color: Vector4f,
color: Vector3f,
texture: gl::GLint,
}

@@ -65,13 +65,13 @@ impl Asteroids {
const OFFSET_POS: gl::GLsizei = 0;
const OFFSET_SIZ: gl::GLsizei = OFFSET_POS + size_of::<Vector2f>() as gl::GLsizei;
const OFFSET_CLR: gl::GLsizei = OFFSET_SIZ + size_of::<gl::GLfloat>() as gl::GLsizei;
const OFFSET_TEX: gl::GLsizei = OFFSET_CLR + size_of::<Vector4f>() as gl::GLsizei;
const OFFSET_TEX: gl::GLsizei = OFFSET_CLR + size_of::<Vector3f>() as gl::GLsizei;

let vertex_array = VertexArray::builder()
.bind_buffer(Buffer::new()?)
.vertex_attrib_pointer(0, 2, DataType::Float, false, STRIDE, OFFSET_POS)?
.vertex_attrib_pointer(1, 1, DataType::Float, false, STRIDE, OFFSET_SIZ)?
.vertex_attrib_pointer(2, 4, DataType::Float, false, STRIDE, OFFSET_CLR)?
.vertex_attrib_pointer(2, 3, DataType::Float, false, STRIDE, OFFSET_CLR)?
.vertex_attrib_pointer(3, 1, DataType::Int, false, STRIDE, OFFSET_TEX)?
.build()?;



+ 3
- 3
space-crush-app/src/render/planets.rs View File

@@ -5,7 +5,7 @@ use glc::{
misc::{BindGuard, Bindable},
shader::{Program, Type, Uniform},
texture::Texture,
vector::{Vector2f, Vector4f},
vector::{Vector2f, Vector3f},
vertex_array::{DataType, VertexArray},
};
use space_crush_common::{
@@ -35,7 +35,7 @@ pub struct Planets {
struct VertexData {
pos: Vector2f,
size: gl::GLfloat,
color: Vector4f,
color: Vector3f,
}

impl Planets {
@@ -67,7 +67,7 @@ impl Planets {
.bind_buffer(Buffer::new()?)
.vertex_attrib_pointer(0, 2, DataType::Float, false, STRIDE, OFFSET_POS)?
.vertex_attrib_pointer(1, 1, DataType::Float, false, STRIDE, OFFSET_SIZ)?
.vertex_attrib_pointer(2, 4, DataType::Float, false, STRIDE, OFFSET_CLR)?
.vertex_attrib_pointer(2, 3, DataType::Float, false, STRIDE, OFFSET_CLR)?
.build()?;

let reader_id = world


+ 4
- 4
space-crush-app/src/render/ships.rs View File

@@ -5,7 +5,7 @@ use glc::{
misc::{BindGuard, Bindable},
shader::{Program, Type, Uniform},
texture::Texture,
vector::{Vector2f, Vector4f},
vector::{Vector2f, Vector3f},
vertex_array::{DataType, VertexArray},
};
use space_crush_common::{
@@ -34,7 +34,7 @@ pub struct Ships {
struct VertexData {
pos: Vector2f,
dir: Vector2f,
color: Vector4f,
color: Vector3f,
texture: gl::GLint,
}

@@ -58,13 +58,13 @@ impl Ships {
const OFFSET_POS: gl::GLsizei = 0;
const OFFSET_DIR: gl::GLsizei = OFFSET_POS + size_of::<Vector2f>() as gl::GLsizei;
const OFFSET_CLR: gl::GLsizei = OFFSET_DIR + size_of::<Vector2f>() as gl::GLsizei;
const OFFSET_TEX: gl::GLsizei = OFFSET_CLR + size_of::<Vector4f>() as gl::GLsizei;
const OFFSET_TEX: gl::GLsizei = OFFSET_CLR + size_of::<Vector3f>() as gl::GLsizei;

let vertex_array = VertexArray::builder()
.bind_buffer(Buffer::new()?)
.vertex_attrib_pointer(0, 2, DataType::Float, false, STRIDE, OFFSET_POS)?
.vertex_attrib_pointer(1, 2, DataType::Float, false, STRIDE, OFFSET_DIR)?
.vertex_attrib_pointer(2, 4, DataType::Float, false, STRIDE, OFFSET_CLR)?
.vertex_attrib_pointer(2, 3, DataType::Float, false, STRIDE, OFFSET_CLR)?
.vertex_attrib_pointer(3, 1, DataType::Int, false, STRIDE, OFFSET_TEX)?
.build()?;



+ 4
- 4
space-crush-common/src/components/player.rs View File

@@ -1,4 +1,4 @@
use glc::vector::Vector4f;
use glc::vector::Vector3f;
use serde::{Deserialize, Serialize};
use specs::{
error::NoError,
@@ -9,7 +9,7 @@ use specs::{
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct Player {
index: usize,
color: Vector4f,
color: Vector3f,
}

#[derive(Copy, Clone, Debug)]
@@ -24,7 +24,7 @@ pub struct OwnedData<M> {

impl Player {
#[inline]
pub fn new(color: Vector4f) -> Self {
pub fn new(color: Vector3f) -> Self {
Self {
index: next_index(),
color,
@@ -37,7 +37,7 @@ impl Player {
}

#[inline]
pub fn color(&self) -> &Vector4f {
pub fn color(&self) -> &Vector3f {
&self.color
}
}


Loading…
Cancel
Save