1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-01-11 18:00:34 +00:00

shaded rug

This commit is contained in:
Zeno Rogue 2020-04-17 15:01:55 +02:00
parent 09ce04bd4a
commit 7a71132806
3 changed files with 17 additions and 8 deletions

View File

@ -36,6 +36,7 @@ static const int POLY_INTENSE = (1<<23); // extra intense colors
static const int POLY_DEBUG = (1<<24); // debug this shape static const int POLY_DEBUG = (1<<24); // debug this shape
static const int POLY_PRINTABLE = (1<<25); // these walls are printable static const int POLY_PRINTABLE = (1<<25); // these walls are printable
static const int POLY_FAT = (1<<26); // fatten this model in WRL export (used for Rug) static const int POLY_FAT = (1<<26); // fatten this model in WRL export (used for Rug)
static const int POLY_SHADE_TEXTURE = (1<<27); // texture has 'z' coordinate for shading
/** \brief A graphical element that can be drawn. Objects are not drawn immediately but rather queued. /** \brief A graphical element that can be drawn. Objects are not drawn immediately but rather queued.
* *
@ -596,6 +597,7 @@ void dqi_poly::gldraw() {
if(tinf) { if(tinf) {
glhr::be_textured(); glhr::be_textured();
if(flags & POLY_SHADE_TEXTURE) current_display->next_shader_flags |= GF_TEXTURE_SHADED;
glBindTexture(GL_TEXTURE_2D, tinf->texture_id); glBindTexture(GL_TEXTURE_2D, tinf->texture_id);
glhr::vertices_texture(v, tinf->tvertices, offset, offset_texture); glhr::vertices_texture(v, tinf->tvertices, offset, offset_texture);
ioffset = 0; ioffset = 0;

10
rug.cpp
View File

@ -987,20 +987,18 @@ void drawTriangle(triangle& t) {
if(!t.m[i]->valid) return; if(!t.m[i]->valid) return;
} }
/*
ld col = 1; ld col = 1;
if(num == 3) { if(true) {
hyperpoint hc = (h[1] - h[0]) ^ (h[2] - h[0]); hyperpoint hc = (t.m[1]->native - t.m[0]->native) ^ (t.m[2]->native - t.m[0]->native);
double hch = hypot_d(3, hc); double hch = hypot_d(3, hc);
col = (2 + hc[0]/hch) / 3; col = (2 + hc[0]/hch) / 3;
} }
*/
for(int i=0; i<3; i++) { for(int i=0; i<3; i++) {
if(t.m[i]->native[3] != 1) if(t.m[i]->native[3] != 1)
println(hlog, "bad point: ", t.m[i]->native); println(hlog, "bad point: ", t.m[i]->native);
curvepoint(t.m[i]->native); curvepoint(t.m[i]->native);
tinf.tvertices.push_back(glhr::pointtogl(point3(t.m[i]->x1, t.m[i]->y1, 0))); tinf.tvertices.push_back(glhr::pointtogl(point3(t.m[i]->x1, t.m[i]->y1, col)));
} }
} }
@ -1081,7 +1079,7 @@ EX void drawRugScene() {
rug.V = rugView; rug.V = rugView;
rug.offset_texture = 0; rug.offset_texture = 0;
rug.tinf = &tinf; rug.tinf = &tinf;
rug.flags = POLY_TRIANGLES | POLY_FAT | POLY_PRINTABLE | POLY_ALWAYS_IN | POLY_ISSIDE; rug.flags = POLY_TRIANGLES | POLY_FAT | POLY_PRINTABLE | POLY_ALWAYS_IN | POLY_ISSIDE | POLY_SHADE_TEXTURE;
dynamicval<projection_configuration> p(pconf, rconf); dynamicval<projection_configuration> p(pconf, rconf);
calcparam(); calcparam();

View File

@ -16,8 +16,9 @@ constexpr flagtype GF_TEXTURE = 1;
constexpr flagtype GF_VARCOLOR = 2; constexpr flagtype GF_VARCOLOR = 2;
constexpr flagtype GF_LIGHTFOG = 4; constexpr flagtype GF_LIGHTFOG = 4;
constexpr flagtype GF_LEVELS = 8; constexpr flagtype GF_LEVELS = 8;
constexpr flagtype GF_TEXTURE_SHADED = 16;
constexpr flagtype GF_which = 15; constexpr flagtype GF_which = 31;
constexpr flagtype SF_PERS3 = 256; constexpr flagtype SF_PERS3 = 256;
constexpr flagtype SF_BAND = 512; constexpr flagtype SF_BAND = 512;
@ -62,7 +63,15 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) {
varying += "varying mediump vec4 vColor;\n"; varying += "varying mediump vec4 vColor;\n";
fmain += "gl_FragColor = vColor;\n"; fmain += "gl_FragColor = vColor;\n";
if(shader_flags & GF_TEXTURE) { if(shader_flags & GF_TEXTURE_SHADED) {
vsh += "attribute mediump vec3 aTexture;\n";
varying += "varying mediump vec3 vTexCoord;\n";
fsh += "uniform mediump sampler2D tTexture;\n";
vmain += "vTexCoord = aTexture;\n";
fmain += "gl_FragColor *= texture2D(tTexture, vTexCoord.xy);\n";
fmain += "gl_FragColor.rgb *= vTexCoord.z;\n";
}
else if(shader_flags & GF_TEXTURE) {
vsh += "attribute mediump vec2 aTexture;\n"; vsh += "attribute mediump vec2 aTexture;\n";
varying += "varying mediump vec2 vTexCoord;\n"; varying += "varying mediump vec2 vTexCoord;\n";
fsh += "uniform mediump sampler2D tTexture;\n"; fsh += "uniform mediump sampler2D tTexture;\n";