mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-01 10:59:23 +00:00
Fix unparsable characters in shader, OpenTK issue 3186
This commit is contained in:
parent
bef7ecd1ed
commit
fb507db838
|
@ -1,57 +1,57 @@
|
||||||
// Copyright (c) 2008 the OpenTK Team. See license.txt for legal bla
|
// Copyright (c) 2008 the OpenTK Team. See license.txt for legal bla
|
||||||
|
|
||||||
// Material uniforms
|
// Material uniforms
|
||||||
uniform sampler2D Material_DiffuseAndHeight;
|
uniform sampler2D Material_DiffuseAndHeight;
|
||||||
uniform sampler2D Material_NormalAndGloss;
|
uniform sampler2D Material_NormalAndGloss;
|
||||||
uniform vec3 Material_ScaleBiasShininess; // x=Scale, y=Bias, z=Shininess
|
uniform vec3 Material_ScaleBiasShininess; // x=Scale, y=Bias, z=Shininess
|
||||||
|
|
||||||
// Light uniforms
|
// Light uniforms
|
||||||
uniform vec3 Light_DiffuseColor;
|
uniform vec3 Light_DiffuseColor;
|
||||||
uniform vec3 Light_SpecularColor;
|
uniform vec3 Light_SpecularColor;
|
||||||
|
|
||||||
// from VS
|
// from VS
|
||||||
varying vec3 VaryingLightVector;
|
varying vec3 VaryingLightVector;
|
||||||
varying vec3 VaryingEyeVector;
|
varying vec3 VaryingEyeVector;
|
||||||
|
|
||||||
vec3 normal;
|
vec3 normal;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 lightVector = normalize( VaryingLightVector );
|
vec3 lightVector = normalize( VaryingLightVector );
|
||||||
vec3 eyeVector = normalize( VaryingEyeVector );
|
vec3 eyeVector = normalize( VaryingEyeVector );
|
||||||
|
|
||||||
// first, find the parallax displacement by reading only the height map
|
// first, find the parallax displacement by reading only the height map
|
||||||
float parallaxOffset = texture2D( Material_DiffuseAndHeight, gl_TexCoord[0].st ).a *
|
float parallaxOffset = texture2D( Material_DiffuseAndHeight, gl_TexCoord[0].st ).a *
|
||||||
Material_ScaleBiasShininess.x - Material_ScaleBiasShininess.y;
|
Material_ScaleBiasShininess.x - Material_ScaleBiasShininess.y;
|
||||||
vec2 newTexCoords = gl_TexCoord[0].st + ( parallaxOffset * eyeVector.xy ); // displace texcoords according to viewer
|
vec2 newTexCoords = gl_TexCoord[0].st + ( parallaxOffset * eyeVector.xy ); // displace texcoords according to viewer
|
||||||
|
|
||||||
// knowing the displacement, read RGB, Normal and Gloss
|
// knowing the displacement, read RGB, Normal and Gloss
|
||||||
vec3 diffuseColor = texture2D( Material_DiffuseAndHeight, newTexCoords.st ).rgb;
|
vec3 diffuseColor = texture2D( Material_DiffuseAndHeight, newTexCoords.st ).rgb;
|
||||||
vec4 temp = texture2D( Material_NormalAndGloss, newTexCoords.st );
|
vec4 temp = texture2D( Material_NormalAndGloss, newTexCoords.st );
|
||||||
|
|
||||||
// build a usable normal vector
|
// build a usable normal vector
|
||||||
normal.xy = temp.ag * 2.0 - 1.0; // swizzle alpha and green to x/y and scale to [-1..+1]
|
normal.xy = temp.ag * 2.0 - 1.0; // swizzle alpha and green to x/y and scale to [-1..+1]
|
||||||
normal.z = sqrt( 1.0 - normal.x*normal.x - normal.y*normal.y ); // z = sqrt(1-x²-y²)
|
normal.z = sqrt( 1.0 - normal.x*normal.x - normal.y*normal.y ); // z = sqrt(1-x^2-y^2)
|
||||||
|
|
||||||
// move other properties to be better readable
|
// move other properties to be better readable
|
||||||
float gloss = temp.r;
|
float gloss = temp.r;
|
||||||
|
|
||||||
// float alpha = temp.b;
|
// float alpha = temp.b;
|
||||||
// if ( alpha < 0.2 ) // optimization: should move this test before reading RGB texture
|
// if ( alpha < 0.2 ) // optimization: should move this test before reading RGB texture
|
||||||
// discard;
|
// discard;
|
||||||
|
|
||||||
// tweaked phong lighting
|
// tweaked phong lighting
|
||||||
float lambert = max( dot( lightVector, normal ), 0.0 );
|
float lambert = max( dot( lightVector, normal ), 0.0 );
|
||||||
|
|
||||||
gl_FragColor = vec4( Light_DiffuseColor * diffuseColor, 1.0 ) *
|
gl_FragColor = vec4( Light_DiffuseColor * diffuseColor, 1.0 ) *
|
||||||
lambert;
|
lambert;
|
||||||
|
|
||||||
if ( lambert > 0.0 )
|
if ( lambert > 0.0 )
|
||||||
{
|
{
|
||||||
float specular = pow(
|
float specular = pow(
|
||||||
clamp( dot( reflect( -lightVector, normal ), eyeVector ), 0.0, 1.0 ),
|
clamp( dot( reflect( -lightVector, normal ), eyeVector ), 0.0, 1.0 ),
|
||||||
Material_ScaleBiasShininess.z );
|
Material_ScaleBiasShininess.z );
|
||||||
|
|
||||||
gl_FragColor += vec4( Light_SpecularColor * diffuseColor, 1.0 ) * ( specular * gloss );
|
gl_FragColor += vec4( Light_SpecularColor * diffuseColor, 1.0 ) * ( specular * gloss );
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue