LeeMcQueen / GameDemo

Demo
0 stars 0 forks source link

watershader.h #22

Open LeeMcQueen opened 3 years ago

LeeMcQueen commented 3 years ago

pragma once

include "ShaderProgram.h"

include "Light.h"

class WaterShader : public ShaderProgram {

public:

WaterShader();

static const char *WATER_VERTEX_FILE;
static const char *WATER_FRAGMENT_FILE;

//变换矩阵加载 参数类型mat4
void loadTransformationMatrix(glm::mat4 matrix);
//投影矩阵加载 参数类型mat4
void loadProjectionMatrix(glm::mat4 matrix);
//观察矩阵加载 参数类型mat4
void loadViewMatrix(glm::mat4 matrix);
//光线信息加载 参数 1:vec3光线颜色 2:vec3光线位置
void loadLight(Light light);

protected:

//继承 给传入shader的VBO进行命名
void bindAttributes() override;
//继承 加载uniform 参数类型char
void getAllUniformLocations() override;

private:

//变换矩阵传递参数
GLuint Location_transformtionMatrix;
//投影矩阵传递参数
GLuint Location_projectionMatrix;
//观察矩阵传递参数
GLuint Location_viewMatrix;
//光线颜色传递参数
GLuint Location_lightColor;
//光线位置传递参数
GLuint Location_lightPosition;

};

LeeMcQueen commented 3 years ago

include "WaterShader.h"

const char WaterShader::WATER_VERTEX_FILE = "terrainVertexShader.txt"; const char WaterShader::WATER_FRAGMENT_FILE = "terrainFragmentShader.txt";

WaterShader::WaterShader() : ShaderProgram(WATER_VERTEX_FILE, WATER_FRAGMENT_FILE) { //给传入shader的VBO进行命名 bindAttributes();

//加载uniform到顶点shader
getAllUniformLocations();   

}

void WaterShader::loadTransformationMatrix(glm::mat4 matrix){

loadMatirx4(Location_transformationMatrix, matrix);

}

void WaterShader::loadProjectionMatrix(glm::mat4 matrix){

loadMatrix4(Location_projectionMatrix, matrix);

}

void WaterShader::loadViewMatrix(glm::mat4 matrix){

loadMatrix4(Location_viewMatrix, matrix);

}

void WaterShader::loadLight(Light light){

loadVector3(Location_lightColor, light.getColor());
loadVector3(Location_lightPosition, light.getPosition());

}

void WaterShader::bindAttributes(){

bindAttribute(0, "position") bindAttribute(1, "textureCoords"); bindAttribute(2, "normal"); }

void WaterShader::getAllUniformLocations(){

Location_transformtonMatrix = getUniformLocation("transformationMatrix");
Location_projectionMatrix = getUniformLocation("projectionMatrix");
Location_viewMatrix = getUniformLocation("viewMatrix");
Location_lightColor = getUniformLocation("lightColor");
Location_lightPosition = getUniformLocation("lightPosition");

}

LeeMcQueen commented 3 years ago

class WaterTile{

public:

WaterTile(float centerX, float centerZ, float height):

float getX() const {
    return _x;
}

float getZ() const {
    return _z;
}

float getHeight() const {
    return _height;
}

float getTileSize() const {
    return TILE_SIZE
}

private:

const flaot TILE_SIZE = 125.0f;
float _x, _z;
gloat _height;

}