Commit eb660cbd by Kai Westerkamp

geometry

parent 86111c8b
...@@ -121,10 +121,6 @@ void GLView::initShader() ...@@ -121,10 +121,6 @@ void GLView::initShader()
if(!vertex2->compileSourceFile(QLatin1String(":/landscape.vert"))) if(!vertex2->compileSourceFile(QLatin1String(":/landscape.vert")))
qCritical()<< "Vertex Shader landscape failed"<< vertex2->log(); qCritical()<< "Vertex Shader landscape failed"<< vertex2->log();
QOpenGLShader *fragment2 = new QOpenGLShader(QOpenGLShader::Fragment);
if(!fragment2->compileSourceFile(QLatin1String(":/landscape.frag")))
qCritical()<< "Fragment Shader landscape failed"<< fragment2->log();
QOpenGLShader *tesselationControl = new QOpenGLShader(QOpenGLShader::TessellationControl); QOpenGLShader *tesselationControl = new QOpenGLShader(QOpenGLShader::TessellationControl);
if(!tesselationControl->compileSourceFile(QLatin1String(":/landscape.tcs"))) if(!tesselationControl->compileSourceFile(QLatin1String(":/landscape.tcs")))
qCritical()<< "Tesselation Control landscape failed"<< tesselationControl->log(); qCritical()<< "Tesselation Control landscape failed"<< tesselationControl->log();
...@@ -133,11 +129,20 @@ void GLView::initShader() ...@@ -133,11 +129,20 @@ void GLView::initShader()
if(!tesselationEval->compileSourceFile(QLatin1String(":/landscape.tes"))) if(!tesselationEval->compileSourceFile(QLatin1String(":/landscape.tes")))
qCritical()<< "Tesselation Eval landscape failed"<< tesselationEval->log(); qCritical()<< "Tesselation Eval landscape failed"<< tesselationEval->log();
QOpenGLShader *geometry = new QOpenGLShader(QOpenGLShader::Geometry);
if(!geometry->compileSourceFile(QLatin1String(":/landscape.geo")))
qCritical()<< "Tesselation Eval landscape failed"<< geometry->log();
QOpenGLShader *fragment2 = new QOpenGLShader(QOpenGLShader::Fragment);
if(!fragment2->compileSourceFile(QLatin1String(":/landscape.frag")))
qCritical()<< "Fragment Shader landscape failed"<< fragment2->log();
landscapeShader = new QOpenGLShaderProgram(this); landscapeShader = new QOpenGLShaderProgram(this);
landscapeShader->addShader(vertex2); landscapeShader->addShader(vertex2);
landscapeShader->addShader(fragment2); landscapeShader->addShader(fragment2);
landscapeShader->addShader(tesselationControl); landscapeShader->addShader(tesselationControl);
landscapeShader->addShader(tesselationEval); landscapeShader->addShader(tesselationEval);
landscapeShader->addShader(geometry);
if(!landscapeShader->link()){ if(!landscapeShader->link()){
qCritical()<< "Linking landscape failed:"<<landscapeShader->log(); qCritical()<< "Linking landscape failed:"<<landscapeShader->log();
} }
......
...@@ -53,6 +53,7 @@ DISTFILES += \ ...@@ -53,6 +53,7 @@ DISTFILES += \
landscape.frag \ landscape.frag \
landscape.vert \ landscape.vert \
landscape.tec \ landscape.tec \
landscape.tes landscape.tes \
landscape.geo
FORMS += FORMS +=
...@@ -25,5 +25,6 @@ ...@@ -25,5 +25,6 @@
<file>landscape.vert</file> <file>landscape.vert</file>
<file>landscape.tcs</file> <file>landscape.tcs</file>
<file>landscape.tes</file> <file>landscape.tes</file>
<file>landscape.geo</file>
</qresource> </qresource>
</RCC> </RCC>
#version 420 #version 420
out vec4 FragColor; out vec4 FragColor;
in vec3 tePosition; in vec3 gPosition;
in vec2 teUV; in vec2 gUV;
in vec3 gTriDistance;
uniform sampler2D heightmap; uniform sampler2D heightmap;
uniform sampler2D landTex1; uniform sampler2D landTex1;
...@@ -14,17 +15,28 @@ void main() ...@@ -14,17 +15,28 @@ void main()
{ {
// //
vec2 textureUV = teUV*8; vec2 textureUV = gUV*8;
vec3 col1 = texture2D(landTex1,textureUV).xyz; vec3 col1 = texture2D(landTex1,textureUV).xyz;
vec3 col2 = texture2D(landTex2,textureUV).xyz; vec3 col2 = texture2D(landTex2,textureUV).xyz;
float height = tePosition.y/5; float height = gPosition.y/5;
float alpha = smoothstep(0.4f,0.6f,height); float alpha = smoothstep(0.4f,0.6f,height);
//float alpha = clamp(height,0.0,1.0); //float alpha = clamp(height,0.0,1.0);
FragColor = vec4((1-alpha)*col2 + alpha *col1,1.0);
float d = min(gTriDistance[0],min(gTriDistance.y,gTriDistance.z));
float edgeIntensity = exp2(-1.0*d*d);
FragColor = +vec4((1-alpha)*col2 + alpha *col1,1.0);
if(d < 0.05){
FragColor = edgeIntensity*vec4(0.0,1.0,0.0,1.0);
}
//FragColor = vec4(gUV,0.0,1.0);
//FragColor = vec4(alpha); //FragColor = vec4(alpha);
//FragColor = vec4(col1,1.0); //FragColor = vec4(col1,1.0);
//FragColor = clamp(vec4(vec3(textureLod(heightmap,teUV,0).x), 1.0)*10,0,1); //FragColor = clamp(vec4(vec3(textureLod(heightmap,teUV,0).x), 1.0)*10,0,1);
......
#version 420
layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;
in vec2 teUV[3];
out vec2 gUV;
in vec3 tePosition[3];
out vec3 gPosition;
out vec3 gTriDistance;
void main(void)
{
gTriDistance = vec3(1, 0, 0);
gUV = teUV[0];
gPosition = tePosition[0];
gl_Position = gl_in[0].gl_Position; EmitVertex();
gTriDistance = vec3(0, 1, 0);
gUV = teUV[1];
gPosition = tePosition[1];
gl_Position = gl_in[1].gl_Position; EmitVertex();
gTriDistance = vec3(0, 0, 1);
gUV = teUV[2];
gPosition = tePosition[2];
gl_Position = gl_in[2].gl_Position; EmitVertex();
EndPrimitive();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment