Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Dumblecore

Pages: [1]
1
German corner / Re: Licht + Shader
« on: September 26, 2013, 08:03:40 pm »
Super danke :) hab jetzt noch etwas rumprobiert und jetzt funktionierts

2
German corner / Licht + Shader
« on: September 25, 2013, 01:16:18 pm »
Hallo,
ich versuche gerade einen Tag/Nacht-Zyklus zu erstellen. Es klappt soweit auch alles wunder bar, bis auf eine Sache:
Mein Terrain bleibt immer gleich hell. Egal, ob ich das Ambient-Light verändere, oder das Terrain durch eine Lichtquelle beleuchte. Es bleibt immer genau gleich. Meine Idee war, dass das irgendwie mit dem Splat-Map-Shader zusammenhängt, den ich verwende... Aber wie kann ich das dann beheben.

hier noch meine Methode zur Erstellung des Terrains:
Code: [Select]
private void loadTerrain() throws Exception{
TextureInfo ti = new TextureInfo(TextureManager.getInstance().getTextureID("grass"));
ti.add(TextureManager.getInstance().getTextureID("sand"), TextureInfo.MODE_MODULATE);
ti.add(TextureManager.getInstance().getTextureID("stone"), TextureInfo.MODE_MODULATE);
ti.add(TextureManager.getInstance().getTextureID("alpha"), TextureInfo.MODE_MODULATE);

ground = Loader.load3DS(new FileInputStream("data/world/Terrain.3ds"), 20f)[0];
ground.setTexture(ti);
ground.rotateX(-(float)Math.PI/2f);
ground.setSpecularLighting(true);
Game.world.addObject(ground);
ground.build();
ground.compileAndStrip();
ground.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);

String fragSource = Loader.loadTextFile("data/misc/fragmentshader.glsl");
String vertexSource = Loader.loadTextFile("data/misc/vertexshader.glsl");
GLSLShader shader = new GLSLShader(vertexSource, fragSource);
shader.setStaticUniform("Grass", 0);
shader.setStaticUniform("Sand", 1);
shader.setStaticUniform("Stone", 2);
shader.setStaticUniform("Alpha", 3);
ground.setRenderHook(shader);
}

3
Projects / Re: Thinking about some RPG..Android version.
« on: September 11, 2013, 10:52:40 pm »
You could try this site:
http://www.reinerstilesets.de/3d-grafiken/

Or maybe TurboSquid

