ParallaxMaping-GLSL
#version 130
uniform vec4 g_vec4ViewCoord;
uniform vec4 g_vec4LightCoord;
uniform mat4 m_mat4ModelInvert;
uniform mat4 g_mat4ModelViewProj;
in vec3 g_vec3Tangent;
in vec3 g_vec3Binormal;
in vec3 g_vec3Normal;
in vec2 g_vec2TexCoord;
in vec3 g_vec3VertexCoord;
out vec2 g_vec2FragTexCoord;
out vec3 g_vec3TangentViewDirection;
out vec3 g_vec3TangentLightDirection;
// @desc: The entry of vertex shader.
void main()
{
// Calculate the view direction and light direction in model space.
vec3 vec3ViewDirection = (m_mat4ModelInvert*g_vec4ViewCoord).xyz - g_vec3VertexCoord;
vec3 vec3LightDirection = (m_mat4ModelInvert*g_vec4LightCoord).xyz - g_vec3VertexCoord;
// Calculate the view direction and light direction in tangent space.
mat3 mat3Tangent = mat3(g_vec3Tangent, g_vec3Binormal, g_vec3Normal);
g_vec3TangentViewDirection = vec3ViewDirection*mat3Tangent;
g_vec3TangentLightDirection = vec3LightDirection*mat3Tangent;
// Pass texture coordinate and calculate the coordinate in clipping space.
g_vec2FragTexCoord = g_vec2TexCoord;
gl_Position = g_mat4ModelViewProj*vec4(g_vec3VertexCoord, 1.0f);
}
#version 130
uniform vec3 g_vec3Irradiance;
uniform vec3 g_vec3Diffuse;
uniform vec3 g_vec3Specular;
uniform float g_fSmoothness;
uniform float g_fScaleGene;
uniform float g_fBiasGene;
uniform sampler2D g_SurfaceMap;
uniform sampler2D g_NormalMap;
uniform sampler2D g_HeightMap;
in vec2 g_vec2FragTexCoord;
in vec3 g_vec3TangentViewDirection;
in vec3 g_vec3TangentLightDirection;
out vec4 g_vec4FragColor;
// @desc: The entry of fragment shader.
void main()
{
// Calculate offset texture coordinate.
vec3 vec3TangentViewDirection = normalize(g_vec3TangentViewDirection);
float fAdjustedHeight = texture2D(g_HeightMap, g_vec2FragTexCoord).x*g_fScaleGene - g_fBiasGene;
vec2 vec2DisplaceTexCoord = g_vec2FragTexCoord + fAdjustedHeight*vec3TangentViewDirection.xy ;
// Calculate diffuse gene.
vec3 vec3TangentLightDirection = normalize(g_vec3TangentLightDirection);
vec3 vec3DisturbNormal = normalize( (texture2D(g_NormalMap, vec2DisplaceTexCoord).xyz - 0.5f)*2.0f );
float fDiffuseGene = max(dot(vec3TangentLightDirection, vec3DisturbNormal), 0.0f);
// Calculate specular gene.
float fSpecularGene = 0.0f;
if (fDiffuseGene > 0.0f)
{
vec3 vec3Reflection = reflect(-vec3TangentLightDirection, vec3DisturbNormal);
fSpecularGene = pow(max(dot(vec3Reflection, vec3TangentViewDirection), 0.0f), g_fSmoothness);
}
// Sampler the texture of surface.
vec4 vec4Surface = texture2D(g_SurfaceMap, vec2DisplaceTexCoord);
// Caluate the exitance of light.
vec3 vec3Exitance = (fDiffuseGene*g_vec3Diffuse*vec4Surface.rgb + fSpecularGene*g_vec3Specular)*g_vec3Irradiance;
g_vec4FragColor = vec4(vec3Exitance, 1.0f);
}
uniform vec4 g_vec4ViewCoord;
uniform vec4 g_vec4LightCoord;
uniform mat4 m_mat4ModelInvert;
uniform mat4 g_mat4ModelViewProj;
in vec3 g_vec3Tangent;
in vec3 g_vec3Binormal;
in vec3 g_vec3Normal;
in vec2 g_vec2TexCoord;
in vec3 g_vec3VertexCoord;
out vec2 g_vec2FragTexCoord;
out vec3 g_vec3TangentViewDirection;
out vec3 g_vec3TangentLightDirection;
// @desc: The entry of vertex shader.
void main()
{
// Calculate the view direction and light direction in model space.
vec3 vec3ViewDirection = (m_mat4ModelInvert*g_vec4ViewCoord).xyz - g_vec3VertexCoord;
vec3 vec3LightDirection = (m_mat4ModelInvert*g_vec4LightCoord).xyz - g_vec3VertexCoord;
// Calculate the view direction and light direction in tangent space.
mat3 mat3Tangent = mat3(g_vec3Tangent, g_vec3Binormal, g_vec3Normal);
g_vec3TangentViewDirection = vec3ViewDirection*mat3Tangent;
g_vec3TangentLightDirection = vec3LightDirection*mat3Tangent;
// Pass texture coordinate and calculate the coordinate in clipping space.
g_vec2FragTexCoord = g_vec2TexCoord;
gl_Position = g_mat4ModelViewProj*vec4(g_vec3VertexCoord, 1.0f);
}
#version 130
uniform vec3 g_vec3Irradiance;
uniform vec3 g_vec3Diffuse;
uniform vec3 g_vec3Specular;
uniform float g_fSmoothness;
uniform float g_fScaleGene;
uniform float g_fBiasGene;
uniform sampler2D g_SurfaceMap;
uniform sampler2D g_NormalMap;
uniform sampler2D g_HeightMap;
in vec2 g_vec2FragTexCoord;
in vec3 g_vec3TangentViewDirection;
in vec3 g_vec3TangentLightDirection;
out vec4 g_vec4FragColor;
// @desc: The entry of fragment shader.
void main()
{
// Calculate offset texture coordinate.
vec3 vec3TangentViewDirection = normalize(g_vec3TangentViewDirection);
float fAdjustedHeight = texture2D(g_HeightMap, g_vec2FragTexCoord).x*g_fScaleGene - g_fBiasGene;
vec2 vec2DisplaceTexCoord = g_vec2FragTexCoord + fAdjustedHeight*vec3TangentViewDirection.xy ;
// Calculate diffuse gene.
vec3 vec3TangentLightDirection = normalize(g_vec3TangentLightDirection);
vec3 vec3DisturbNormal = normalize( (texture2D(g_NormalMap, vec2DisplaceTexCoord).xyz - 0.5f)*2.0f );
float fDiffuseGene = max(dot(vec3TangentLightDirection, vec3DisturbNormal), 0.0f);
// Calculate specular gene.
float fSpecularGene = 0.0f;
if (fDiffuseGene > 0.0f)
{
vec3 vec3Reflection = reflect(-vec3TangentLightDirection, vec3DisturbNormal);
fSpecularGene = pow(max(dot(vec3Reflection, vec3TangentViewDirection), 0.0f), g_fSmoothness);
}
// Sampler the texture of surface.
vec4 vec4Surface = texture2D(g_SurfaceMap, vec2DisplaceTexCoord);
// Caluate the exitance of light.
vec3 vec3Exitance = (fDiffuseGene*g_vec3Diffuse*vec4Surface.rgb + fSpecularGene*g_vec3Specular)*g_vec3Irradiance;
g_vec4FragColor = vec4(vec3Exitance, 1.0f);
}
浙公网安备 33010602011771号