Skip to content

Commit

Permalink
major improvements in shader appearance. texture loading supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Aug 19, 2011
1 parent afdc212 commit 92daafe
Show file tree
Hide file tree
Showing 34 changed files with 174 additions and 500 deletions.
Empty file modified 3rdparty/VSML/vsml.cpp 100755 → 100644
Empty file.
Empty file modified 3rdparty/VSML/vsml.h 100755 → 100644
Empty file.
411 changes: 0 additions & 411 deletions 3rdparty/fftw/fftw3.h

This file was deleted.

6 changes: 3 additions & 3 deletions Makefile 100755 → 100644
Expand Up @@ -6,12 +6,12 @@ ifeq ($(BUILD_TYPE), debug)
CFLAGS = -Wall -g -std=c++0x
else
CFLAGS = -O3 -msse2 -ffast-math -funswitch-loops -funsafe-math-optimizations \
-fsingle-precision-constant -funsafe-loop-optimizations -fgcse-sm -fgcse-las -fsee -std=c++0x
-fsingle-precision-constant -funsafe-loop-optimizations -fgcse-sm -fgcse-las -fsee -std=c++0x -static
endif


ifeq ($(OS),Windows_NT)
LDFLAGS = -L/usr/local/lib -lglew32 -lglu32 -lopengl32 -lgdi32 -L3rdparty/fftw -lfftw3f
LDFLAGS = -LC:/MinGW/msys/1.0/lib -lglew32 -lglu32 -lopengl32 -lgdi32 -LC:/MinGW/msys/1.0/local/lib -lfftw3f -lpthread -lIL
else
LDFLAGS = -lm -lX11 -lGL -lGLU
endif
Expand All @@ -20,7 +20,7 @@ endif
SRCDIR := src
VSMLDIR := 3rdparty/VSML

