Jump to content

Emission shader : variable emission strengh


YouGroove
 Share

Recommended Posts

The goal is to have emission strengh able to vary on time like linear, from strong to low , than low to strong. Like some burned wood by flames or some lava effect or Sci Fi.

 

Is there some Guru shader that can tell me if it's possible ?

 

 

Original Diffuse-Normal-Specular-Emission shader code :

 

void main(void)
{
   vec4 outcolor = ex_color;
   vec4 color_specular = texture(texture2,ex_texcoords0) * materialcolorspecular;

   vec3 screencoord = vec3(((gl_FragCoord.x/buffersize.x)-0.5) * 2.0 * (buffersize.x/buffersize.y),((-gl_FragCoord.y/buffersize.y)+0.5) * 2.0,DepthToZPosition( gl_FragCoord.z ));
   screencoord.x *= screencoord.z / camerazoom;
   screencoord.y *= -screencoord.z / camerazoom;   
   vec3 nscreencoord = normalize(screencoord);

   //Modulate blend with diffuse map
   outcolor *= texture(texture0,ex_texcoords0);

   //Normal map
   vec3 normal = ex_normal;
   normal = texture(texture1,ex_texcoords0).xyz * 2.0 - 1.0;
   float ao = normal.z;
   normal = ex_tangent*normal.x + ex_binormal*normal.y + ex_normal*normal.z;    
   normal=normalize(normal);

   //Calculate lighting
   vec4 lighting_diffuse = vec4(0);
   vec4 lighting_specular = vec4(0);
   float attenuation=1.0;
   vec3 lightdir;
   vec3 lightreflection;
   int i;
   float anglecos;
   float diffspotangle;    
   float denom;

   //Blend with selection color if selected
   fragData0 = outcolor;// * (1.0-ex_selectionstate) + ex_selectionstate * (outcolor*0.5+vec4(0.5,0.0,0.0,0.0));
   //fragData0.xyz = normal*0.5+0.5;

#if BFN_ENABLED==1
   //Best-fit normals
   fragData1 = texture(texture15,normalize(vec3(normal.x,-normal.y,normal.z)));
#else
   //Low-res normals
   fragData1 = vec4(normalize(normal)*0.5+0.5,fragData0.a);
#endif
   fragData1.a = color_specular.r * 0.299 + color_specular.g * 0.587 + color_specular.b * 0.114;
   int materialflags=1;
   if (ex_selectionstate>0.0) materialflags += 2;
   fragData2 = vec4(texture(texture4,ex_texcoords0).rgb,materialflags/255.0);
}

Stop toying and make games

Link to comment
Share on other sites

Somthing like this not testet for a sinus wave (not tested);

uniform float currenttime;

..
fragData2 = vec4(texture(texture4,ex_texcoords0).rgb*sin(currenttime*0.001),materialflags/255.0);

 

or like Josh suggests:

 

fragData2 = vec4(texture(texture4,ex_texcoords0).rgb*ex_color.a,materialflags/255.0);

 

Then in your app code send emmision strength by

entity->SetColor(1,1,1,emissionstrength);

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Thanks Shadmar, it worked.

 

The two versions are interesting for different uses like

- regular glowing effect (Sci Fi, burned stuff, lava, radioactive etc ...)

- ability to control manually emissive strenght in Lua like when you activate some button it would become emissive or some Sci Fi panels or similar stuff that would loose emissive and they would be shoot down.

 

I'll try different experiments, than i'll upload it as shader contribution.

Stop toying and make games

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...