Merge branch 'master' of https://github.com/yvt/openspades
This commit is contained in:
commit
1d9cbd54e8
@ -33,6 +33,7 @@ uniform sampler2D waveTexture1;
|
||||
uniform sampler2D waveTexture2;
|
||||
uniform sampler2D waveTexture3;
|
||||
uniform sampler2D mirrorTexture;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform vec3 fogColor;
|
||||
uniform vec3 skyColor;
|
||||
uniform vec2 zNearFar;
|
||||
@ -84,12 +85,10 @@ void main() {
|
||||
vec2 origScrPos = screenPosition.xy / screenPosition.z;
|
||||
vec2 scrPos = origScrPos;
|
||||
|
||||
// TODO: do displacement
|
||||
vec2 xToUV = dFdx(worldPosition.xy);
|
||||
vec2 yToUV = dFdy(worldPosition.xy);
|
||||
float scale = 1. / dot(xToUV.xy, yToUV.yx * vec2(1., -1.));
|
||||
vec2 disp = vec2(dot(xToUV, wave.xy * vec2(1., -1.)),
|
||||
dot(yToUV, wave.xy * vec2(-1., 1.)));
|
||||
float scale = 1. / viewPosition.z;
|
||||
vec2 disp = wave.xy * 0.1;
|
||||
scrPos += disp * scale * displaceScale * 4.;
|
||||
|
||||
// check envelope length.
|
||||
@ -132,6 +131,7 @@ void main() {
|
||||
0., 1.);
|
||||
vec2 sampCoord = integralCoord + subCoord * blurDirSign;
|
||||
vec3 waterColor = texture2D(texture, sampCoord / 512.).xyz;
|
||||
waterColor *= EvaluateSunLight() + EvaluateAmbientLight(1.);
|
||||
|
||||
// underwater object color
|
||||
gl_FragColor = texture2D(screenTexture, scrPos);
|
||||
@ -149,17 +149,18 @@ void main() {
|
||||
|
||||
/* ------- Reflection -------- */
|
||||
|
||||
// compute reflection color
|
||||
vec2 scrPos2 = origScrPos;
|
||||
//disp = vec2(dot(xToUV, wave.xy * vec2(1., -1.)),
|
||||
// dot(yToUV, wave.xy * vec2(-1., 1.)));
|
||||
scrPos2 -= disp * scale * displaceScale * 15.;
|
||||
vec3 ongoing = normalize(worldPositionFromOrigin);
|
||||
|
||||
// bluring for far surface
|
||||
float lodBias = dot(abs(vec4(xToUV, yToUV)), vec4(1. / 4.));
|
||||
lodBias = max(1., lodBias * 120.);
|
||||
float lodBias = 1.0 / ongoing.z;
|
||||
float dispScaleByLod = min(1., ongoing.z * 0.5);
|
||||
lodBias = log2(lodBias);
|
||||
lodBias = clamp(lodBias, 0., 5.);
|
||||
lodBias = clamp(lodBias, 0., 2.);
|
||||
|
||||
// compute reflection color
|
||||
vec2 scrPos2 = origScrPos;
|
||||
scrPos2 -= disp * scale * displaceScale * 15.;
|
||||
|
||||
|
||||
vec3 refl = texture2D(mirrorTexture, scrPos2, lodBias).xyz;
|
||||
refl *= refl; // linearize
|
||||
@ -167,7 +168,6 @@ void main() {
|
||||
|
||||
// reflectivity
|
||||
vec3 sunlight = EvaluateSunLight();
|
||||
vec3 ongoing = normalize(worldPositionFromOrigin);
|
||||
float reflective = dot(ongoing, wave.xyz);
|
||||
reflective = clamp(1. - reflective, 0., 1.);
|
||||
|
||||
@ -211,7 +211,7 @@ void main() {
|
||||
spec *= spec; // ^512
|
||||
spec *= spec; // ^1024
|
||||
spec *= reflective;
|
||||
gl_FragColor.xyz += sunlight * spec * 1000. * att;
|
||||
gl_FragColor.xyz += sunlight * spec * 10000. * att;
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
Shaders/Water2.fs
|
||||
Shaders/Water2.vs
|
||||
*shadow*
|
||||
*shadow-variance*
|
||||
|
@ -48,13 +48,13 @@ float DisplaceWater(vec2 worldPos){
|
||||
vec2 waveCoord2 = worldPos.xy * 0.02344 + vec2(.154, .7315);
|
||||
|
||||
|
||||
vec4 wave = texture2DLod(waveTexture1, waveCoord.xy, 3.).xyzw;
|
||||
vec4 wave = texture2DLod(waveTexture1, waveCoord.xy, 1.).xyzw;
|
||||
float disp = mix(-0.1, 0.1, wave.w) * 1.;
|
||||
|
||||
vec4 wave2 = texture2DLod(waveTexture2, waveCoord.zw, 4.).xyzw;
|
||||
vec4 wave2 = texture2DLod(waveTexture2, waveCoord.zw, 2.).xyzw;
|
||||
disp += mix(-0.1, 0.1, wave2.w) * 0.5;
|
||||
|
||||
wave2 = texture2DLod(waveTexture3, waveCoord2.xy, 2.).xyzw;
|
||||
wave2 = texture2DLod(waveTexture3, waveCoord2.xy, 0.).xyzw;
|
||||
disp += mix(-0.1, 0.1, wave2.w) * 2.5;
|
||||
|
||||
return disp * 4.;
|
||||
|
@ -365,7 +365,7 @@ namespace spades {
|
||||
IGLDevice::Linear);
|
||||
dev->TexParamater(IGLDevice::Texture2D,
|
||||
IGLDevice::TextureMinFilter,
|
||||
IGLDevice::LinearMipmapLinear);
|
||||
IGLDevice::Linear);
|
||||
dev->TexParamater(IGLDevice::Texture2D,
|
||||
IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
@ -584,7 +584,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
device->BindTexture(IGLDevice::Texture2D, mirrorColorTexture);
|
||||
device->GenerateMipmap(IGLDevice::Texture2D);
|
||||
//device->GenerateMipmap(IGLDevice::Texture2D);
|
||||
|
||||
// restore framebuffer
|
||||
if(useMultisample){
|
||||
|
@ -227,7 +227,7 @@ namespace spades {
|
||||
|
||||
// if true, this is negative-y faced plane
|
||||
// if false, this is negative-z faced plane
|
||||
bool isSide = pixel & 0x80 != 0;
|
||||
bool isSide = (pixel & 0x80) != 0;
|
||||
|
||||
// direction dependent process
|
||||
Vector3 center; // center of face
|
||||
|
@ -733,6 +733,7 @@ namespace spades {
|
||||
static GLProgramUniform projectionViewMatrix("projectionViewMatrix");
|
||||
static GLProgramUniform modelMatrix("modelMatrix");
|
||||
static GLProgramUniform viewModelMatrix("viewModelMatrix");
|
||||
static GLProgramUniform viewMatrix("viewMatrix");
|
||||
static GLProgramUniform fogDistance("fogDistance");
|
||||
static GLProgramUniform fogColor("fogColor");
|
||||
static GLProgramUniform skyColor("skyColor");
|
||||
@ -746,6 +747,7 @@ namespace spades {
|
||||
projectionViewMatrix(prg);
|
||||
modelMatrix(prg);
|
||||
viewModelMatrix(prg);
|
||||
viewMatrix(prg);
|
||||
fogDistance(prg);
|
||||
fogColor(prg);
|
||||
skyColor(prg);
|
||||
@ -759,6 +761,7 @@ namespace spades {
|
||||
projectionViewMatrix.SetValue(renderer->GetProjectionViewMatrix());
|
||||
modelMatrix.SetValue(mat);
|
||||
viewModelMatrix.SetValue(renderer->GetViewMatrix() * mat);
|
||||
viewMatrix.SetValue(renderer->GetViewMatrix());
|
||||
fogDistance.SetValue(fogDist);
|
||||
fogColor.SetValue(fogCol.x, fogCol.y, fogCol.z);
|
||||
skyColor.SetValue(skyCol.x, skyCol.y, skyCol.z);
|
||||
@ -768,8 +771,8 @@ namespace spades {
|
||||
def.viewOrigin.z);
|
||||
/*displaceScale.SetValue(1.f / renderer->ScreenWidth() / tanf(def.fovX * .5f),
|
||||
1.f / renderer->ScreenHeight() / tanf(def.fovY) * .5f);*/
|
||||
displaceScale.SetValue(.3f / renderer->ScreenWidth(),
|
||||
.3f / renderer->ScreenHeight());
|
||||
displaceScale.SetValue(1.f,
|
||||
1.f);
|
||||
fovTan.SetValue(tanf(def.fovX * .5f), -tanf(def.fovY * .5f),
|
||||
-tanf(def.fovX * .5f), tanf(def.fovY * .5f));
|
||||
|
||||
@ -840,6 +843,11 @@ namespace spades {
|
||||
// mirror
|
||||
device->ActiveTexture(6);
|
||||
device->BindTexture(IGLDevice::Texture2D, renderer->GetFramebufferManager()->GetMirrorTexture());
|
||||
if((float)r_maxAnisotropy > 1.1f) {
|
||||
device->TexParamater(IGLDevice::Texture2D,
|
||||
IGLDevice::TextureMaxAnisotropy,
|
||||
(float)r_maxAnisotropy);
|
||||
}
|
||||
mirrorTexture.SetValue(6);
|
||||
|
||||
shadowShader(renderer, prg, 7);
|
||||
|
Loading…
x
Reference in New Issue
Block a user