merge development into test #26
@@ -0,0 +1,79 @@
|
|||||||
|
package pp.mdga.client.board.Outline;
|
||||||
|
|
||||||
|
import com.jme3.asset.AssetManager;
|
||||||
|
import com.jme3.material.Material;
|
||||||
|
import com.jme3.material.MaterialDef;
|
||||||
|
import com.jme3.math.ColorRGBA;
|
||||||
|
import com.jme3.math.Vector2f;
|
||||||
|
import com.jme3.post.Filter;
|
||||||
|
import com.jme3.renderer.RenderManager;
|
||||||
|
import com.jme3.renderer.ViewPort;
|
||||||
|
import com.jme3.texture.FrameBuffer;
|
||||||
|
|
||||||
|
public class OutlineProFilter extends Filter {
|
||||||
|
|
||||||
|
private OutlinePreFilter outlinePreFilter;
|
||||||
|
private ColorRGBA outlineColor = new ColorRGBA(0, 1, 0, 1);
|
||||||
|
private float outlineWidth = 1;
|
||||||
|
|
||||||
|
public OutlineProFilter(OutlinePreFilter outlinePreFilter) {
|
||||||
|
super("OutlineFilter");
|
||||||
|
this.outlinePreFilter = outlinePreFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initFilter(AssetManager assetManager, RenderManager renderManager, ViewPort vp, int w, int h) {
|
||||||
|
MaterialDef matDef = (MaterialDef) assetManager.loadAsset("MatDefs/OutlinePro.j3md");
|
||||||
|
material = new Material(matDef);
|
||||||
|
material.setVector2("Resolution", new Vector2f(w, h));
|
||||||
|
material.setColor("OutlineColor", outlineColor);
|
||||||
|
material.setFloat("OutlineWidth", outlineWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void preFrame(float tpf) {
|
||||||
|
super.preFrame(tpf);
|
||||||
|
material.setTexture("OutlineDepthTexture", outlinePreFilter.getOutlineTexture());
|
||||||
|
// System.out.println("OutlineFilter.preFrame()");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void postFrame(RenderManager renderManager, ViewPort viewPort, FrameBuffer prevFilterBuffer, FrameBuffer sceneBuffer) {
|
||||||
|
super.postFrame(renderManager, viewPort, prevFilterBuffer, sceneBuffer);
|
||||||
|
// material.setTexture("OutlineDepthTexture", outlinePreFilter.getDefaultPassDepthTexture());
|
||||||
|
// System.out.println("OutlineFilter.postFrame()");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Material getMaterial() {
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorRGBA getOutlineColor() {
|
||||||
|
return outlineColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutlineColor(ColorRGBA outlineColor) {
|
||||||
|
this.outlineColor = outlineColor;
|
||||||
|
if (material != null) {
|
||||||
|
material.setColor("OutlineColor", outlineColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getOutlineWidth() {
|
||||||
|
return outlineWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutlineWidth(float outlineWidth) {
|
||||||
|
this.outlineWidth = outlineWidth;
|
||||||
|
if (material != null) {
|
||||||
|
material.setFloat("OutlineWidth", outlineWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutlinePreFilter getOutlinePreFilter() {
|
||||||
|
return outlinePreFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -23,8 +23,8 @@ public class SelectObjectOutliner {
|
|||||||
private final int width;
|
private final int width;
|
||||||
private boolean selected;
|
private boolean selected;
|
||||||
private ViewPort outlineViewport = null;
|
private ViewPort outlineViewport = null;
|
||||||
private OutlineFilter outlineFilter = null;
|
// private OutlineFilter outlineFilter = null;
|
||||||
|
private OutlineProFilter outlineFilter = null;
|
||||||
|
|
||||||
public SelectObjectOutliner(int width, FilterPostProcessor fpp, RenderManager renderManager, AssetManager assetManager, Camera cam) {
|
public SelectObjectOutliner(int width, FilterPostProcessor fpp, RenderManager renderManager, AssetManager assetManager, Camera cam) {
|
||||||
this.selected = false;
|
this.selected = false;
|
||||||
@@ -69,7 +69,8 @@ private void showOutlineFilterEffect(Spatial model, int width, ColorRGBA color)
|
|||||||
outlineViewport.attachScene(model);
|
outlineViewport.attachScene(model);
|
||||||
outlineViewport.addProcessor(outlineFpp);
|
outlineViewport.addProcessor(outlineFpp);
|
||||||
|
|
||||||
outlineFilter = new OutlineFilter(outlinePreFilter);
|
// outlineFilter = new OutlineFilter(outlinePreFilter);
|
||||||
|
outlineFilter = new OutlineProFilter(outlinePreFilter);
|
||||||
outlineFilter.setOutlineColor(color);
|
outlineFilter.setOutlineColor(color);
|
||||||
outlineFilter.setOutlineWidth(width);
|
outlineFilter.setOutlineWidth(width);
|
||||||
|
|
||||||
|
|||||||
@@ -10,17 +10,17 @@
|
|||||||
import pp.mdga.client.board.Outline.SelectObjectOutliner;
|
import pp.mdga.client.board.Outline.SelectObjectOutliner;
|
||||||
|
|
||||||
public class OutlineControl extends AbstractControl {
|
public class OutlineControl extends AbstractControl {
|
||||||
private int thickness = 4;
|
private static final int THICKNESS_DEFAULT = 6;
|
||||||
private final SelectObjectOutliner outlineOwn;
|
private final SelectObjectOutliner outlineOwn;
|
||||||
|
|
||||||
ColorRGBA color;
|
ColorRGBA color;
|
||||||
|
|
||||||
public OutlineControl(MdgaApp app, FilterPostProcessor fpp){
|
public OutlineControl(MdgaApp app, FilterPostProcessor fpp){
|
||||||
outlineOwn = new SelectObjectOutliner(thickness, fpp, app.getRenderManager(), app.getAssetManager(), app.getCamera());
|
outlineOwn = new SelectObjectOutliner(THICKNESS_DEFAULT, fpp, app.getRenderManager(), app.getAssetManager(), app.getCamera());
|
||||||
}
|
}
|
||||||
|
|
||||||
public OutlineControl(MdgaApp app, FilterPostProcessor fpp, Camera cam){
|
public OutlineControl(MdgaApp app, FilterPostProcessor fpp, Camera cam){
|
||||||
outlineOwn = new SelectObjectOutliner(thickness, fpp, app.getRenderManager(), app.getAssetManager(), cam);
|
outlineOwn = new SelectObjectOutliner(THICKNESS_DEFAULT, fpp, app.getRenderManager(), app.getAssetManager(), cam);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OutlineControl(MdgaApp app, FilterPostProcessor fpp, Camera cam, int thickness){
|
public OutlineControl(MdgaApp app, FilterPostProcessor fpp, Camera cam, int thickness){
|
||||||
|
|||||||
109
Projekte/mdga/client/src/main/resources/MatDefs/OutlinePro.frag
Normal file
109
Projekte/mdga/client/src/main/resources/MatDefs/OutlinePro.frag
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
uniform sampler2D m_Texture;
|
||||||
|
uniform sampler2D m_OutlineDepthTexture;
|
||||||
|
uniform sampler2D m_DepthTexture;
|
||||||
|
varying vec2 texCoord;
|
||||||
|
|
||||||
|
uniform vec2 m_Resolution;
|
||||||
|
uniform vec4 m_OutlineColor;
|
||||||
|
uniform float m_OutlineWidth;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 depth = texture2D(m_OutlineDepthTexture, texCoord);
|
||||||
|
vec4 depth1 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(m_OutlineWidth,m_OutlineWidth))/m_Resolution);
|
||||||
|
vec4 depth2 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(m_OutlineWidth,-m_OutlineWidth))/m_Resolution);
|
||||||
|
vec4 depth3 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(-m_OutlineWidth,m_OutlineWidth))/m_Resolution);
|
||||||
|
vec4 depth4 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(-m_OutlineWidth,-m_OutlineWidth))/m_Resolution);
|
||||||
|
vec4 depth5 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(0.,m_OutlineWidth))/m_Resolution);
|
||||||
|
vec4 depth6 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(0.,-m_OutlineWidth))/m_Resolution);
|
||||||
|
vec4 depth7 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(m_OutlineWidth,0.))/m_Resolution);
|
||||||
|
vec4 depth8 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(-m_OutlineWidth,0.))/m_Resolution);
|
||||||
|
vec4 color = texture2D(m_Texture, texCoord);
|
||||||
|
//如果是背景
|
||||||
|
float ratio=0.;
|
||||||
|
if(depth==vec4(0.) && (depth1 != depth || depth2 != depth || depth3 != depth || depth4 != depth||depth5 != depth || depth6 != depth || depth7 != depth || depth8 != depth)){
|
||||||
|
float dist=m_OutlineWidth;
|
||||||
|
//距离边的像素
|
||||||
|
vec4 nearDepth;
|
||||||
|
if(depth1 != depth){
|
||||||
|
for(float i=0.;i<m_OutlineWidth;i++){
|
||||||
|
nearDepth = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(i,i))/m_Resolution);
|
||||||
|
if(nearDepth != depth){
|
||||||
|
dist = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
if(depth2 != depth){
|
||||||
|
for(float i=0.;i<m_OutlineWidth;i++){
|
||||||
|
nearDepth = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(i,-i))/m_Resolution);
|
||||||
|
if(nearDepth != depth){
|
||||||
|
dist = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
if(depth3 != depth){
|
||||||
|
for(float i=0.;i<m_OutlineWidth;i++){
|
||||||
|
nearDepth = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(-i,i))/m_Resolution);
|
||||||
|
if(nearDepth != depth){
|
||||||
|
dist = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
if(depth4 != depth){
|
||||||
|
for(float i=0.;i<m_OutlineWidth;i++){
|
||||||
|
nearDepth = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(-i,-i))/m_Resolution);
|
||||||
|
if(nearDepth != depth){
|
||||||
|
dist = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
if(depth5 != depth){
|
||||||
|
for(float i=0.;i<m_OutlineWidth;i++){
|
||||||
|
nearDepth = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(0.,i))/m_Resolution);
|
||||||
|
if(nearDepth != depth){
|
||||||
|
dist = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
if(depth6 != depth){
|
||||||
|
for(float i=0.;i<m_OutlineWidth;i++){
|
||||||
|
nearDepth = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(0.,-i))/m_Resolution);
|
||||||
|
if(nearDepth != depth){
|
||||||
|
dist = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
if(depth7 != depth){
|
||||||
|
for(float i=0.;i<m_OutlineWidth;i++){
|
||||||
|
nearDepth = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(i,0.))/m_Resolution);
|
||||||
|
if(nearDepth != depth){
|
||||||
|
dist = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
if(depth8 != depth){
|
||||||
|
for(float i=0.;i<m_OutlineWidth;i++){
|
||||||
|
nearDepth = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(-i,0.))/m_Resolution);
|
||||||
|
if(nearDepth != depth){
|
||||||
|
dist = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//0:场景颜色 1:outline颜色
|
||||||
|
ratio = clamp(1.- dist/m_OutlineWidth,0.,1.);
|
||||||
|
//float off = (1.-ratio*ratio)*(1.-ratio*ratio);
|
||||||
|
gl_FragColor = color*(1.-ratio) +m_OutlineColor*ratio;
|
||||||
|
//gl_FragColor = m_OutlineColor;
|
||||||
|
}else{
|
||||||
|
gl_FragColor = color;
|
||||||
|
}
|
||||||
|
//debug
|
||||||
|
//gl_FragColor = vec4(0.,(1.-ratio),0.,1.);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MaterialDef Cartoon Edge {
|
||||||
|
|
||||||
|
MaterialParameters {
|
||||||
|
Int NumSamples
|
||||||
|
Int NumSamplesDepth
|
||||||
|
Texture2D Texture
|
||||||
|
Texture2D OutlineDepthTexture
|
||||||
|
Texture2D DepthTexture
|
||||||
|
Vector2 Resolution
|
||||||
|
Color OutlineColor
|
||||||
|
Float OutlineWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
Technique {
|
||||||
|
VertexShader GLSL100: MatDefs/SelectObjectOutliner/Post15.vert
|
||||||
|
FragmentShader GLSL100: MatDefs/OutlinePro.frag
|
||||||
|
|
||||||
|
WorldParameters {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user