package com.haxademic.demo.draw.shapes.shader;

import com.haxademic.core.app.P;
import com.haxademic.core.app.PAppletHax;
import com.haxademic.core.debug.DebugView;
import com.haxademic.core.draw.context.PG;
import com.haxademic.core.draw.filters.pshader.BlurProcessingFilter;
import com.haxademic.core.draw.image.ImageUtil;
import com.haxademic.core.file.FileUtil;
import com.haxademic.core.hardware.mouse.Mouse;
import com.haxademic.core.media.DemoAssets;

import processing.core.PGraphics;
import processing.core.PImage;
import processing.core.PShape;
import processing.opengl.PShader;

public class Demo_Sphere_BumpMap
extends PAppletHax {
	public static void main(String args[]) { arguments = args; PAppletHax.main(Thread.currentThread().getStackTrace()[1].getClassName()); }

	// Ported into haxademic from: 
	// https://github.com/codeanticode/pshader-experiments
	
	protected PImage texture;
	protected PGraphics bumpMap;
	protected PGraphics specMap;
	protected PShape sphere;
	protected PShader bumpMapShader;

	protected void firstFrame() {
		// load textures
		texture = DemoAssets.textureJupiter();
		bumpMap = ImageUtil.imageToGraphics(DemoAssets.textureJupiter());
		specMap = ImageUtil.imageToGraphics(DemoAssets.textureJupiter());
		
		// adjust texture, since we're reusing the texture map for alternate purposes
		BlurProcessingFilter.instance(p).setBlurSize(2);
		BlurProcessingFilter.instance(p).setSigma(1);
		for(int i=0; i < 5; i++) BlurProcessingFilter.instance(p).applyTo(bumpMap);
		DebugView.setTexture("bumpMap", bumpMap);
		
		ImageUtil.copyImage(bumpMap, specMap);
		
		// load shader
		bumpMapShader = loadShader(
				FileUtil.getPath("haxademic/shaders/vertex/bump-mapping-frag.glsl"), 
				FileUtil.getPath("haxademic/shaders/vertex/bump-mapping-vert.glsl")
				);
		bumpMapShader.set("texMap", texture);
		bumpMapShader.set("bumpMap", bumpMap);
		bumpMapShader.set("specularMap", specMap);
		bumpMapShader.set("bumpScale", 0.05f);
		
		// create sphere
		p.sphereDetail(150);
		sphere = createShape(P.SPHERE, 200);
		sphere.setStroke(false);
		sphere.setSpecular(color(125));
		sphere.setShininess(10);
	}
	
	protected void drawApp() {
		// set context
		background(0);
		PG.setDrawCorner(p);
		PG.setCenterScreen(p);
		
		// light source emitting from the right of the camera
		p.pointLight(255, 255, 255, P.map(Mouse.xNorm, 0, 1, 1500, -1500), 0, 500);
		
		// update shader
		bumpMapShader.set("bumpScale", Mouse.yNorm * 0.1f);
		
		// draw from center
		p.shader(bumpMapShader);
		p.pushMatrix();
		p.rotateY(P.map(p.mouseX, 0, p.width, 0, P.TWO_PI));
		p.shape(sphere);
		p.popMatrix();	  
	}

}

@@ -116,16 +116,111 @@
 letHax;%0A
+import com.haxademic.core.app.config.AppSettings;%0Aimport com.haxademic.core.app.config.Config;%0A
 import c
@@ -366,16 +366,81 @@
 Filter;%0A
+import com.haxademic.core.draw.filters.pshader.BrightnessFilter;%0A
 import c
@@ -598,24 +598,24 @@
 ore.
-media.DemoAssets
+render.FrameLoop
 ;%0A%0Ai
@@ -1195,148 +1195,392 @@
 oid 
-firstFrame() %7B%0A%09%09// load textures%0A%09%09texture = DemoAssets.textureJupiter();%0A%09%09bumpMap = ImageUtil.imageToGraphics(DemoAssets.textureJupiter()
+config() %7B%0A%09%09Config.setAppSize(1024, 1024);%0A%09%09Config.setProperty(AppSettings.LOOP_FRAMES, 900);%0A%09%7D%0A%09%0A%09protected void firstFrame() %7B%0A%09%09// load textures%0A%09%09texture = P.getImage(%22images/textures/space/moon-layers/color.jpg%22); // DemoAssets.textureJupiter();%0A%09%09bumpMap = ImageUtil.imageToGraphics(P.getImage(%22images/textures/space/moon-layers/displacement.jpg%22));%0A%09%09ImageUtil.flipV(bumpMap
 );%0A%09
@@ -1620,35 +1620,15 @@
 ics(
-DemoAssets.textureJupiter()
+bumpMap
 );%0A%09
@@ -1808,16 +1808,18 @@
 gma(1);%0A
+//
 %09%09for(in
@@ -1972,24 +1972,204 @@
 , specMap);%0A
+%09%09BrightnessFilter.instance(p).setBrightness(0.25f);%0A%09%09BrightnessFilter.instance(p).applyTo(specMap);%0A%09%09for(int i=0; i %3C 2; i++) BlurProcessingFilter.instance(p).applyTo(specMap);%0A
 %09%09%0A%09%09// load
@@ -2608,11 +2608,24 @@
 RE, 
-200
+p.height * 0.35f
 );%0A%09
@@ -3109,16 +3109,18 @@
 trix();%0A
+//
 %09%09p.rota
@@ -3166,16 +3166,55 @@
 O_PI));%0A
+%09%09p.rotateY(FrameLoop.progressRads());%0A
 %09%09p.shap

Update Demo_Sphere_BumpMap.java