Removed use of 'R' raw string literals as CS 2012 doesn't support them.
This commit is contained in:
parent
5a23299634
commit
ba58cff815
@ -90,86 +90,86 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
QSharedPointer<QGLShaderProgram> shader(new QGLShaderProgram);
|
QSharedPointer<QGLShaderProgram> shader(new QGLShaderProgram);
|
||||||
|
|
||||||
if (!shader->addShaderFromSourceCode(QGLShader::Vertex, R"(
|
if (!shader->addShaderFromSourceCode(QGLShader::Vertex,
|
||||||
#version 140
|
"#version 140\n"
|
||||||
|
|
||||||
in vec4 position; // This will be the position of the vertex in model-space
|
"in vec4 position; // This will be the position of the vertex in model-space\n"
|
||||||
in vec4 normal; // The normal data may not have been set
|
"in vec4 normal; // The normal data may not have been set\n"
|
||||||
in ivec2 material;
|
"in ivec2 material;\n"
|
||||||
|
|
||||||
uniform mat4 cameraToClipMatrix;
|
"uniform mat4 cameraToClipMatrix;\n"
|
||||||
uniform mat4 worldToCameraMatrix;
|
"uniform mat4 worldToCameraMatrix;\n"
|
||||||
uniform mat4 modelToWorldMatrix;
|
"uniform mat4 modelToWorldMatrix;\n"
|
||||||
|
|
||||||
out vec4 worldPosition; //This is being passed to the fragment shader to calculate the normals
|
"out vec4 worldPosition; //This is being passed to the fragment shader to calculate the normals\n"
|
||||||
out vec3 normalFromVS;
|
"out vec3 normalFromVS;\n"
|
||||||
flat out ivec2 materialFromVS;
|
"flat out ivec2 materialFromVS;\n"
|
||||||
|
|
||||||
void main()
|
"void main()\n"
|
||||||
{
|
"{\n"
|
||||||
// Compute the usual OpenGL transformation to clip space.
|
" // Compute the usual OpenGL transformation to clip space.\n"
|
||||||
gl_Position = cameraToClipMatrix * worldToCameraMatrix * modelToWorldMatrix * position;
|
" gl_Position = cameraToClipMatrix * worldToCameraMatrix * modelToWorldMatrix * position;\n"
|
||||||
|
|
||||||
// This example is demonstrating the marching cubes mesh, which does have per-vertex normals. We can
|
" // This example is demonstrating the marching cubes mesh, which does have per-vertex normals. We can \n"
|
||||||
// just pass them through, though real code might want to deal with transforming normals appropriatly.
|
" // just pass them through, though real code might want to deal with transforming normals appropriatly.\n"
|
||||||
normalFromVS = normal.xyz;
|
" normalFromVS = normal.xyz;\n"
|
||||||
|
|
||||||
// Nothing special here, we just pass the material through to the fragment shader.
|
" // Nothing special here, we just pass the material through to the fragment shader.\n"
|
||||||
materialFromVS = material;
|
" materialFromVS = material;\n"
|
||||||
}
|
"}\n"
|
||||||
)"))
|
))
|
||||||
{
|
{
|
||||||
std::cerr << shader->log().toStdString() << std::endl;
|
std::cerr << shader->log().toStdString() << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shader->addShaderFromSourceCode(QGLShader::Fragment, R"(
|
if (!shader->addShaderFromSourceCode(QGLShader::Fragment,
|
||||||
#version 130
|
"#version 130\n"
|
||||||
|
|
||||||
in vec4 worldPosition; //Passed in from the vertex shader
|
"in vec4 worldPosition; //Passed in from the vertex shader\n"
|
||||||
in vec3 normalFromVS;
|
"in vec3 normalFromVS;\n"
|
||||||
flat in ivec2 materialFromVS;
|
"flat in ivec2 materialFromVS;\n"
|
||||||
|
|
||||||
out vec4 outputColor;
|
"out vec4 outputColor;\n"
|
||||||
|
|
||||||
void main()
|
"void main()\n"
|
||||||
{
|
"{\n"
|
||||||
// The first byte of our voxel data is the material.
|
" // The first byte of our voxel data is the material.\n"
|
||||||
// We use this to decide how to color the fragment.
|
" // We use this to decide how to color the fragment.\n"
|
||||||
vec4 surfaceColor;
|
" vec4 surfaceColor;\n"
|
||||||
switch(materialFromVS.x)
|
" switch(materialFromVS.x)\n"
|
||||||
{
|
" {\n"
|
||||||
case 1:
|
" case 1:\n"
|
||||||
surfaceColor = vec4(1.0, 0.0, 0.0, 1.0);
|
" surfaceColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
|
||||||
break;
|
" break;\n"
|
||||||
case 2:
|
" case 2:\n"
|
||||||
surfaceColor = vec4(0.0, 1.0, 0.0, 1.0);
|
" surfaceColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
|
||||||
break;
|
" break;\n"
|
||||||
case 3:
|
" case 3:\n"
|
||||||
surfaceColor = vec4(0.0, 0.0, 1.0, 1.0);
|
" surfaceColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
|
||||||
break;
|
" break;\n"
|
||||||
case 4:
|
" case 4:\n"
|
||||||
surfaceColor = vec4(1.0, 1.0, 0.0, 1.0);
|
" surfaceColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
|
||||||
break;
|
" break;\n"
|
||||||
case 5:
|
" case 5:\n"
|
||||||
surfaceColor = vec4(1.0, 0.0, 1.0, 1.0);
|
" surfaceColor = vec4(1.0, 0.0, 1.0, 1.0);\n"
|
||||||
break;
|
" break;\n"
|
||||||
default:
|
" default:\n"
|
||||||
surfaceColor = vec4(1.0, 1.0, 1.0, 1.0);
|
" surfaceColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
|
||||||
break;
|
" break;\n"
|
||||||
}
|
" }\n"
|
||||||
|
|
||||||
// Quick and dirty lighting, obviously a real implementation
|
" // Quick and dirty lighting, obviously a real implementation\n"
|
||||||
// should pass light properties as shader parameters, etc.
|
" // should pass light properties as shader parameters, etc.\n"
|
||||||
vec3 lightDir = vec3(0.0, 0.0, 1.0);
|
" vec3 lightDir = vec3(0.0, 0.0, 1.0);\n"
|
||||||
float diffuse = clamp(dot(lightDir, normalFromVS), 0.0, 1.0);
|
" float diffuse = clamp(dot(lightDir, normalFromVS), 0.0, 1.0);\n"
|
||||||
diffuse *= 0.7; // Dim the diffuse a bit
|
" diffuse *= 0.7; // Dim the diffuse a bit\n"
|
||||||
float ambient = 0.3; // Add some ambient
|
" float ambient = 0.3; // Add some ambient\n"
|
||||||
float lightIntensity = diffuse + ambient; // Compute the final light intensity
|
" float lightIntensity = diffuse + ambient; // Compute the final light intensity\n"
|
||||||
|
|
||||||
outputColor = surfaceColor * lightIntensity; //Compute final rendered color
|
" outputColor = surfaceColor * lightIntensity; //Compute final rendered color\n"
|
||||||
}
|
"}\n"
|
||||||
)"))
|
))
|
||||||
{
|
{
|
||||||
std::cerr << shader->log().toStdString() << std::endl;
|
std::cerr << shader->log().toStdString() << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -91,28 +91,28 @@ void OpenGLWidget::initializeGL()
|
|||||||
|
|
||||||
// This is basically a simple fallback vertex shader which does the most basic rendering possible.
|
// This is basically a simple fallback vertex shader which does the most basic rendering possible.
|
||||||
// PolyVox examples are able to provide their own shaders to demonstrate certain effects if desired.
|
// PolyVox examples are able to provide their own shaders to demonstrate certain effects if desired.
|
||||||
if (!mShader->addShaderFromSourceCode(QGLShader::Vertex, R"(
|
if (!mShader->addShaderFromSourceCode(QGLShader::Vertex,
|
||||||
#version 140
|
"#version 140\n"
|
||||||
|
|
||||||
in vec4 position; // This will be the position of the vertex in model-space
|
"in vec4 position; // This will be the position of the vertex in model-space\n"
|
||||||
|
|
||||||
// The usual matrices are provided
|
"// The usual matrices are provided\n"
|
||||||
uniform mat4 cameraToClipMatrix;
|
"uniform mat4 cameraToClipMatrix;\n"
|
||||||
uniform mat4 worldToCameraMatrix;
|
"uniform mat4 worldToCameraMatrix;\n"
|
||||||
uniform mat4 modelToWorldMatrix;
|
"uniform mat4 modelToWorldMatrix;\n"
|
||||||
|
|
||||||
// This will be used by the fragment shader to calculate flat-shaded normals. This is an unconventional approach
|
"// This will be used by the fragment shader to calculate flat-shaded normals. This is an unconventional approach\n"
|
||||||
// but we use it in this example framework because not all surface extractor generate surface normals.
|
"// but we use it in this example framework because not all surface extractor generate surface normals.\n"
|
||||||
out vec4 worldPosition;
|
"out vec4 worldPosition;\n"
|
||||||
|
|
||||||
void main()
|
"void main()\n"
|
||||||
{
|
"{\n"
|
||||||
// Standard sequence of OpenGL transformations.
|
" // Standard sequence of OpenGL transformations.\n"
|
||||||
worldPosition = modelToWorldMatrix * position;
|
" worldPosition = modelToWorldMatrix * position;\n"
|
||||||
vec4 cameraPosition = worldToCameraMatrix * worldPosition;
|
" vec4 cameraPosition = worldToCameraMatrix * worldPosition;\n"
|
||||||
gl_Position = cameraToClipMatrix * cameraPosition;
|
" gl_Position = cameraToClipMatrix * cameraPosition;\n"
|
||||||
}
|
"}\n"
|
||||||
)"))
|
))
|
||||||
{
|
{
|
||||||
std::cerr << mShader->log().toStdString() << std::endl;
|
std::cerr << mShader->log().toStdString() << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -120,27 +120,27 @@ void OpenGLWidget::initializeGL()
|
|||||||
|
|
||||||
// This is basically a simple fallback fragment shader which does the most basic rendering possible.
|
// This is basically a simple fallback fragment shader which does the most basic rendering possible.
|
||||||
// PolyVox examples are able to provide their own shaders to demonstrate certain effects if desired.
|
// PolyVox examples are able to provide their own shaders to demonstrate certain effects if desired.
|
||||||
if (!mShader->addShaderFromSourceCode(QGLShader::Fragment, R"(
|
if (!mShader->addShaderFromSourceCode(QGLShader::Fragment,
|
||||||
#version 130
|
"#version 130\n"
|
||||||
|
|
||||||
// Passed in from the vertex shader
|
"// Passed in from the vertex shader\n"
|
||||||
in vec4 worldPosition;
|
"in vec4 worldPosition;\n"
|
||||||
in vec4 worldNormal;
|
"in vec4 worldNormal;\n"
|
||||||
|
|
||||||
// the color that gets written to the display
|
"// the color that gets written to the display\n"
|
||||||
out vec4 outputColor;
|
"out vec4 outputColor;\n"
|
||||||
|
|
||||||
void main()
|
"void main()\n"
|
||||||
{
|
"{\n"
|
||||||
// Again, for the purposes of these examples we cannot be sure that per-vertex normals are provided. A sensible fallback
|
" // Again, for the purposes of these examples we cannot be sure that per-vertex normals are provided. A sensible fallback \n"
|
||||||
// is to use this little trick to compute per-fragment flat-shaded normals from the world positions using derivative operations.
|
" // is to use this little trick to compute per-fragment flat-shaded normals from the world positions using derivative operations.\n"
|
||||||
vec3 normal = normalize(cross(dFdy(worldPosition.xyz), dFdx(worldPosition.xyz)));
|
" vec3 normal = normalize(cross(dFdy(worldPosition.xyz), dFdx(worldPosition.xyz)));\n"
|
||||||
|
|
||||||
// We are just using the normal as the output color, and making it lighter so it looks a bit nicer.
|
" // We are just using the normal as the output color, and making it lighter so it looks a bit nicer. \n"
|
||||||
// Obviously a real shader would also do texuring, lighting, or whatever is required for the application.
|
" // Obviously a real shader would also do texuring, lighting, or whatever is required for the application.\n"
|
||||||
outputColor = vec4(abs(normal) * 0.5 + vec3(0.5, 0.5, 0.5), 1.0);
|
" outputColor = vec4(abs(normal) * 0.5 + vec3(0.5, 0.5, 0.5), 1.0);\n"
|
||||||
}
|
"}\n"
|
||||||
)"))
|
))
|
||||||
{
|
{
|
||||||
std::cerr << mShader->log().toStdString() << std::endl;
|
std::cerr << mShader->log().toStdString() << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user