Maybe I can share some of my own models some time in the future (when they're finished)

4
German corner / Re: Probleme mit Splat-Mapping
« on: September 08, 2013, 01:02:42 am »
Super danke für die Antwort :D
Die GLSLShader-Klasse geht wirklich viel einfacher^^
Die Units hab ich jetzt auch richtig gesetzt und am Fragment-Shader noch etwas rumgespielt

Wen die Shader vllt noch jemand braucht:

Fragment:
Code: [Select]
uniform sampler2D Grass;
uniform sampler2D Sand;
uniform sampler2D Stone;
uniform sampler2D Alpha;

varying vec4 texCoord;

void main()
{

    vec4 texel0 = texture2D(Grass, gl_TexCoord[0].xy * 4.0).rgba;//Faktor kann man nach belieben ändern
    vec4 texel1 = texture2D(Sand, gl_TexCoord[0].xy*4.0).rgba;
    vec4 texel2 = texture2D(Stone, gl_TexCoord[0].xy*4.0).rgba;
    vec4 mixmapTexel = texture2D(Alpha, gl_TexCoord[0].xy).rgba;

    texel0 *= mixmapTexel.r;
    texel1 = mix(texel0,  texel1, mixmapTexel.g);
    vec4 outColor = mix(texel1, texel2, mixmapTexel.b);
   
    gl_FragColor = outColor;
}

Vertex:
Code: [Select]
varying vec4 VertexPosition;

void main() {

    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = ftransform();
    //VertexPosition = gl_ModelViewMatrix * gl_Vertex;
    VertexPosition = gl_Vertex;
}

So und hier nochmal das Ergebnis (nicht besonders schön, aber war ja auch nur ein Test):

5
German corner / Probleme mit Splat-Mapping
« on: September 07, 2013, 02:58:27 pm »
Ich habe heute versucht via Splat-Mapping mehrere Texturen auf ein Terrain Objekt zu malen. Da ich mit Shadern allerdings wenig Erfahrung habe (eigentlich mehr oder weniger gar keine), habe ich versucht das Normal-Mapping Beispiel aus dem Wiki zu modifizieren. Das ganze hat (wie zu erwarten) nicht wirklich geklappt. Mein Ziel ist es eigentlich die Texturen so ähnlich zu malen, wie in Egons RPG, aber irgendwie werden nur alle Texturen ineinander "gematscht". Rufe ich den Shader richtig auf? Und was macht denn eigentlich die Zeile: "ARBShaderObjects.glUniform1iARB(int, int)?

Hier mein Ergebnis:


Das ist der Code, den ich verwendet habe:

Aufruf des Shaders:
Code: [Select]
TextureManager tm = TextureManager.getInstance();
tm.addTexture("grass" , new Texture("data/textures/grass.png"));
tm.addTexture("sand", new Texture("data/textures/sand.png"));
tm.addTexture("stone", new Texture("data/texture/stone.png"));
tm.addTexture("alpha", new Texture("data/texture/SplatMap.png"));

TextureInfo ti = new TextureInfo(TextureManager.getInstance().getTextureID("grass"));
ti.add(TextureManager.getInstance().getTextureID("sand"), TextureInfo.MODE_MODULATE);
ti.add(TextureManager.getInstance().getTextureID("stone"), TextureInfo.MODE_MODULATE);
ti.add(TextureManager.getInstance().getTextureID("alpha"), TextureInfo.MODE_MODULATE);

buffer = new FrameBuffer(1280, 720, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.MODE_OPENGL);
buffer.setPaintListener(this);

world = new World();
world.setAmbientLight(200, 200, 200);

Object3D ground = Loader.load3DS(new FileInputStream("data/world/Terrain.3ds"), 20f)[0];
//retexture(ground, "grass", 160); //TODO right tile scale
ground.setTexture(ti);
ground.rotateX(-(float)Math.PI/2f);
world.addObject(ground);
ground.build();
ground.compileAndStrip();
ground.setRenderHook(new SplatMapShader());

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 150);
cam.moveCamera(Camera.CAMERA_MOVEUP, 170);
cam.lookAt(new SimpleVector());

