mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2024-11-26 15:45:41 +00:00
Use c++11 raw string literals
This commit is contained in:
parent
3efb055344
commit
2335f3173b
|
@ -4,55 +4,59 @@
|
||||||
|
|
||||||
namespace New3D {
|
namespace New3D {
|
||||||
|
|
||||||
static const char *vertexShaderFog =
|
static const char *vertexShaderFog = R"glsl(
|
||||||
|
|
||||||
"uniform mat4 mvp;\n"
|
uniform mat4 mvp;
|
||||||
|
|
||||||
"void main(void)\n"
|
void main(void)
|
||||||
"{\n"
|
{
|
||||||
"gl_Position = mvp * gl_Vertex;\n"
|
gl_Position = mvp * gl_Vertex;
|
||||||
"}\n";
|
};
|
||||||
|
|
||||||
static const char *fragmentShaderFog =
|
)glsl";
|
||||||
|
|
||||||
"uniform float fogAttenuation;\n"
|
static const char *fragmentShaderFog = R"glsl(
|
||||||
"uniform float fogAmbient;\n"
|
|
||||||
"uniform vec4 fogColour;\n"
|
|
||||||
"uniform vec3 spotFogColor;\n"
|
|
||||||
"uniform vec4 spotEllipse;\n"
|
|
||||||
|
|
||||||
// Spotlight on fog
|
uniform float fogAttenuation;
|
||||||
"float ellipse;\n"
|
uniform float fogAmbient;
|
||||||
"vec2 position, size;\n"
|
uniform vec4 fogColour;
|
||||||
"vec3 lSpotFogColor;\n"
|
uniform vec3 spotFogColor;
|
||||||
|
uniform vec4 spotEllipse;
|
||||||
|
|
||||||
// Scroll fog
|
// Spotlight on fog
|
||||||
"float lfogAttenuation;\n"
|
float ellipse;
|
||||||
"vec3 lFogColor;\n"
|
vec2 position, size;
|
||||||
"vec4 scrollFog;\n"
|
vec3 lSpotFogColor;
|
||||||
|
|
||||||
"void main()\n"
|
// Scroll fog
|
||||||
"{\n"
|
float lfogAttenuation;
|
||||||
|
vec3 lFogColor;
|
||||||
|
vec4 scrollFog;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
// Scroll fog base color
|
// Scroll fog base color
|
||||||
"lFogColor = fogColour.rgb * fogAmbient;\n"
|
lFogColor = fogColour.rgb * fogAmbient;
|
||||||
|
|
||||||
// Spotlight on fog (area)
|
// Spotlight on fog (area)
|
||||||
"position = spotEllipse.xy;\n"
|
position = spotEllipse.xy;
|
||||||
"size = spotEllipse.zw;\n"
|
size = spotEllipse.zw;
|
||||||
"ellipse = length((gl_FragCoord.xy - position) / size);\n"
|
ellipse = length((gl_FragCoord.xy - position) / size);
|
||||||
"ellipse = pow(ellipse, 2.0);\n" // decay rate = square of distance from center
|
ellipse = pow(ellipse, 2.0); // decay rate = square of distance from center
|
||||||
"ellipse = 1.0 - ellipse;\n" // invert
|
ellipse = 1.0 - ellipse; // invert
|
||||||
"ellipse = max(0.0, ellipse);\n" // clamp
|
ellipse = max(0.0, ellipse); // clamp
|
||||||
|
|
||||||
// Spotlight on fog (color)
|
// Spotlight on fog (color)
|
||||||
"lSpotFogColor = mix(spotFogColor * ellipse * fogColour.rgb, vec3(0.0), fogAttenuation);\n"
|
lSpotFogColor = mix(spotFogColor * ellipse * fogColour.rgb, vec3(0.0), fogAttenuation);
|
||||||
|
|
||||||
// Scroll fog density
|
// Scroll fog density
|
||||||
"scrollFog = vec4(lFogColor + lSpotFogColor, fogColour.a);\n"
|
scrollFog = vec4(lFogColor + lSpotFogColor, fogColour.a);
|
||||||
|
|
||||||
// Final Color
|
// Final Color
|
||||||
"gl_FragColor = scrollFog;\n"
|
gl_FragColor = scrollFog;
|
||||||
"}\n";
|
};
|
||||||
|
|
||||||
|
)glsl";
|
||||||
|
|
||||||
|
|
||||||
R3DScrollFog::R3DScrollFog()
|
R3DScrollFog::R3DScrollFog()
|
||||||
|
|
|
@ -3,165 +3,167 @@
|
||||||
|
|
||||||
namespace New3D {
|
namespace New3D {
|
||||||
|
|
||||||
static const char *vertexShaderR3D =
|
static const char *vertexShaderR3D = R"glsl(
|
||||||
|
|
||||||
// uniforms
|
// uniforms
|
||||||
"uniform float fogIntensity;\n"
|
uniform float fogIntensity;
|
||||||
"uniform float fogDensity;\n"
|
uniform float fogDensity;
|
||||||
"uniform float fogStart;\n"
|
uniform float fogStart;
|
||||||
|
|
||||||
//outputs to fragment shader
|
//outputs to fragment shader
|
||||||
"varying float fsFogFactor;\n"
|
varying float fsFogFactor;
|
||||||
"varying vec3 fsViewVertex;\n"
|
varying vec3 fsViewVertex;
|
||||||
"varying vec3 fsViewNormal;\n" // per vertex normal vector
|
varying vec3 fsViewNormal; // per vertex normal vector
|
||||||
"varying vec4 fsColor;\n"
|
varying vec4 fsColor;
|
||||||
|
|
||||||
"void main(void)\n"
|
void main(void)
|
||||||
"{\n"
|
{
|
||||||
"fsViewVertex = vec3(gl_ModelViewMatrix * gl_Vertex);\n"
|
fsViewVertex = vec3(gl_ModelViewMatrix * gl_Vertex);
|
||||||
"fsViewNormal = normalize(gl_NormalMatrix *gl_Normal);\n"
|
fsViewNormal = normalize(gl_NormalMatrix * gl_Normal);
|
||||||
"float z = length(fsViewVertex);\n"
|
float z = length(fsViewVertex);
|
||||||
"fsFogFactor = fogIntensity * clamp(fogStart + z * fogDensity, 0.0, 1.0);\n"
|
fsFogFactor = fogIntensity * clamp(fogStart + z * fogDensity, 0.0, 1.0);
|
||||||
|
|
||||||
"fsColor = gl_Color;\n"
|
fsColor = gl_Color;
|
||||||
"gl_TexCoord[0] = gl_MultiTexCoord0;\n"
|
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||||
"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||||
"}\n";
|
}
|
||||||
|
)glsl";
|
||||||
|
|
||||||
static const char *fragmentShaderR3D =
|
static const char *fragmentShaderR3D = R"glsl(
|
||||||
|
|
||||||
"uniform sampler2D tex1;\n" // base tex
|
uniform sampler2D tex1; // base tex
|
||||||
"uniform sampler2D tex2;\n" // micro tex (optional)
|
uniform sampler2D tex2; // micro tex (optional)
|
||||||
|
|
||||||
"uniform bool textureEnabled;\n"
|
uniform bool textureEnabled;
|
||||||
"uniform bool microTexture;\n"
|
uniform bool microTexture;
|
||||||
"uniform float microTextureScale;\n"
|
uniform float microTextureScale;
|
||||||
"uniform vec2 baseTexSize;\n"
|
uniform vec2 baseTexSize;
|
||||||
"uniform bool textureInverted;\n"
|
uniform bool textureInverted;
|
||||||
"uniform bool alphaTest;\n"
|
uniform bool alphaTest;
|
||||||
"uniform bool textureAlpha;\n"
|
uniform bool textureAlpha;
|
||||||
"uniform vec3 fogColour;\n"
|
uniform vec3 fogColour;
|
||||||
"uniform vec4 spotEllipse;\n" // spotlight ellipse position: .x=X position (screen coordinates), .y=Y position, .z=half-width, .w=half-height)
|
uniform vec4 spotEllipse; // spotlight ellipse position: .x=X position (screen coordinates), .y=Y position, .z=half-width, .w=half-height)
|
||||||
"uniform vec2 spotRange;\n" // spotlight Z range: .x=start (viewspace coordinates), .y=limit
|
uniform vec2 spotRange; // spotlight Z range: .x=start (viewspace coordinates), .y=limit
|
||||||
"uniform vec3 spotColor;\n" // spotlight RGB color
|
uniform vec3 spotColor; // spotlight RGB color
|
||||||
"uniform vec3 spotFogColor;\n" // spotlight RGB color on fog
|
uniform vec3 spotFogColor; // spotlight RGB color on fog
|
||||||
"uniform vec3 lighting[2];\n" // lighting state (lighting[0] = sun direction, lighting[1].x,y = diffuse, ambient intensities from 0-1.0)
|
uniform vec3 lighting[2]; // lighting state (lighting[0] = sun direction, lighting[1].x,y = diffuse, ambient intensities from 0-1.0)
|
||||||
"uniform bool lightEnable;\n" // lighting enabled (1.0) or luminous (0.0), drawn at full intensity
|
uniform bool lightEnable; // lighting enabled (1.0) or luminous (0.0), drawn at full intensity
|
||||||
"uniform float specularCoefficient;\n" // specular coefficient
|
uniform float specularCoefficient;// specular coefficient
|
||||||
"uniform float shininess;\n" // specular shininess
|
uniform float shininess; // specular shininess
|
||||||
"uniform float fogAttenuation;\n"
|
uniform float fogAttenuation;
|
||||||
"uniform float fogAmbient;\n"
|
uniform float fogAmbient;
|
||||||
|
|
||||||
//interpolated inputs from vertex shader
|
//interpolated inputs from vertex shader
|
||||||
"varying float fsFogFactor;\n"
|
varying float fsFogFactor;
|
||||||
"varying vec3 fsViewVertex;\n"
|
varying vec3 fsViewVertex;
|
||||||
"varying vec3 fsViewNormal;\n" // per vertex normal vector
|
varying vec3 fsViewNormal; // per vertex normal vector
|
||||||
"varying vec4 fsColor;\n"
|
varying vec4 fsColor;
|
||||||
|
|
||||||
"vec4 GetTextureValue()\n"
|
vec4 GetTextureValue()
|
||||||
"{\n"
|
{
|
||||||
"vec4 tex1Data = texture2D( tex1, gl_TexCoord[0].st);\n"
|
vec4 tex1Data = texture2D( tex1, gl_TexCoord[0].st);
|
||||||
|
|
||||||
"if(textureInverted) {\n"
|
if(textureInverted) {
|
||||||
"tex1Data.rgb = vec3(1.0) - vec3(tex1Data.rgb);\n"
|
tex1Data.rgb = vec3(1.0) - vec3(tex1Data.rgb);
|
||||||
"}\n"
|
}
|
||||||
|
|
||||||
"if (microTexture) {\n"
|
if (microTexture) {
|
||||||
"vec2 scale = baseTexSize/256.0;\n"
|
vec2 scale = baseTexSize/256.0;
|
||||||
"vec4 tex2Data = texture2D( tex2, gl_TexCoord[0].st * scale * microTextureScale);\n"
|
vec4 tex2Data = texture2D( tex2, gl_TexCoord[0].st * scale * microTextureScale);
|
||||||
"tex1Data = (tex1Data+tex2Data)/2.0;\n"
|
tex1Data = (tex1Data+tex2Data)/2.0;
|
||||||
"}\n"
|
}
|
||||||
|
|
||||||
"if (alphaTest) {\n"
|
if (alphaTest) {
|
||||||
"if (tex1Data.a < (8.0/16.0)) {\n"
|
if (tex1Data.a < (8.0/16.0)) {
|
||||||
"discard;\n"
|
discard;
|
||||||
"}\n"
|
}
|
||||||
"}\n"
|
}
|
||||||
|
|
||||||
"if (textureAlpha == false) {\n"
|
if (textureAlpha == false) {
|
||||||
"tex1Data.a = 1.0;\n"
|
tex1Data.a = 1.0;
|
||||||
"}\n"
|
}
|
||||||
|
|
||||||
"return tex1Data;\n"
|
return tex1Data;
|
||||||
"}"
|
}
|
||||||
|
|
||||||
"void main()\n"
|
void main()
|
||||||
"{\n"
|
{
|
||||||
"vec4 tex1Data;\n"
|
vec4 tex1Data;
|
||||||
"vec4 colData;\n"
|
vec4 colData;
|
||||||
"vec4 finalData;\n"
|
vec4 finalData;
|
||||||
"vec4 fogData;\n"
|
vec4 fogData;
|
||||||
|
|
||||||
"fogData = vec4(fogColour.rgb * fogAmbient, fsFogFactor);\n"
|
fogData = vec4(fogColour.rgb * fogAmbient, fsFogFactor);
|
||||||
"tex1Data = vec4(1.0, 1.0, 1.0, 1.0);\n"
|
tex1Data = vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
|
|
||||||
"if(textureEnabled) {\n"
|
if(textureEnabled) {
|
||||||
"tex1Data = GetTextureValue();\n"
|
tex1Data = GetTextureValue();
|
||||||
"}\n"
|
}
|
||||||
|
|
||||||
"colData = fsColor;\n"
|
colData = fsColor;
|
||||||
"finalData = tex1Data * colData;\n"
|
finalData = tex1Data * colData;
|
||||||
|
|
||||||
"if (finalData.a < (1.0/16.0)) {\n" // basically chuck out any totally transparent pixels value = 1/16 the smallest transparency level h/w supports
|
if (finalData.a < (1.0/16.0)) { // basically chuck out any totally transparent pixels value = 1/16 the smallest transparency level h/w supports
|
||||||
"discard;\n"
|
discard;
|
||||||
"}\n"
|
}
|
||||||
|
|
||||||
"float ellipse;\n"
|
float ellipse;
|
||||||
"ellipse = length((gl_FragCoord.xy - spotEllipse.xy) / spotEllipse.zw);\n"
|
ellipse = length((gl_FragCoord.xy - spotEllipse.xy) / spotEllipse.zw);
|
||||||
"ellipse = pow(ellipse, 2.0);\n" // decay rate = square of distance from center
|
ellipse = pow(ellipse, 2.0); // decay rate = square of distance from center
|
||||||
"ellipse = 1.0 - ellipse;\n" // invert
|
ellipse = 1.0 - ellipse; // invert
|
||||||
"ellipse = max(0.0, ellipse);\n" // clamp
|
ellipse = max(0.0, ellipse); // clamp
|
||||||
|
|
||||||
"if (lightEnable) {\n"
|
if (lightEnable) {
|
||||||
"vec3 lightIntensity;\n"
|
vec3 lightIntensity;
|
||||||
"vec3 sunVector;\n" // sun lighting vector (as reflecting away from vertex)
|
vec3 sunVector; // sun lighting vector (as reflecting away from vertex)
|
||||||
"float sunFactor;\n" // sun light projection along vertex normal (0.0 to 1.0)
|
float sunFactor; // sun light projection along vertex normal (0.0 to 1.0)
|
||||||
|
|
||||||
// Sun angle
|
// Sun angle
|
||||||
"sunVector = lighting[0];\n"
|
sunVector = lighting[0];
|
||||||
|
|
||||||
// Compute diffuse factor for sunlight
|
// Compute diffuse factor for sunlight
|
||||||
"sunFactor = max(dot(sunVector, fsViewNormal), 0.0);\n"
|
sunFactor = max(dot(sunVector, fsViewNormal), 0.0);
|
||||||
|
|
||||||
// Total light intensity: sum of all components
|
// Total light intensity: sum of all components
|
||||||
"lightIntensity = vec3(sunFactor*lighting[1].x + min(lighting[1].y,0.75));\n" // diffuse + ambient (clamped to max 0.75)
|
lightIntensity = vec3(sunFactor*lighting[1].x + min(lighting[1].y,0.75)); // diffuse + ambient (clamped to max 0.75)
|
||||||
|
|
||||||
"lightIntensity = clamp(lightIntensity,0.0,1.0);\n"
|
lightIntensity = clamp(lightIntensity,0.0,1.0);
|
||||||
|
|
||||||
// Compute spotlight and apply lighting
|
// Compute spotlight and apply lighting
|
||||||
"float enable, range, d;\n"
|
float enable, range, d;
|
||||||
"float inv_r = 1.0 / spotEllipse.z;\n" // slope of decay function
|
float inv_r = 1.0 / spotEllipse.z; // slope of decay function
|
||||||
|
|
||||||
"d = spotRange.x + spotRange.y + fsViewVertex.z;\n"
|
d = spotRange.x + spotRange.y + fsViewVertex.z;
|
||||||
"enable = step(spotRange.x + min(spotRange.y, 0.0), -fsViewVertex.z);\n"
|
enable = step(spotRange.x + min(spotRange.y, 0.0), -fsViewVertex.z);
|
||||||
|
|
||||||
// inverse-linear falloff
|
// inverse-linear falloff
|
||||||
// Reference: https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/
|
// Reference: https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/
|
||||||
// y = 1 / (d/r + 1)^2
|
// y = 1 / (d/r + 1)^2
|
||||||
"range = 1.0 / pow(min(0.0, d * inv_r) - 1.0, 2.0);\n"
|
range = 1.0 / pow(min(0.0, d * inv_r) - 1.0, 2.0);
|
||||||
"range = clamp(range, 0.0, 1.0);\n"
|
range = clamp(range, 0.0, 1.0);
|
||||||
"range *= enable;\n"
|
range *= enable;
|
||||||
|
|
||||||
"float lobeEffect = range * ellipse;\n"
|
float lobeEffect = range * ellipse;
|
||||||
|
|
||||||
"lightIntensity.rgb += spotColor*lobeEffect;\n"
|
lightIntensity.rgb += spotColor*lobeEffect;
|
||||||
|
|
||||||
"finalData.rgb *= lightIntensity;\n"
|
finalData.rgb *= lightIntensity;
|
||||||
|
|
||||||
"if (sunFactor > 0.0 && specularCoefficient > 0.0) {\n"
|
if (sunFactor > 0.0 && specularCoefficient > 0.0) {
|
||||||
"float nDotL = max(dot(fsViewNormal,sunVector),0.0);\n"
|
float nDotL = max(dot(fsViewNormal,sunVector),0.0);
|
||||||
"finalData.rgb += vec3(specularCoefficient * pow(nDotL,shininess));\n"
|
finalData.rgb += vec3(specularCoefficient * pow(nDotL,shininess));
|
||||||
"}\n"
|
}
|
||||||
"}\n"
|
}
|
||||||
|
|
||||||
// Spotlight on fog
|
// Spotlight on fog
|
||||||
"vec3 lSpotFogColor = spotFogColor * ellipse * fogColour.rgb;\n"
|
vec3 lSpotFogColor = spotFogColor * ellipse * fogColour.rgb;
|
||||||
|
|
||||||
// Fog & spotlight applied
|
// Fog & spotlight applied
|
||||||
"finalData.rgb = mix(finalData.rgb, lSpotFogColor * fogAttenuation + fogData.rgb, fogData.a);\n"
|
finalData.rgb = mix(finalData.rgb, lSpotFogColor * fogAttenuation + fogData.rgb, fogData.a);
|
||||||
|
|
||||||
"gl_FragColor = finalData;\n"
|
gl_FragColor = finalData;
|
||||||
"}\n";
|
}
|
||||||
|
)glsl";
|
||||||
|
|
||||||
R3DShader::R3DShader()
|
R3DShader::R3DShader()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue