Use specularmap as glossiness map.
This commit is contained in:
parent
cafc07680a
commit
79c6424703
@ -1,6 +1,9 @@
|
|||||||
|
uniform sampler2D tex;
|
||||||
|
|
||||||
#if __VERSION__ >= 130
|
#if __VERSION__ >= 130
|
||||||
in vec3 nor;
|
in vec3 nor;
|
||||||
out vec2 EncodedNormal;
|
in vec2 uv;
|
||||||
|
out vec3 EncodedNormal;
|
||||||
#else
|
#else
|
||||||
varying vec3 nor;
|
varying vec3 nor;
|
||||||
#define EncodedNormal gl_FragColor.xy
|
#define EncodedNormal gl_FragColor.xy
|
||||||
@ -10,5 +13,7 @@ vec2 EncodeNormal(vec3 n);
|
|||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
EncodedNormal = 0.5 * EncodeNormal(normalize(nor)) + 0.5;
|
vec4 col = texture(tex, uv);
|
||||||
|
EncodedNormal.xy = 0.5 * EncodeNormal(normalize(nor)) + 0.5;
|
||||||
|
EncodedNormal.z = exp2(10. * (1. - col.a) + 1.);
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,6 @@ vec3 getLightFactor(float specMapValue);
|
|||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
vec4 color = texture(Albedo, uv);
|
vec4 color = texture(Albedo, uv);
|
||||||
vec3 LightFactor = getLightFactor(1. - color.a);
|
vec3 LightFactor = getLightFactor(1.);
|
||||||
FragColor = vec4(color.xyz * LightFactor, 1.);
|
FragColor = vec4(color.xyz * LightFactor, 1.);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ uniform sampler2D tex;
|
|||||||
#if __VERSION__ >= 130
|
#if __VERSION__ >= 130
|
||||||
in vec3 nor;
|
in vec3 nor;
|
||||||
in vec2 uv;
|
in vec2 uv;
|
||||||
out vec2 EncodedNormal;
|
out vec3 EncodedNormal;
|
||||||
#else
|
#else
|
||||||
varying vec3 nor;
|
varying vec3 nor;
|
||||||
varying vec2 uv;
|
varying vec2 uv;
|
||||||
@ -16,6 +16,7 @@ void main() {
|
|||||||
vec4 col = texture(tex, uv);
|
vec4 col = texture(tex, uv);
|
||||||
if (col.a < 0.5)
|
if (col.a < 0.5)
|
||||||
discard;
|
discard;
|
||||||
EncodedNormal = 0.5 * EncodeNormal(normalize(nor)) + 0.5;
|
EncodedNormal.xy = 0.5 * EncodeNormal(normalize(nor)) + 0.5;
|
||||||
|
EncodedNormal.z = 1.;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ void main()
|
|||||||
vec2 texc = gl_FragCoord.xy / screen;
|
vec2 texc = gl_FragCoord.xy / screen;
|
||||||
float z = texture(dtex, texc).x;
|
float z = texture(dtex, texc).x;
|
||||||
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, texc).xy - 1.));
|
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, texc).xy - 1.));
|
||||||
//float roughness = texture(ntex, texc).z;
|
float roughness = texture(ntex, texc).z;
|
||||||
|
|
||||||
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
|
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
|
||||||
xpos = invproj * xpos;
|
xpos = invproj * xpos;
|
||||||
@ -41,7 +41,8 @@ void main()
|
|||||||
|
|
||||||
float NdotL = max(0., dot(norm, L));
|
float NdotL = max(0., dot(norm, L));
|
||||||
float NdotH = max(0., dot(norm, H));
|
float NdotH = max(0., dot(norm, H));
|
||||||
|
float normalisationFactor = (roughness + 2.) / 8.;
|
||||||
|
|
||||||
Diffuse = vec4(NdotL * light_col * att, 1.);
|
Diffuse = vec4(NdotL * light_col * att, 1.);
|
||||||
Specular = vec4(pow(NdotH, spec) * light_col * NdotL * spec_att, 1.);
|
Specular = vec4(pow(NdotH, roughness) * light_col * NdotL * spec_att * normalisationFactor, 1.);
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
|
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
|
||||||
|
float roughness = texture(ntex, uv).z;
|
||||||
vec3 eyedir = -normalize(xpos.xyz);
|
vec3 eyedir = -normalize(xpos.xyz);
|
||||||
|
|
||||||
// Normalized on the cpu
|
// Normalized on the cpu
|
||||||
@ -46,7 +47,8 @@ void main() {
|
|||||||
float NdotL = max(0., dot(norm, L));
|
float NdotL = max(0., dot(norm, L));
|
||||||
float NdotH = max(0., dot(norm, H));
|
float NdotH = max(0., dot(norm, H));
|
||||||
|
|
||||||
float Specular = pow(NdotH, 200) * NdotL;
|
float normalisationFactor = (roughness + 2.) / 8.;
|
||||||
|
float Specular = pow(NdotH, roughness) * NdotL * normalisationFactor;
|
||||||
|
|
||||||
vec3 outcol = NdotL * col;
|
vec3 outcol = NdotL * col;
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ void main() {
|
|||||||
xpos.xyz /= xpos.w;
|
xpos.xyz /= xpos.w;
|
||||||
|
|
||||||
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
|
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
|
||||||
|
float roughness =texture(ntex, uv).z;
|
||||||
vec3 eyedir = -normalize(xpos.xyz);
|
vec3 eyedir = -normalize(xpos.xyz);
|
||||||
|
|
||||||
// Normalized on the cpu
|
// Normalized on the cpu
|
||||||
@ -74,7 +75,9 @@ void main() {
|
|||||||
float NdotL = max(0., dot(norm, L));
|
float NdotL = max(0., dot(norm, L));
|
||||||
float NdotH = max(0., dot(norm, H));
|
float NdotH = max(0., dot(norm, H));
|
||||||
|
|
||||||
float Specular = pow(NdotH, 200) * NdotL;
|
float normalisationFactor = (roughness + 2.) / 8.;
|
||||||
|
float Specular = pow(NdotH, roughness) * NdotL * normalisationFactor;
|
||||||
|
|
||||||
|
|
||||||
vec3 outcol = NdotL * col;
|
vec3 outcol = NdotL * col;
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ RTT::RTT()
|
|||||||
RenderTargetTextures[RTT_TMP2] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT);
|
RenderTargetTextures[RTT_TMP2] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT);
|
||||||
RenderTargetTextures[RTT_TMP3] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT);
|
RenderTargetTextures[RTT_TMP3] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT);
|
||||||
RenderTargetTextures[RTT_TMP4] = generateRTT(res, GL_R16F, GL_RED, GL_FLOAT);
|
RenderTargetTextures[RTT_TMP4] = generateRTT(res, GL_R16F, GL_RED, GL_FLOAT);
|
||||||
RenderTargetTextures[RTT_NORMAL_AND_DEPTH] = generateRTT(res, GL_RG16F, GL_RG, GL_FLOAT);
|
RenderTargetTextures[RTT_NORMAL_AND_DEPTH] = generateRTT(res, GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||||
RenderTargetTextures[RTT_COLOR] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT);
|
RenderTargetTextures[RTT_COLOR] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT);
|
||||||
RenderTargetTextures[RTT_MLAA_COLORS] = generateRTT(res, GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE);
|
RenderTargetTextures[RTT_MLAA_COLORS] = generateRTT(res, GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE);
|
||||||
RenderTargetTextures[RTT_LOG_LUMINANCE] = generateRTT(res, GL_R16F, GL_RED, GL_FLOAT);
|
RenderTargetTextures[RTT_LOG_LUMINANCE] = generateRTT(res, GL_R16F, GL_RED, GL_FLOAT);
|
||||||
|
@ -395,8 +395,10 @@ namespace MeshShader
|
|||||||
GLuint ObjectPass1Shader::Program;
|
GLuint ObjectPass1Shader::Program;
|
||||||
GLuint ObjectPass1Shader::attrib_position;
|
GLuint ObjectPass1Shader::attrib_position;
|
||||||
GLuint ObjectPass1Shader::attrib_normal;
|
GLuint ObjectPass1Shader::attrib_normal;
|
||||||
|
GLuint ObjectPass1Shader::attrib_texcoord;
|
||||||
GLuint ObjectPass1Shader::uniform_MVP;
|
GLuint ObjectPass1Shader::uniform_MVP;
|
||||||
GLuint ObjectPass1Shader::uniform_TIMV;
|
GLuint ObjectPass1Shader::uniform_TIMV;
|
||||||
|
GLuint ObjectPass1Shader::uniform_tex;
|
||||||
|
|
||||||
void ObjectPass1Shader::init()
|
void ObjectPass1Shader::init()
|
||||||
{
|
{
|
||||||
@ -406,14 +408,17 @@ namespace MeshShader
|
|||||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass1.frag").c_str());
|
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass1.frag").c_str());
|
||||||
attrib_position = glGetAttribLocation(Program, "Position");
|
attrib_position = glGetAttribLocation(Program, "Position");
|
||||||
attrib_normal = glGetAttribLocation(Program, "Normal");
|
attrib_normal = glGetAttribLocation(Program, "Normal");
|
||||||
|
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
|
||||||
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
|
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
|
||||||
uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView");
|
uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView");
|
||||||
|
uniform_tex = glGetUniformLocation(Program, "tex");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView)
|
void ObjectPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_tex)
|
||||||
{
|
{
|
||||||
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
|
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
|
||||||
glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer());
|
glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer());
|
||||||
|
glUniform1i(uniform_tex, TU_tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint ObjectRefPass1Shader::Program;
|
GLuint ObjectRefPass1Shader::Program;
|
||||||
|
@ -37,11 +37,11 @@ class ObjectPass1Shader
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static GLuint Program;
|
static GLuint Program;
|
||||||
static GLuint attrib_position, attrib_normal;
|
static GLuint attrib_position, attrib_texcoord, attrib_normal;
|
||||||
static GLuint uniform_MVP, uniform_TIMV;
|
static GLuint uniform_MVP, uniform_TIMV, uniform_tex;
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
|
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_tex);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ObjectRefPass1Shader
|
class ObjectRefPass1Shader
|
||||||
|
@ -225,7 +225,8 @@ void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjecti
|
|||||||
GLenum itype = mesh.IndexType;
|
GLenum itype = mesh.IndexType;
|
||||||
size_t count = mesh.IndexCount;
|
size_t count = mesh.IndexCount;
|
||||||
|
|
||||||
MeshShader::ObjectPass1Shader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView);
|
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||||
|
MeshShader::ObjectPass1Shader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, 0);
|
||||||
|
|
||||||
assert(mesh.vao_first_pass);
|
assert(mesh.vao_first_pass);
|
||||||
glBindVertexArray(mesh.vao_first_pass);
|
glBindVertexArray(mesh.vao_first_pass);
|
||||||
@ -743,7 +744,7 @@ void initvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedM
|
|||||||
{
|
{
|
||||||
case FPSM_DEFAULT:
|
case FPSM_DEFAULT:
|
||||||
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||||
MeshShader::ObjectPass1Shader::attrib_position, -1, -1, MeshShader::ObjectPass1Shader::attrib_normal, -1, -1, -1, mesh.Stride);
|
MeshShader::ObjectPass1Shader::attrib_position, MeshShader::ObjectPass1Shader::attrib_texcoord, -1, MeshShader::ObjectPass1Shader::attrib_normal, -1, -1, -1, mesh.Stride);
|
||||||
mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride);
|
mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride);
|
||||||
break;
|
break;
|
||||||
case FPSM_ALPHA_REF_TEXTURE:
|
case FPSM_ALPHA_REF_TEXTURE:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user