Der Shader selbst
Code: [Select]
public class SplatMapShader implements IRenderHook{

private String fragSource = Loader.loadTextFile("data/misc/fragmentshader.glsl");
private String vertexSource = Loader.loadTextFile("data/misc/vertexshader.glsl");
private int prg = 0;
private int fragShade = 0;
private int vertShade = 0;
private boolean init = false;

private int alpha = 0;
private int grass = 0;
private int sand = 0;
private int stone = 0;

@Override
public void afterRendering(int polyID) {
ARBShaderObjects.glUseProgramObjectARB(0);
}

@Override
public void beforeRendering(int polyID) {
if(!init){
init();
}
ARBShaderObjects.glUseProgramObjectARB(prg);
//Was machen diese Zeilen?
ARBShaderObjects.glUniform1iARB(alpha, 1);//<--
ARBShaderObjects.glUniform1iARB(grass, 1);//<--
ARBShaderObjects.glUniform1iARB(sand, 1);//<--
ARBShaderObjects.glUniform1iARB(stone, 1);//<--

}

private void init() {
//Initializing program
prg=ARBShaderObjects.glCreateProgramObjectARB();

//initializing fragment shader
fragShade=ARBShaderObjects.glCreateShaderObjectARB(ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);
//loading & compiling fragment shader from source
byte[] src=fragSource.getBytes();
ByteBuffer shader = BufferUtils.createByteBuffer(src.length);
shader.put(src);
shader.flip();

ARBShaderObjects.glShaderSourceARB(fragShade, shader);

ARBShaderObjects.glCompileShaderARB(fragShade);
ARBShaderObjects.glAttachObjectARB(prg, fragShade);

//repeating stuff for vertex shader
vertShade=ARBShaderObjects.glCreateShaderObjectARB(ARBVertexShader.GL_VERTEX_SHADER_ARB);

src=vertexSource.getBytes();
ByteBuffer shader2 = BufferUtils.createByteBuffer(src.length);
shader2.put(src);
shader2.flip();

ARBShaderObjects.glShaderSourceARB(vertShade, shader2);

ARBShaderObjects.glCompileShaderARB(vertShade);
ARBShaderObjects.glAttachObjectARB(prg, vertShade);

//linking program
ARBShaderObjects.glLinkProgramARB(prg);

Logger.log("Shader compiled!", Logger.MESSAGE);

alpha = getLocation("Alpha");
grass = getLocation("Grass");
sand = getLocation("Sand");
stone = getLocation("Stone");
System.out.println(alpha + "," + grass + "," + sand + ","+ stone);

init = true;
}

private int getLocation(String n) {
byte[] nb=n.getBytes();
ByteBuffer name = BufferUtils.createByteBuffer(nb.length+1);
name.put(nb);
name.put((byte)0);
name.flip();
return ARBShaderObjects.glGetUniformLocationARB(prg, name);
}



@Override
public void onDispose() {
ARBShaderObjects.glDeleteObjectARB(fragShade);
ARBShaderObjects.glDeleteObjectARB(vertShade);
ARBShaderObjects.glDeleteObjectARB(prg);
}

@Override
public boolean repeatRendering() {
return false;
}

Hier der fragment-shader:
Code: [Select]
uniform sampler2D Alpha;
uniform sampler2D Grass;
uniform sampler2D Stone;
uniform sampler2D Sand;

varying vec4 texCoord;

void main(void)
{
   vec4 alpha   = texture2D( Alpha, texCoord.xy );
   vec4 tex0    = texture2D( Grass, texCoord.xy * 4.0 ); // Tile
   vec4 tex1    = texture2D( Sand,  texCoord.xy * 4.0 ); // Tile
   vec4 tex2    = texture2D( Stone, texCoord.xy * 4.0 ); // Tile

   tex0 *= alpha.r; // Red channel
   tex1 = mix( tex0, tex1, alpha.g ); // Green channel
   vec4 outColor = mix( tex1, tex2, alpha.b ); // Blue channel
   
   gl_FragColor = outColor;
}

und hier noch der vertex-shader:
Code: [Select]
varying vec4 VertexPosition;

void main() {

    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = ftransform();
    //VertexPosition = gl_ModelViewMatrix * gl_Vertex;;
    VertexPosition = gl_Vertex;
}

6
Support / Re: Creating/Loading a world for a RPG
« on: September 05, 2013, 10:58:25 pm »
Well with bigger project i meant to say something like: "It's easily going to take more than a year to code this"
Although i noticed it'll probably take even longer due to my lack of knowledge in 3D programming stuff.  ;)

I guess i will approach it quite similar to your way. Thanks you helped me a lot.


7
Support / Creating/Loading a world for a RPG
« on: September 05, 2013, 05:27:19 pm »
During the last few weeks i tried to learn the basics of jPCT. Now i want to start my first, bigger project.
Therefore i need a world (which will be rather big), but i've got no idea how to create this world, and load it later on.

First i thoght of generating the map from a heightmap (don't know if that is a good approach), but i don't know how to fill this generated world with life. I want to have accessible buildings with furniture and stuff, but i do also want to have a vast (well maybe not soo vast) outdoor area. So are there any tools to achieve this goal, or do i have to add every single chair by hand?

Pages: [1]