WaterFilter can now have a square shape
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9553 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
9276987aac
commit
28926b8383
10
engine/src/core-data/Common/ShaderLib/WaterUtil.glsllib
Normal file
10
engine/src/core-data/Common/ShaderLib/WaterUtil.glsllib
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifdef ENABLE_AREA
|
||||||
|
bool isOverExtent(vec3 position,vec3 center,float radius){
|
||||||
|
vec2 dist = position.xz-center.xz;
|
||||||
|
#ifdef SQUARE_AREA
|
||||||
|
return dist.x*dist.x >radius || dist.y*dist.y >radius;
|
||||||
|
#else
|
||||||
|
return dot(dist,dist)>radius;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
@ -1,3 +1,4 @@
|
|||||||
|
#import "Common/ShaderLib/WaterUtil.glsllib"
|
||||||
// Water pixel shader
|
// Water pixel shader
|
||||||
// Copyright (C) JMonkeyEngine 3.0
|
// Copyright (C) JMonkeyEngine 3.0
|
||||||
// by Remy Bouquet (nehon) for JMonkeyEngine 3.0
|
// by Remy Bouquet (nehon) for JMonkeyEngine 3.0
|
||||||
@ -241,7 +242,7 @@ void main(){
|
|||||||
if(level >= m_CameraPosition.y){
|
if(level >= m_CameraPosition.y){
|
||||||
#ifdef ENABLE_AREA
|
#ifdef ENABLE_AREA
|
||||||
vec3 dist = m_CameraPosition-m_Center;
|
vec3 dist = m_CameraPosition-m_Center;
|
||||||
if(dot(dist,dist) >m_Radius){
|
if(isOverExtent(m_CameraPosition, m_Center, m_Radius)){
|
||||||
gl_FragColor = vec4(color2, 1.0);
|
gl_FragColor = vec4(color2, 1.0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -251,8 +252,7 @@ void main(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_AREA
|
#ifdef ENABLE_AREA
|
||||||
vec3 dist = position-m_Center;
|
if(isOverExtent(position, m_Center, m_Radius)){
|
||||||
if(dot(dist,dist) >m_Radius){
|
|
||||||
gl_FragColor = vec4(color2, 1.0);
|
gl_FragColor = vec4(color2, 1.0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ MaterialDef Advanced Water {
|
|||||||
|
|
||||||
Float Radius
|
Float Radius
|
||||||
Vector3 Center
|
Vector3 Center
|
||||||
|
Boolean SquareArea
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ MaterialDef Advanced Water {
|
|||||||
ENABLE_CAUSTICS : UseCaustics
|
ENABLE_CAUSTICS : UseCaustics
|
||||||
ENABLE_REFRACTION : UseRefraction
|
ENABLE_REFRACTION : UseRefraction
|
||||||
ENABLE_AREA : Center
|
ENABLE_AREA : Center
|
||||||
|
SQUARE_AREA : SquareArea
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +88,7 @@ MaterialDef Advanced Water {
|
|||||||
ENABLE_CAUSTICS : UseCaustics
|
ENABLE_CAUSTICS : UseCaustics
|
||||||
ENABLE_REFRACTION : UseRefraction
|
ENABLE_REFRACTION : UseRefraction
|
||||||
ENABLE_AREA : Center
|
ENABLE_AREA : Center
|
||||||
|
SQUARE_AREA : SquareArea
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
#import "Common/ShaderLib/MultiSample.glsllib"
|
#import "Common/ShaderLib/MultiSample.glsllib"
|
||||||
|
#import "Common/ShaderLib/WaterUtil.glsllib"
|
||||||
|
|
||||||
// Water pixel shader
|
// Water pixel shader
|
||||||
// Copyright (C) JMonkeyEngine 3.0
|
// Copyright (C) JMonkeyEngine 3.0
|
||||||
@ -229,13 +230,14 @@ vec4 underWater(int sampleNum){
|
|||||||
|
|
||||||
return vec4(color, 1.0);
|
return vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NOTE: This will be called even for single-sampling
|
// NOTE: This will be called even for single-sampling
|
||||||
vec4 main_multiSample(int sampleNum){
|
vec4 main_multiSample(int sampleNum){
|
||||||
// If we are underwater let's call the underwater function
|
// If we are underwater let's call the underwater function
|
||||||
if(m_WaterHeight >= m_CameraPosition.y){
|
if(m_WaterHeight >= m_CameraPosition.y){
|
||||||
#ifdef ENABLE_AREA
|
#ifdef ENABLE_AREA
|
||||||
vec2 dist = m_CameraPosition.xz-m_Center.xz;
|
if(isOverExtent(m_CameraPosition, m_Center, m_Radius)){
|
||||||
if(dot(dist,dist) >m_Radius){
|
|
||||||
return fetchTextureSample(m_Texture, texCoord, sampleNum);
|
return fetchTextureSample(m_Texture, texCoord, sampleNum);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -249,8 +251,7 @@ vec4 main_multiSample(int sampleNum){
|
|||||||
vec3 position = getPosition(sceneDepth, texCoord);
|
vec3 position = getPosition(sceneDepth, texCoord);
|
||||||
|
|
||||||
#ifdef ENABLE_AREA
|
#ifdef ENABLE_AREA
|
||||||
vec2 dist = position.xz-m_Center.xz;
|
if(isOverExtent(position, m_Center, m_Radius)){
|
||||||
if(dot(dist,dist) >m_Radius){
|
|
||||||
return vec4(color2, 1.0);
|
return vec4(color2, 1.0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -118,6 +118,12 @@ public class WaterFilter extends Filter {
|
|||||||
//positional attributes
|
//positional attributes
|
||||||
private Vector3f center;
|
private Vector3f center;
|
||||||
private float radius;
|
private float radius;
|
||||||
|
private AreaShape shapeType = AreaShape.Circular;
|
||||||
|
|
||||||
|
public enum AreaShape{
|
||||||
|
Circular,
|
||||||
|
Square
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Water Filter
|
* Create a Water Filter
|
||||||
@ -300,6 +306,7 @@ public class WaterFilter extends Filter {
|
|||||||
if (center != null) {
|
if (center != null) {
|
||||||
material.setVector3("Center", center);
|
material.setVector3("Center", center);
|
||||||
material.setFloat("Radius", radius * radius);
|
material.setFloat("Radius", radius * radius);
|
||||||
|
material.setBoolean("SquareArea", shapeType==AreaShape.Square);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1055,6 +1062,10 @@ public class WaterFilter extends Filter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the center of this effect
|
||||||
|
* @return the center of this effect
|
||||||
|
*/
|
||||||
public Vector3f getCenter() {
|
public Vector3f getCenter() {
|
||||||
return center;
|
return center;
|
||||||
}
|
}
|
||||||
@ -1072,6 +1083,10 @@ public class WaterFilter extends Filter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the radius of this effect
|
||||||
|
* @return the radius of this effect
|
||||||
|
*/
|
||||||
public float getRadius() {
|
public float getRadius() {
|
||||||
return radius;
|
return radius;
|
||||||
|
|
||||||
@ -1089,4 +1104,26 @@ public class WaterFilter extends Filter {
|
|||||||
material.setFloat("Radius", radius * radius);
|
material.setFloat("Radius", radius * radius);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the shape of the water area
|
||||||
|
* @return the shape of the water area
|
||||||
|
*/
|
||||||
|
public AreaShape getShapeType() {
|
||||||
|
return shapeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the shape of the water area (Circular (default) or Square).
|
||||||
|
* if the shape is square the radius is considered as an extent.
|
||||||
|
* @param shapeType the shape type
|
||||||
|
*/
|
||||||
|
public void setShapeType(AreaShape shapeType) {
|
||||||
|
this.shapeType = shapeType;
|
||||||
|
if (material != null) {
|
||||||
|
material.setBoolean("SquareArea", shapeType==AreaShape.Square);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user