glsl vertex displacement mapping

Hi folks

I finally managed to create simple vertex displacement in shader, but I get some weird anomalies.

I get this result using fully black image as displacement map and color map.

this seems to come with

tex2.setFormat(Texture.FRgba32)

I’m using 1.7.0 on 64bit ubuntu

So, hopefully someone has a solution to get this fixed.

This could have many causes. We need to know a bit more about your setup and how your code works before we can make accurate guesses what the problem could be.

Ok, your response wasn’t actually surprise :wink:

I uploaded my test case
http://www.upload.ee/files/444592/glsl.zip.html
Click download button there.

next question as I got glsl working in windows.

is it possible to get this tex2D_bilinear function working on panda?

currently I’m getting “ERROR: 0:7: error(#132) Syntax error: ‘uniform’ parse error”

//GLSL
uniform sampler2D displacementMap;

#define textureSize 256.0
#define texelSize 1.0 / 256.0

vec4 tex2D_bilinear( uniform sampler2D tex, vec2 t )
{
    vec2 f = fract( t.xy * textureSize );
    vec4 t00 = texture2D( tex, t );
    vec4 t10 = texture2D( tex, t + vec2( texelSize, 0.0 ));
    vec4 tA = mix( t00, t10, f.x );
    vec4 t01 = texture2D( tex, t + vec2( 0.0, texelSize ) );
    vec4 t11 = texture2D( tex, t + vec2( texelSize, texelSize ) );
    vec4 tB = mix( t01, t11, f.x );
    return mix( tA, tB, f.y );
}	
    

void main(void)
{
	vec4 newVertexPos;
	vec4 dv;
	float df;
	
	gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
	
	dv = tex2D_bilinear( displacementMap, gl_MultiTexCoord0.xy );
    //dv = texture2D( displacementMap, gl_MultiTexCoord0.xy );
	
	df = 0.30*dv.x + 0.59*dv.y + 0.11*dv.z;
	newVertexPos = vec4(gl_Normal * df * 10.0, 0.0) + gl_Vertex;

	gl_Position = gl_ModelViewProjectionMatrix *  newVertexPos;
}

More questions: :cry:

Why I’m seeing four circles, my bitmap olny has one in the middle
(this is without tex2D_bilinear function)

And same artifacts are in windows also :confused:

uhh, got it working… seems

tex2.setFormat(Texture.FRgba32)

is not nessecary

But still looking forward about that tex2D_bilinear function issue.

At least I’m happy again. :smiley:

Here is my python code

import sys
import direct.directbase.DirectStart
from pandac.PandaModules import Texture, TextureStage, Shader

cube = loader.loadModel("plane.egg")
cube.reparentTo(render)

tex1 = loader.loadTexture('plane_copy.png')

tex2 = loader.loadTexture('plane.png')
#tex2.setMinfilter( Texture.FTNearest )
#tex2.setFormat(Texture.FRgba32)

tex3 = loader.loadTexture('plane_copy.png')

cube.setTexture(tex3)
shader = Shader.load(Shader.SLGLSL, "./vertexprog.glsl", "./fragmentprog.glsl","") 
cube.setShaderInput("colorMap", tex1)
cube.setShaderInput("displacementMap", tex2)
cube.setShader(shader)

base.accept("escape", sys.exit)
base.accept("o", base.oobe)
#base.toggleWireframe()

run()