mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 21:18:32 -05:00
Update model shader example shaders
This commit is contained in:
@@ -28,21 +28,19 @@ in vec2 vs_st;
|
||||
in vec3 vs_normalViewSpace;
|
||||
in vec4 vs_positionCameraSpace;
|
||||
in float vs_screenSpaceDepth;
|
||||
in mat3 TBN;
|
||||
in mat3 vs_TBN;
|
||||
|
||||
uniform float ambientIntensity = 0.2;
|
||||
uniform float diffuseIntensity = 1.0;
|
||||
uniform float specularIntensity = 1.0;
|
||||
|
||||
uniform bool performShading = true;
|
||||
|
||||
uniform bool use_forced_color = false;
|
||||
uniform bool has_texture_diffuse;
|
||||
uniform bool has_texture_normal;
|
||||
uniform bool has_texture_specular;
|
||||
uniform bool has_color_specular;
|
||||
|
||||
uniform bool opacityBlending = false;
|
||||
|
||||
uniform sampler2D texture_diffuse;
|
||||
uniform sampler2D texture_normal;
|
||||
uniform sampler2D texture_specular;
|
||||
@@ -54,22 +52,57 @@ uniform int nLightSources;
|
||||
uniform vec3 lightDirectionsViewSpace[8];
|
||||
uniform float lightIntensities[8];
|
||||
|
||||
uniform float opacity = 1.0;
|
||||
uniform bool performManualDepthTest = false;
|
||||
uniform sampler2D gBufferDepthTexture;
|
||||
|
||||
uniform vec4 viewport;
|
||||
uniform vec2 resolution;
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
frag.depth = vs_screenSpaceDepth;
|
||||
frag.gPosition = vs_positionCameraSpace;
|
||||
frag.gNormal = vec4(vs_normalViewSpace, 0.0);
|
||||
frag.disableLDR2HDR = true;
|
||||
frag.color.a = 1.0;
|
||||
|
||||
if (performManualDepthTest) {
|
||||
// gl_FragCoord.x goes from 0 to resolution.x and gl_FragCoord.y goes from 0 to
|
||||
// resolution.y, need to normalize it
|
||||
vec2 texCoord = gl_FragCoord.xy;
|
||||
texCoord.x = texCoord.x / resolution.x;
|
||||
texCoord.y = texCoord.y / resolution.y;
|
||||
|
||||
// Modify the texCoord based on the Viewport and Resolution. This modification is
|
||||
// necessary in case of side-by-side stereo as we only want to access the part of the
|
||||
// feeding texture that we are currently responsible for. Otherwise we would map the
|
||||
// entire feeding texture into our half of the result texture, leading to a doubling
|
||||
// of the "missing" half. If you don't believe me, load a configuration file with the
|
||||
// side_by_side stereo mode enabled, disable FXAA, and remove this modification.
|
||||
// The same calculation is done in the FXAA shader, the HDR resolving and the
|
||||
// atmosphere shader
|
||||
vec2 st = texCoord;
|
||||
st.x = st.x / (resolution.x / viewport[2]) + (viewport[0] / resolution.x);
|
||||
st.y = st.y / (resolution.y / viewport[3]) + (viewport[1] / resolution.y);
|
||||
|
||||
// Manual depth test
|
||||
float gBufferDepth = denormalizeFloat(texture(gBufferDepthTexture, st).x);
|
||||
if (vs_screenSpaceDepth > gBufferDepth) {
|
||||
frag.color = vec4(0.0);
|
||||
frag.depth = gBufferDepth;
|
||||
return frag;
|
||||
}
|
||||
}
|
||||
|
||||
// Frag color is the normal values
|
||||
if (has_texture_normal) {
|
||||
vec3 normalAlbedo = texture(texture_normal, vs_st).rgb;
|
||||
normalAlbedo = normalize(normalAlbedo * 2.0 - 1.0);
|
||||
frag.color.rgb = normalize(TBN * normalAlbedo);
|
||||
frag.color.rgb = normalize(vs_TBN * normalAlbedo);
|
||||
}
|
||||
else {
|
||||
frag.color.rgb = normalize(vs_normalViewSpace);
|
||||
}
|
||||
frag.color.a = 1.0;
|
||||
frag.gPosition = vs_positionCameraSpace;
|
||||
frag.gNormal = vec4(vs_normalViewSpace, 0.0);
|
||||
frag.disableLDR2HDR = true;
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ out vec2 vs_st;
|
||||
out vec3 vs_normalViewSpace;
|
||||
out float vs_screenSpaceDepth;
|
||||
out vec4 vs_positionCameraSpace;
|
||||
out mat3 TBN;
|
||||
out mat3 vs_TBN;
|
||||
|
||||
uniform mat4 modelViewTransform;
|
||||
uniform mat4 projectionTransform;
|
||||
@@ -52,17 +52,18 @@ void main() {
|
||||
vs_st = in_st;
|
||||
vs_screenSpaceDepth = positionScreenSpace.w;
|
||||
|
||||
vs_normalViewSpace = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_normal));
|
||||
vs_normalViewSpace =
|
||||
normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_normal));
|
||||
|
||||
// TBN matrix for normal mapping
|
||||
vec3 T = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_tangent));
|
||||
vec3 N = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_normal));
|
||||
// TBN matrix for normal mapping
|
||||
vec3 T = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_tangent));
|
||||
vec3 N = normalize(mat3(normalTransform) * (mat3(meshNormalTransform) * in_normal));
|
||||
|
||||
// Re-orthogonalize T with respect to N
|
||||
T = normalize(T - dot(T, N) * N);
|
||||
// Re-orthogonalize T with respect to N
|
||||
T = normalize(T - dot(T, N) * N);
|
||||
|
||||
// Retrieve perpendicular vector B with cross product of T and N
|
||||
vec3 B = normalize(cross(N, T));
|
||||
// Retrieve perpendicular vector B with cross product of T and N
|
||||
vec3 B = normalize(cross(N, T));
|
||||
|
||||
TBN = mat3(T, B, N);
|
||||
vs_TBN = mat3(T, B, N);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user