-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skybox and bug fix
- Loading branch information
Showing
10 changed files
with
68,627 additions
and
18,976 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#ifndef IMAGE_MANAGER_H_ | ||
#define IMAGE_MANAGER_H_ | ||
|
||
#include <map> | ||
#include <stdio.h> | ||
#include <assert.h> | ||
|
||
#include "Gz.h" | ||
|
||
struct Image | ||
{ | ||
int width, height; | ||
GzColor* data; | ||
|
||
inline const float* GetPixel(int x, int y) | ||
{ | ||
return data[y*width + x]; | ||
} | ||
}; | ||
|
||
|
||
/* | ||
* Manager to create and store ppm images. | ||
*/ | ||
class ImageManager | ||
{ | ||
private: | ||
typedef std::map<std::string, Image*> ImageMap; | ||
|
||
public: | ||
ImageManager() {} | ||
~ImageManager() {} | ||
|
||
static ImageManager* GetSingleton() | ||
{ | ||
static ImageManager manager; | ||
return &manager; | ||
} | ||
|
||
Image* GetImage(const std::string& name, const std::string& file_path) | ||
{ | ||
if(data_.find(name) != data_.end()) | ||
return data_[name]; | ||
FILE* fd = fopen (file_path.c_str(), "rb"); | ||
assert(fd); | ||
Image* image = new Image; | ||
data_[name] = image; | ||
char foo[8]; | ||
unsigned char pixel[3]; | ||
unsigned char dummy; | ||
fscanf (fd, "%s %d %d %c", pixel, &image->width, &image->height, &dummy); | ||
image->data = (GzColor*)malloc(sizeof(GzColor)*(image->width+1)*(image->height+1)); | ||
assert(image); | ||
|
||
for (int i = 0; i <image->width*image->height; i++) { /* create array of GzColor values */ | ||
fread(pixel, sizeof(pixel), 1, fd); | ||
image->data[i][RED] = (float)((int)pixel[RED]) * (1.0f / 255.0f); | ||
image->data[i][GREEN] = (float)((int)pixel[GREEN]) * (1.0f / 255.0f); | ||
image->data[i][BLUE] = (float)((int)pixel[BLUE]) * (1.0f / 255.0f); | ||
} | ||
fclose(fd); | ||
return image; | ||
} | ||
|
||
private: | ||
ImageMap data_; | ||
}; | ||
|
||
|
||
#endif //IMAGE_MANAGER_H_ |
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 |
---|---|---|
@@ -1,73 +1,74 @@ | ||
#ifndef RENDER_H_ | ||
#define RENDER_H_ | ||
|
||
#include "Gz.h" | ||
#include "disp.h" /* include your own disp.h file (e.g. hw1)*/ | ||
|
||
#define MATLEVELS 100 /* how many matrix pushes allowed */ | ||
#define MAX_LIGHTS 10 /* how many lights allowed */ | ||
#define MAX_TEXTURE 10 | ||
|
||
#ifndef GZRENDER | ||
#define GZRENDER | ||
|
||
struct PixelShaderInput; | ||
struct GzRender; | ||
|
||
struct GzRender { /* define a renderer */ | ||
typedef void (*VertexShader)(GzRender *, int, const GzToken *, const GzPointer *, PixelShaderInput[3]); | ||
typedef void (*PixelShader)(GzRender* , const PixelShaderInput&, GzColor); | ||
|
||
GzRenderClass renderClass; | ||
GzDisplay *display; | ||
short open; | ||
GzCamera camera; | ||
short matlevel; /* top of stack - current xform */ | ||
GzMatrix Ximage[MATLEVELS]; /* stack of xforms (Xsm) */ | ||
GzMatrix Xnorm[MATLEVELS]; /* xforms for norms (Xim) */ | ||
GzMatrix Xsp; /* NDC to screen (pers-to-screen) */ | ||
GzMatrix Xwm; | ||
GzMatrix Xsm; | ||
GzMatrix Xsm_inverse; | ||
GzMatrix Xn; //Transformation for normals from Object to World space. | ||
GzMatrix Xn_inverse; | ||
GzColor flatcolor; /* color state for flat shaded triangles */ | ||
int interp_mode; | ||
int numlights; | ||
GzLight lights[MAX_LIGHTS]; | ||
GzLight ambientlight; | ||
GzColor Ka, Kd, Ks; | ||
float spec; /* specular power */ | ||
GzTexture tex_fun[MAX_TEXTURE]; /* tex_fun(float u, float v, GzColor color) */ | ||
int tex_count; | ||
VertexShader v_shader; | ||
PixelShader p_shader; | ||
bool show_wireframe; | ||
GzDisplay* texture_display[MAX_TEXTURE]; | ||
}; | ||
#endif | ||
|
||
// Function declaration | ||
// HW2 | ||
int GzNewRender(GzRender **render, GzRenderClass renderClass, GzDisplay *display); | ||
int GzFreeRender(GzRender *render); | ||
int GzBeginRender(GzRender *render); | ||
int GzPutAttribute(GzRender *render, int numAttributes, GzToken *nameList, | ||
GzPointer *valueList); | ||
int GzPutTriangle(GzRender *render, int numParts, GzToken *nameList, | ||
GzPointer *valueList); | ||
|
||
// HW3 | ||
int GzPutCamera(GzRender *render, GzCamera *camera); | ||
int GzPushMatrix(GzRender *render, GzMatrix matrix); | ||
int GzPopMatrix(GzRender *render); | ||
|
||
// Object Translation | ||
int GzRotXMat(float degree, GzMatrix mat); | ||
int GzRotYMat(float degree, GzMatrix mat); | ||
int GzRotZMat(float degree, GzMatrix mat); | ||
int GzTrxMat(GzCoord translate, GzMatrix mat); | ||
int GzScaleMat(GzCoord scale, GzMatrix mat); | ||
|
||
|
||
#ifndef RENDER_H_ | ||
#define RENDER_H_ | ||
|
||
#include "Gz.h" | ||
#include "disp.h" /* include your own disp.h file (e.g. hw1)*/ | ||
|
||
#define MATLEVELS 100 /* how many matrix pushes allowed */ | ||
#define MAX_LIGHTS 10 /* how many lights allowed */ | ||
#define MAX_TEXTURE 10 | ||
|
||
#ifndef GZRENDER | ||
#define GZRENDER | ||
|
||
struct PixelShaderInput; | ||
struct GzRender; | ||
|
||
struct GzRender { /* define a renderer */ | ||
typedef void (*VertexShader)(GzRender *, int, const GzToken *, const GzPointer *, PixelShaderInput[3]); | ||
typedef void (*PixelShader)(GzRender* , const PixelShaderInput&, GzColor); | ||
|
||
GzRenderClass renderClass; | ||
GzDisplay *display; | ||
short open; | ||
GzCamera camera; | ||
short matlevel; /* top of stack - current xform */ | ||
GzMatrix Ximage[MATLEVELS]; /* stack of xforms (Xsm) */ | ||
GzMatrix Xnorm[MATLEVELS]; /* xforms for norms (Xim) */ | ||
GzMatrix Xsp; /* NDC to screen (pers-to-screen) */ | ||
GzMatrix Xwm; | ||
GzMatrix Xsm; | ||
GzMatrix Xsm_inverse; | ||
GzMatrix Xn; //Transformation for normals from Object to World space. | ||
GzMatrix Xn_inverse; | ||
GzColor flatcolor; /* color state for flat shaded triangles */ | ||
int interp_mode; | ||
int numlights; | ||
GzLight lights[MAX_LIGHTS]; | ||
GzLight ambientlight; | ||
GzColor Ka, Kd, Ks; | ||
float spec; /* specular power */ | ||
GzTexture tex_fun[MAX_TEXTURE]; /* tex_fun(float u, float v, GzColor color) */ | ||
char tex_name[MAX_TEXTURE][64]; | ||
int tex_count; | ||
VertexShader v_shader; | ||
PixelShader p_shader; | ||
bool show_wireframe; | ||
GzDisplay* texture_display[MAX_TEXTURE]; | ||
}; | ||
#endif | ||
|
||
// Function declaration | ||
// HW2 | ||
int GzNewRender(GzRender **render, GzRenderClass renderClass, GzDisplay *display); | ||
int GzFreeRender(GzRender *render); | ||
int GzBeginRender(GzRender *render); | ||
int GzPutAttribute(GzRender *render, int numAttributes, GzToken *nameList, | ||
GzPointer *valueList); | ||
int GzPutTriangle(GzRender *render, int numParts, GzToken *nameList, | ||
GzPointer *valueList); | ||
|
||
// HW3 | ||
int GzPutCamera(GzRender *render, GzCamera *camera); | ||
int GzPushMatrix(GzRender *render, GzMatrix matrix); | ||
int GzPopMatrix(GzRender *render); | ||
|
||
// Object Translation | ||
int GzRotXMat(float degree, GzMatrix mat); | ||
int GzRotYMat(float degree, GzMatrix mat); | ||
int GzRotZMat(float degree, GzMatrix mat); | ||
int GzTrxMat(GzCoord translate, GzMatrix mat); | ||
int GzScaleMat(GzCoord scale, GzMatrix mat); | ||
|
||
|
||
#endif //RENDER_H_ |
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 |
---|---|---|
@@ -1,56 +1,59 @@ | ||
#ifndef SHADERS_H_ | ||
#define SHADERS_H_ | ||
|
||
#include "rend.h" | ||
|
||
struct PixelShaderInput | ||
{ | ||
GzCoord positon; | ||
GzCoord normal; | ||
GzTextureIndex texture; | ||
GzColor color; | ||
//alpha vary from 0 to 100 | ||
GzIntensity alpha; | ||
|
||
static bool lerp_normal; | ||
static bool lerp_texture; | ||
static bool lerp_color; | ||
|
||
void Assign(const GzCoord& p, const GzCoord& n, const GzTextureIndex& t, const GzColor& c) | ||
{ | ||
for(int i=0; i<3; i++) | ||
{ | ||
positon[i] = p[i]; | ||
normal[i] = n[i]; | ||
color[i] = c[i]; | ||
} | ||
|
||
for(int i=0; i<2; i++) | ||
{ | ||
texture[i] = t[i]; | ||
} | ||
} | ||
}; | ||
|
||
void FlatVertexShader(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void FlatPixelShader(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void GouraudVertexShader(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void GouraudPixelShader(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void GouraudRefractionPixelShader(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
void GouraudReflectionPixelShader(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void PhongVertexShader(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void PhongPixelShader(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void PhongTextureVS(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void PhongTexturePS(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void GlobalReflectionVS(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void GlobalReflectionPS(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void FinalWaterVS(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void FinalWaterPS(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
#ifndef SHADERS_H_ | ||
#define SHADERS_H_ | ||
|
||
#include "rend.h" | ||
|
||
struct PixelShaderInput | ||
{ | ||
GzCoord positon; | ||
GzCoord normal; | ||
GzTextureIndex texture; | ||
GzColor color; | ||
//alpha vary from 0 to 100 | ||
GzIntensity alpha; | ||
|
||
static bool lerp_normal; | ||
static bool lerp_texture; | ||
static bool lerp_color; | ||
|
||
void Assign(const GzCoord& p, const GzCoord& n, const GzTextureIndex& t, const GzColor& c) | ||
{ | ||
for(int i=0; i<3; i++) | ||
{ | ||
positon[i] = p[i]; | ||
normal[i] = n[i]; | ||
color[i] = c[i]; | ||
} | ||
|
||
for(int i=0; i<2; i++) | ||
{ | ||
texture[i] = t[i]; | ||
} | ||
} | ||
}; | ||
|
||
void FlatVertexShader(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void FlatPixelShader(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void GouraudVertexShader(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void GouraudPixelShader(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void GouraudRefractionPixelShader(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
void GouraudReflectionPixelShader(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void PhongVertexShader(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void PhongPixelShader(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void PhongTextureVS(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void PhongTexturePS(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void GlobalReflectionVS(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void GlobalReflectionPS(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void FinalWaterVS(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void FinalWaterPS(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
void SkyboxVS(GzRender *render, int numParts, const GzToken *nameList, const GzPointer *valueList, PixelShaderInput vs_output[3]); | ||
void SkyboxPS(GzRender* render, const PixelShaderInput& input, GzColor color); | ||
|
||
#endif //SHADERS_H_ |
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
Oops, something went wrong.