Add support for specular colors if used

This commit is contained in:
KillzXGaming 2019-06-03 19:00:46 -04:00
parent e14286d871
commit 47cd45b4e0
9 changed files with 33 additions and 13 deletions

Binary file not shown.

View file

@ -112,6 +112,15 @@ namespace Bfres.Structs
protected void RenameAction(object sender, EventArgs args) { Rename(); }
protected void DeleteAction(object sender, EventArgs args) { Delete(); }
public int GetOptionValue(string Option)
{
int value = -1;
if (shaderassign.options.ContainsKey(Option))
int.TryParse(shaderassign.options[Option], out value);
return value;
}
public void Delete()
{
string MappedNames = "";

View file

@ -944,6 +944,7 @@ namespace FirstPlugin
shader.SetVector4("gsys_bake_st0", new Vector4(1, 1, 0, 0));
shader.SetVector4("gsys_bake_st1", new Vector4(1, 1, 0, 0));
shader.SetBoolToInt("UseSpecularColor", mat.GetOptionValue("specular_mask_is_color") == 1);
//Colors
shader.SetVector4("const_color0", new Vector4(1, 1, 1, 1));

View file

@ -79,6 +79,8 @@ uniform float enable_emission;
uniform float cSpecularType;
uniform float cIsEnableNormalMap;
uniform int UseSpecularColor;
// Texture Map Toggles
uniform int HasDiffuse;
uniform int HasNormalMap;
@ -139,7 +141,7 @@ BakedData ShadowMapBaked(sampler2D ShadowMap, sampler2D LightMap, vec2 texCoordB
vec3 CalcBumpedNormal(vec3 normal, sampler2D normalMap, VertexAttributes vert, float texCoordIndex);
float AmbientOcclusionBlend(sampler2D BakeShadowMap, VertexAttributes vert, float ao_density);
vec3 EmissionPass(sampler2D EmissionMap, float emission_intensity, VertexAttributes vert, float texCoordIndex, vec3 emission_color);
vec3 SpecularPass(vec3 I, vec3 normal, int HasSpecularMap, sampler2D SpecularMap, vec3 specular_color, VertexAttributes vert, float texCoordIndex);
vec3 SpecularPass(vec3 I, vec3 normal, int HasSpecularMap, sampler2D SpecularMap, vec3 specular_color, VertexAttributes vert, float texCoordIndex, int UseSpecularColor);
vec3 ReflectionPass(vec3 N, vec3 I, vec4 diffuseMap, float SpecularAmount, float aoBlend, vec3 tintColor, VertexAttributes vert);
float ParseComponent(int Type, vec4 Texture)
@ -269,7 +271,7 @@ void main()
// Render Passes
if (HasEmissionMap == 1 || enable_emission == 1) //Can be without texture map
fragColor.rgb += EmissionPass(EmissionMap, emission_intensity, vert, 0, emission_color);
fragColor.rgb += SpecularPass(I, N, HasSpecularMap, SpecularMap, specular_color, vert, 0);
fragColor.rgb += SpecularPass(I, N, HasSpecularMap, SpecularMap, specular_color, vert, 0, UseSpecularColor);
fragColor.rgb += ReflectionPass(N, I, diffuseMapColor,SpecularAmount, AoPass, tintColor, vert);
fragColor.rgb *= pickingColor.rgb;

View file

@ -90,6 +90,7 @@ uniform float enable_fresnel;
uniform float enable_emission;
uniform float cSpecularType;
uniform int UseSpecularColor;
// Texture Map Toggles
uniform int HasDiffuse;
@ -181,7 +182,7 @@ void main()
float metallic = 0;
float roughness = 1;
float specIntensity = 1;
vec3 specIntensity = vec3(1);
float ao = 1;
if (HasMRA == 1) //Kirby Star Allies PBR map
@ -191,7 +192,7 @@ void main()
metallic = texture(MRA, f_texcoord0).r;
roughness = texture(MRA, f_texcoord0).g;
ao = texture(MRA, f_texcoord0).b;
specIntensity = texture(MRA, f_texcoord0).a;
specIntensity = vec3(texture(MRA, f_texcoord0).a);
}
else if (HasShadowMap == 1)
{
@ -208,7 +209,7 @@ void main()
}
if (HasSpecularMap == 1)
{
specIntensity = texture(SpecularMap, f_texcoord0).r;
specIntensity = texture(SpecularMap, f_texcoord0).rgb;
}
if (renderType == 1) // normals vertexColor
@ -277,7 +278,10 @@ void main()
}
else if (renderType == 13) //Specular
{
fragColor = vec4(vec3(specIntensity), 1);
if (UseSpecularColor == 1)
fragColor = vec4(specIntensity.rgb, 1);
else
fragColor = vec4(vec3(specIntensity.r), 1);
}
else if (renderType == 14) //Shadow
{

View file

@ -23,7 +23,7 @@ uniform int hasTangents;
// Defined in Utility.frag.
float Luminance(vec3 rgb);
vec3 SpecularPass(vec3 I, vec3 normal, int HasSpecularMap, sampler2D SpecularMap, vec3 SpecColor, VertexAttributes vert, float texcoord2)
vec3 SpecularPass(vec3 I, vec3 normal, int HasSpecularMap, sampler2D SpecularMap, vec3 SpecColor, VertexAttributes vert, float texcoord2, int UseSpecularColor)
{
float specBrdf = max(dot(I, normal), 0);
float exponent = 8;
@ -36,14 +36,18 @@ vec3 SpecularPass(vec3 I, vec3 normal, int HasSpecularMap, sampler2D SpecularMap
return 0.1 * SpecColor * pow(specBrdf, exponent);
}
// TODO: Different games use the channels for separate textures.
vec3 specularTex = vec3(1);
vec2 SpecTexCoord = vert.texCoord;
if (texcoord2 == 1)
specularTex = texture(SpecularMap, vert.texCoord2).rrr;
else
specularTex = texture(SpecularMap, vert.texCoord).rrr;
SpecTexCoord = vert.texCoord2;
vec3 result = specularTex * SpecColor * pow(specBrdf, exponent);
vec3 Specular = texture(SpecularMap, SpecTexCoord).rgb;
if (UseSpecularColor == 0)
Specular = texture(SpecularMap, SpecTexCoord).rrr;
// TODO: Different games use the channels for separate textures.
vec3 result = Specular * SpecColor * pow(specBrdf, exponent);
result *= SpecColor.rgb;
float intensity = 0.3;