Browse Source

Add TextureStage::M_emission mode

This is similar to M_glow, except that the emission factor is in the RGB channels.
rdb 5 years ago
parent
commit
05876317cf

+ 7 - 0
panda/src/egg/eggTexture.cxx

@@ -558,6 +558,7 @@ affects_polygon_alpha() const {
   case ET_gloss:
   case ET_height:
   case ET_normal_gloss:
+  case ET_emission:
     return false;
 
   case ET_selector:
@@ -882,6 +883,9 @@ string_env_type(const string &string) {
   } else if (cmp_nocase_uh(string, "normal_gloss") == 0) {
     return ET_normal_gloss;
 
+  } else if (cmp_nocase_uh(string, "emission") == 0) {
+    return ET_emission;
+
   } else {
     return ET_unspecified;
   }
@@ -1312,6 +1316,9 @@ ostream &operator << (ostream &out, EggTexture::EnvType type) {
 
   case EggTexture::ET_normal_gloss:
     return out << "normal_gloss";
+
+  case EggTexture::ET_emission:
+    return out << "emission";
   }
 
   nassertr(false, out);

+ 1 - 0
panda/src/egg/eggTexture.h

@@ -107,6 +107,7 @@ PUBLISHED:
     ET_height,
     ET_selector,
     ET_normal_gloss,
+    ET_emission,
   };
   enum CombineMode {
     CM_unspecified,

+ 4 - 0
panda/src/egg2pg/eggLoader.cxx

@@ -1540,6 +1540,10 @@ make_texture_stage(const EggTexture *egg_tex) {
     stage->set_mode(TextureStage::M_normal_gloss);
     break;
 
+  case EggTexture::ET_emission:
+    stage->set_mode(TextureStage::M_emission);
+    break;
+
   case EggTexture::ET_unspecified:
     break;
   }

+ 3 - 0
panda/src/egg2pg/eggSaver.cxx

@@ -864,6 +864,9 @@ convert_primitive(const GeomVertexData *vertex_data,
         case TextureStage::M_normal_gloss:
           egg_tex->set_env_type(EggTexture::ET_normal_gloss);
           break;
+        case TextureStage::M_emission:
+          egg_tex->set_env_type(EggTexture::ET_emission);
+          break;
         default:
           break;
         }

+ 3 - 0
panda/src/gobj/textureStage.cxx

@@ -517,6 +517,9 @@ operator << (ostream &out, TextureStage::Mode mode) {
 
   case TextureStage::M_normal_gloss:
     return out << "normal_gloss";
+
+  case TextureStage::M_emission:
+    return out << "emission";
   }
 
   return out << "**invalid Mode(" << (int)mode << ")**";

+ 2 - 0
panda/src/gobj/textureStage.h

@@ -63,6 +63,8 @@ PUBLISHED:
     M_height,       // Rarely used: normal_height  is more efficient.
     M_selector,
     M_normal_gloss,
+
+    M_emission,
   };
 
   enum CombineMode {

+ 17 - 10
panda/src/pgraphnodes/shaderGenerator.cxx

@@ -467,6 +467,9 @@ analyze_renderstate(ShaderKey &key, const RenderState *rs) {
         skip = true;
       }
       break;
+    case TextureStage::M_emission:
+      info._flags = ShaderKey::TF_map_emission;
+      break;
     default:
       break;
     }
@@ -743,6 +746,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
 
   int map_index_glow = -1;
   int map_index_gloss = -1;
+  int map_index_emission = -1;
 
   // Figure out whether we need to calculate any of these variables.
   bool need_world_position = (key._num_clip_planes > 0);
@@ -833,6 +837,9 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
     if (tex._flags & ShaderKey::TF_map_gloss) {
       map_index_gloss = i;
     }
+    if (tex._flags & ShaderKey::TF_map_emission) {
+      map_index_emission = i;
+    }
   }
   if (need_tangents) {
     tangent_freg = alloc_freg();
@@ -1446,17 +1453,17 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) {
     }
     text << "\t // Begin view-space light summation\n";
     if (key._material_flags & Material::F_emission) {
-      if (key._texture_flags & ShaderKey::TF_map_glow) {
-        text << "\t result = attr_material[2] * saturate(2 * (tex" << map_index_glow << ".a - 0.5));\n";
-      } else {
-        text << "\t result = attr_material[2];\n";
-      }
+      text << "\t result = attr_material[2];\n";
+    } else if (key._texture_flags & (ShaderKey::TF_map_glow | ShaderKey::TF_map_emission)) {
+      text << "\t result = float4(1,1,1,0);\n";
     } else {
-      if (key._texture_flags & ShaderKey::TF_map_glow) {
-        text << "\t result = saturate(2 * (tex" << map_index_glow << ".a - 0.5));\n";
-      } else {
-        text << "\t result = float4(0,0,0,0);\n";
-      }
+      text << "\t result = float4(0,0,0,0);\n";
+    }
+    if (key._texture_flags & ShaderKey::TF_map_emission) {
+      text << "\t result.rgb *= tex" << map_index_emission << ".rgb;\n";
+    }
+    if (key._texture_flags & ShaderKey::TF_map_glow) {
+      text << "\t result *= saturate(2 * (tex" << map_index_glow << ".a - 0.5));\n";
     }
     if (key._have_separate_ambient) {
       if (key._material_flags & Material::F_ambient) {

+ 1 - 0
panda/src/pgraphnodes/shaderGenerator.h

@@ -107,6 +107,7 @@ protected:
       TF_map_height   = 0x040,
       TF_map_glow     = 0x080,
       TF_map_gloss    = 0x100,
+      TF_map_emission = 0x001000000,
       TF_uses_color   = 0x200,
       TF_uses_primary_color = 0x400,
       TF_uses_last_saved_result = 0x800,