INCLUDES = -IC:/Qt/qtcreator-2.2.82/mingw/include -I$(VSMLDIR)
INCLUDES = -IC:/MinGW/msys/1.0/include -IC:/MinGW/msys/1.0/local/include -I$(VSMLDIR)
OBJFILES := $(patsubst $(VSMLDIR)/%.cpp,$(VSMLDIR)/%.o,$(wildcard $(VSMLDIR)/*.cpp)) \
$(patsubst $(SRCDIR)/%.cpp,$(SRCDIR)/%.o,$(wildcard $(SRCDIR)/*.cpp))
COMPILE = $(CC) $(CFLAGS) $(INCLUDES) -c
Expand Down
Empty file modified README 100755 → 100644
Empty file.
Empty file modified Rocky.config 100755 → 100644
Empty file.
Empty file modified Rocky.creator 100755 → 100644
Empty file.
2 changes: 2 additions & 0 deletions Rocky.files 100755 → 100644
Expand Up @@ -28,3 +28,5 @@ src/glfftwater.h
src/glfftwater.cpp
shaders/post0.glsl
shaders/post1.glsl
src/gltextureloader.h
src/gltextureloader.cpp
2 changes: 2 additions & 0 deletions Rocky.includes 100755 → 100644
@@ -1,2 +1,4 @@
3rdparty/VSML
src
C:/MinGW/msys/1.0/include
C:/MinGW/msys/1.0/local/include
Empty file modified shaders/default.glsl 100755 → 100644
Empty file.
Empty file modified shaders/icosohedron.glsl 100755 → 100644
Empty file.
94 changes: 64 additions & 30 deletions shaders/normals.glsl 100755 → 100644
Expand Up @@ -11,44 +11,78 @@ in vec3 in_TexCoord;
out vec3 vTexCoord;
void main() {
vTexCoord = in_TexCoord;
gl_Position = vec4(in_Position, 1.0);
gl_Position = projMatrix*modelviewMatrix * vec4(in_Position, 1.0);
}

#endif

#ifdef _FRAGMENT_
in vec3 vTexCoord;
out float out_Color0;
out float out_Color1;
out float out_Color2;
out float out_Color3;
out float out_Color4;
out float out_Color5;
out float out_Color6;
out float out_Color7;
out vec3 out_Color0;
out vec3 out_Color1;
out vec3 out_Color2;
out vec3 out_Color3;
out vec3 out_Color4;
out vec3 out_Color5;
out vec3 out_Color6;
out vec3 out_Color7;

vec3 computeNormal(vec3 pos, float size) {
float delta =(1.0/size);
float ndelta = -delta;
float prec = (0.5 / size);

float off0 = -delta;
float off1 = -delta;
float off2 = delta;
float off3 = delta;

float l0 = 0.0;
float l1 = 0.0;
float l2 = 0.0;
float l3 = 0.0;

// need to check deltas and sample from different layers if we run over
if(pos.x + off0 <= 0.0) {
l0 -= 1.0;
off0 = 1.0 - off0;
}
else if(pos.x + off0 >= 1.0) {
l0 += 1.0;
off0 = 1.0 - off0;
}

vec3 tc0 = pos+vec3(0.0,off0,l0);
vec3 tc1 = pos+vec3(off1,0.0,l1);
vec3 tc2 = pos+vec3(off2,0.0,l2);
vec3 tc3 = pos+vec3(0.0,off3,l3);

tc0.st = clamp(tc0.st, prec, 1.0-prec);
tc1.st = clamp(tc1.st, prec, 1.0-prec);
tc2.st = clamp(tc2.st, prec, 1.0-prec);
tc3.st = clamp(tc3.st, prec, 1.0-prec);

float p0 = texture(tex, tc0).x;
float p1 = texture(tex, tc1).x;
float p2 = texture(tex, tc2).x;
float p3 = texture(tex, tc3).x;

return normalize(vec3(p1-p2,4.0*delta,p0-p3));
}

void main() {
vec3 size = textureSize(tex, 0);
float prec = 0.5 / size.x;
vec2 c2 = clamp(vTexCoord.st, prec, 1.0-prec);

float h0 = -10000.0;//texture(tex, vec3(c2, layers[0])).x;
float h1 = texture(tex, vec3(c2, layers[1])).x;
float h2 = texture(tex, vec3(c2, layers[2])).x;
float h3 = texture(tex, vec3(c2, layers[3])).x;
float h4 = texture(tex, vec3(c2, layers[4])).x;
float h5 = texture(tex, vec3(c2, layers[5])).x;
float h6 = texture(tex, vec3(c2, layers[6])).x;
float h7 = texture(tex, vec3(c2, layers[7])).x;

out_Color0 = (h0);
out_Color1 = (h1);
out_Color2 = (h2);
out_Color3 = (h3);
out_Color4 = (h4);
out_Color5 = (h5);
out_Color6 = (h6);
out_Color7 = (h7);
vec3 s = textureSize(tex, 0);
float prec = 0.5 / s.x;
vec2 c2 = vTexCoord.st;//clamp(vTexCoord.st, prec, 1.0-prec);

out_Color0 = computeNormal(vec3(c2, layers[0]), s.x);
out_Color1 = computeNormal(vec3(c2, layers[1]), s.x);
out_Color2 = computeNormal(vec3(c2, layers[2]), s.x);
out_Color3 = computeNormal(vec3(c2, layers[3]), s.x);
out_Color4 = computeNormal(vec3(c2, layers[4]), s.x);
out_Color5 = computeNormal(vec3(c2, layers[5]), s.x);
out_Color6 = computeNormal(vec3(c2, layers[6]), s.x);
out_Color7 = computeNormal(vec3(c2, layers[7]), s.x);
}
#endif

Empty file modified shaders/perlin.glsl 100755 → 100644
Empty file.
Empty file modified shaders/post0.glsl 100755 → 100644
Empty file.
26 changes: 7 additions & 19 deletions shaders/post1.glsl 100755 → 100644
@@ -1,21 +1,3 @@
/*float4 ToneMapping( PS_INPUT psInput ) : SV_Target
{
int2 iScreenCoord = int2(psInput.Tex * depthInfo.yz);
float4 sample = tex2D.Load(int3(iScreenCoord, 0));
float4 ramp = colorramp.Sample(linearSampler, float2(cOffset, 0.f));
sample.r += ramp.r - 0.5 * (ramp.g + ramp.b);
sample.g += ramp.g - 0.5 * (ramp.r + ramp.b);
sample.b += ramp.b - 0.5 * (ramp.r + ramp.g);
float Y = dot(sample, CIEXYZ);
float Yw = 0.95;
float Yp = exp(tex2D.Load(int3(0,0,maxMipmapLevel-1)).w); //adaptation luminance
float Yr = alpha * Y / Yp;
float D = (Yr * (1.0 + Yr / (Yw * Yw)) / (1 + Yr));
return sample * D / Y;
}
*/


#version 400 core

uniform sampler2D tex;
Expand All @@ -39,16 +21,22 @@ void main(void) {
in vec3 pass_TexCoord;
out vec3 out_Color;
uniform float alpha = 0.75;
uniform float maxMipLevel;

vec4 tonemap(vec4 color) {
const vec3 luminace = vec3(0.2125f, 0.7154f, 0.0721f);
float Y = dot(color.xyz, luminace);
float Yw = 0.95;
float Yp = exp(textureLod(tex, vec2(0.5, 0.5), 10.0).w); //adaptation luminance
float Yp = exp(textureLod(tex, vec2(0.5, 0.5), maxMipLevel).w); //adaptation luminance
float Yr = alpha * Y / Yp;
float D = (Yr * (1.0 + Yr / (Yw * Yw)) / (1 + Yr));
return color * D / Y;
}

vec4 ssao(vec2 texCoord) {
return vec4(0.0);
}

void main() {
vec4 color = tonemap(texture(tex, pass_TexCoord.st));
out_Color = color.xyz;
Expand Down
35 changes: 26 additions & 9 deletions shaders/recttess.glsl 100755 → 100644
Expand Up @@ -3,7 +3,9 @@
uniform mat4 modelviewMatrix;
uniform mat4 projMatrix;
uniform sampler3D tex;
uniform sampler3D normalTex;
uniform sampler2D waterTex;
uniform sampler2D testTex;
uniform vec2 grid;
uniform float D;
uniform bool wireframe = false;
Expand All @@ -13,6 +15,7 @@ uniform float waterLevel = 0.0;
const float tile =0.015;
const float attenuation = 0.075;
uniform float LOD;

#ifdef _VERTEX_
in vec3 in_Position;
in vec3 in_Normal;
Expand Down Expand Up @@ -221,13 +224,19 @@ vec4 water(vec3 normal, vec4 pos) {
vec3 reflDir = reflect(eyeDir, norm);
vec4 transColor = vec4(0.0, 0.278, 0.321, 0.0);
float cos_angle = max(dot(norm, eyeDir), 0.3);

vec4 waterColor = mix(baseColor, transColor*transColor, cos_angle);
reflDir = normalize(reflDir);
vec4 atmoColor = atmosphere(reflDir);

vec4 atmoColor = atmosphere(reflDir)*1.5;

float distance = length(cameraPos.xyz - pos.xyz);
distance *= .005;
distance = clamp(distance, 0, 1);
//add foam if near shore
float lightAngle = max(dot(norm, lightPos), 0.8);

return mix(waterColor, atmoColor, 0.6);
return mix(waterColor, atmoColor, 0.6*distance);
}

float amplify(float d, float scale, float offset) {
Expand All @@ -241,10 +250,10 @@ vec4 computeFFTNormal(vec2 pos, float atten) {
float delta =(1.0/256.0);
pos *= tile;

float p0 = texture(waterTex, (pos + vec2(0.0, -delta)) ).y * atten;
float p1 = texture(waterTex, (pos + vec2(-delta, 0.0) )).y * atten;
float p2 = texture(waterTex, (pos + vec2(delta, 0.0) ) ).y * atten;
float p3 = texture(waterTex, (pos + vec2(0.0, delta) ) ).y * atten;
float p0 = texture(waterTex, (pos + vec2(0.0,-delta)) ).y * atten;
float p1 = texture(waterTex, (pos + vec2(-delta,0.0) )).y * atten;
float p2 = texture(waterTex, (pos + vec2(delta,0.0) ) ).y * atten;
float p3 = texture(waterTex, (pos + vec2(0.0,delta) ) ).y * atten;

return vec4(p1-p2,2.0*200.0*delta,p0-p3,0.0);
}
Expand All @@ -257,21 +266,29 @@ vec4 refractTerrain(vec3 disp, vec3 normal, float depth) { //fake refraction bas
return vec4(.7, .7, .6, 1.0)*pVal;
}


void main() {

float h = texture(tex, fTexCoord).x;
float pVal = (1.0-(h*0.01+0.25));
out_Color0 = vec4(.7, .7, .6, 1.0)*pVal + vec4(0.3, 0.5, 0.1, 1.0) * clamp((1.0-pVal-0.5), 0.0, 1.0);
out_Color0 = mix(texture(testTex, fTexCoord.st*8.0), out_Color0, min(pVal+0.1, 1.0));
vec3 N = texture(normalTex, fTexCoord).xyz;
vec3 L = normalize(fPosition.xyz-lightPos);
float NL = dot(N, L)*0.25+1.3;

out_Color0.xyz *= NL;

float dH = abs(h - waterLevel)*attenuation;


float waterStrength = 1.0-clamp((-h*attenuation-waterLevel),0.0,1.0);
if(waterStrength < 1.0) {
vec3 I = fPosition.xyz - cameraPos.xyz;
vec3 N = computeFFTNormal(fPosition.xz, dH).xyz;
vec3 fftN = computeFFTNormal(fPosition.xz, dH).xyz;
vec3 displacement = texture(waterTex, fPosition.xz*tile).xyz;
out_Color0 = mix(water(N, fPosition),
refractTerrain(displacement, N, dH), waterStrength);
out_Color0 = mix(water(fftN, fPosition),
refractTerrain(displacement, fftN, dH) * NL, waterStrength);
}

if(wireframe) {
Expand Down
Empty file modified shaders/solid.glsl 100755 → 100644
Empty file.
Empty file modified src/common.h 100755 → 100644
Empty file.
Empty file modified src/glcommon.h 100755 → 100644
Empty file.
45 changes: 34 additions & 11 deletions src/glengine.cpp 100755 → 100644
Expand Up @@ -6,13 +6,17 @@
#include "glshaderprogram.h"
#include "keyboardcontroller.h"
#include "glperlinterrain.h"
#include "gltextureloader.h"
#include <vsml.h>
#include <IL/il.h>

GLTextureLoader *GLTextureLoader::s_instance = 0;
GLFramebufferObject *pMultisampleFramebuffer, *pFramebuffer0, *pFramebuffer1;
GLPrimitive *pQuad;
void hello() {}
GLEngine::GLEngine(WindowProperties &properties) {

renderMode_ = FILL;
//std::thread t(hello);
//renderMode_ = FILL;

//init gl setup
vsml_ = VSML::getInstance();
Expand Down Expand Up @@ -48,7 +52,7 @@ GLEngine::GLEngine(WindowProperties &properties) {
params.type = GL_TEXTURE_2D;
pMultisampleFramebuffer = new GLFramebufferObject(params);

params.hasDepth = false;
params.hasDepth = true;
params.nSamples = 0;

pFramebuffer0 = new GLFramebufferObject(params);
Expand Down Expand Up @@ -94,7 +98,7 @@ GLEngine::GLEngine(WindowProperties &properties) {
shaderPrograms_["icosohedron"]->link();

GLPerlinTerrainParams paramsT;
paramsT.resolution = 128;
paramsT.resolution = 180;
paramsT.gain = 0.61;
paramsT.grid = float2(28,28);
paramsT.lacunarity = 1.7;
Expand All @@ -106,6 +110,7 @@ GLEngine::GLEngine(WindowProperties &properties) {

lightPos_ = float3(1.0, 0.1, 0.0).getNormalized();


}


Expand All @@ -126,7 +131,7 @@ void GLEngine::resize(int w, int h) {

pFramebuffer0->resize(width_, height_);
pFramebuffer1->resize(width_, height_);

camera_.orthogonal_camera(width_, height_);
maxMipLevel_ = (log10((float)max(width_, height_)) / log10(2.f));

}
Expand Down Expand Up @@ -157,11 +162,17 @@ void GLEngine::draw(float time, float dt, const KeyboardController *keyControlle
primitives_["sphere0"]->draw(shaderPrograms_["icosohedron"]);
shaderPrograms_["icosohedron"]->release();
glEnable(GL_DEPTH_TEST);

// join fft computation thread

terrain_->draw(vsml_, time);

// start next fft computation thread

glDrawBuffers(1, outputTex);
pMultisampleFramebuffer->release();
pMultisampleFramebuffer->blit(*pFramebuffer0);

glDisable(GL_DEPTH_TEST);
this->vsmlOrtho();
shaderPrograms_["post0"]->bind(vsml_);
Expand All @@ -172,7 +183,7 @@ void GLEngine::draw(float time, float dt, const KeyboardController *keyControlle
pFramebuffer0->bindsurface(1);
shaderPrograms_["post0"]->setUniformValue("posTex", 1);
glActiveTexture(GL_TEXTURE0);

pFramebuffer1->bind();
shaderPrograms_["post0"]->setUniformValue("modelviewMatrixPrev", previousViewMatrices[0]);
shaderPrograms_["post0"]->setUniformValue("projMatrixPrev", previousViewMatrices[1]);
Expand All @@ -187,15 +198,27 @@ void GLEngine::draw(float time, float dt, const KeyboardController *keyControlle

shaderPrograms_["post1"]->bind(vsml_);
glActiveTexture(GL_TEXTURE0);

pFramebuffer1->bindsurface(0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);

shaderPrograms_["post1"]->setUniformValue("tex", 0);
primitives_["quad1"]->draw(shaderPrograms_["default"]);
shaderPrograms_["post1"]->setUniformValue("maxMipLevel", (float)maxMipLevel_);
primitives_["quad1"]->draw(shaderPrograms_["post1"]);
shaderPrograms_["post1"]->release();
pFramebuffer1->unbindsurface();

camera_.orthogonal_camera(width_, height_);

/*
glActiveTexture(GL_TEXTURE0);
pFramebuffer0->bindsurface(0);
shaderPrograms_["default"]->bind(vsml_);
shaderPrograms_["default"]->setUniformValue("tex", 0);
primitives_["quad1"]->draw(shaderPrograms_["default"]);
pFramebuffer0->unbindsurface();
shaderPrograms_["default"]->release();*/

}

void GLEngine::vsmlOrtho() {
Expand Down

0 comments on commit 92daafe

Please sign in to comment.