Hello out there! I hope my Question isn’t too dumb but i really can’t figure it out
I need 3 special Values in my Shader: 2 Floats for a Position and 1 Integer or Float for a Size. That Values would be different for each Vertex. Maybe i could “missuse” the vertex normal data for that, but thats not really a good solution i think.
As i understand it, vertex data is set by the Mesh.setBuffer(Type, components,Buffer) Method. “in[Type]” should then give the shader access to the data. So i could choose type “TexCoord” for my 2 position floats and the type “Size” for my size value.
But this seems to only work for inPosition,inNormal,inColor,inTexCoord. I tried to create a Buffer of the Type Size and then acces it in the Vertex Shader like its done with inColor but it doesen’t work.
[java]mesh.setBuffer(VertexBuffer.Type.Size, 1, sizeBuffer);[/java]
(.j3md, see lines 8 and 30)
[java]
MaterialDef Unshaded {
MaterialParameters {
Texture2D ColorMap
Texture2D LightMap
Color Color ( Color )
Boolean VertexColor
Boolean VertexSize
Boolean SeparateTexCoord
Boolean DirectViewspace
// Texture of the glowing parts of the material
Texture2D GlowMap
// The glow color of the object
Color GlowColor
}
Technique {
VertexShader GLSL100: MatDefs/UnshadedPointSprite.vert
FragmentShader GLSL100: MatDefs/UnshadedPointSprite.frag
WorldParameters {
WorldViewProjectionMatrix
}
Defines {
SEPARATE_TEXCOORD : SeparateTexCoord
HAS_COLORMAP : ColorMap
HAS_LIGHTMAP : LightMap
HAS_VERTEXCOLOR : VertexColor
HAS_VERTEXSIZE : VertexSize
HAS_COLOR : Color
IS_DIRECTVIEWSPACE: DirectViewspace
}
}
Technique PreNormalPass {
VertexShader GLSL100 : Common/MatDefs/SSAO/normal.vert
FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag
WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
NormalMatrix
}
RenderState {
}
}
Technique Glow {
VertexShader GLSL100: Common/MatDefs/Misc/Unshaded.vert
FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag
WorldParameters {
WorldViewProjectionMatrix
}
Defines {
HAS_GLOWMAP : GlowMap
HAS_GLOWCOLOR : GlowColor
HAS_COLORMAP // Must be passed so that Unshaded.vert exports texCoord.
}
}
}
[/java]
(.vert see lines 18-21)
[java]uniform mat4 g_WorldViewProjectionMatrix;
attribute vec3 inPosition;
varying vec4 tempPos;
#if defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
#define NEED_TEXCOORD1
#endif
#ifdef NEED_TEXCOORD1
attribute vec2 inTexCoord;
varying vec2 texCoord1;
#endif
#ifdef SEPARATE_TEXCOORD
attribute vec2 inTexCoord2;
varying vec2 texCoord2;
#endif
#ifdef HAS_VERTEXCOLOR
attribute vec4 inColor;
varying vec4 vertColor;
#endif
#ifdef HAS_VERTEXSIZE
attribute float inSize;
varying float vertSize;
#endif
void main(){
#ifdef NEED_TEXCOORD1
texCoord1 = inTexCoord;
#endif
#ifdef SEPARATE_TEXCOORD
texCoord2 = inTexCoord2;
#endif
#ifdef HAS_VERTEXCOLOR
vertColor = inColor;
#endif
gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
gl_PointSize = 250.0 / gl_Position.w;
tempPos = gl_Position;
}[/java]
(.frag see lines 36-38 and 48)
[java]uniform vec4 m_Color;
varying vec4 tempPos;
const float C = 1.0;
const float far = 2^40;
const float offset = 1.0;
const int k = 32;//bits of depthbuffer (16/24/32)
const float zn = 1.0;
const float zf = 2^40;
const float K = ( (2^k) - 1 ) / log( zf / zn );
#if defined(HAS_GLOWMAP) || defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
#define NEED_TEXCOORD1
#endif
#ifdef HAS_COLORMAP
uniform sampler2D m_ColorMap;
#endif
#ifdef NEED_TEXCOORD1
varying vec2 texCoord1;
#endif
#ifdef HAS_LIGHTMAP
uniform sampler2D m_LightMap;
#ifdef SEPARATE_TEXCOORD
varying vec2 texCoord2;
#endif
#endif
#ifdef HAS_VERTEXCOLOR
varying vec4 vertColor;
#endif
#ifdef HAS_VERTEXSIZE
varying float vertSize;
#endif
void main(){
vec4 color = vec4(1.0);
#ifdef HAS_VERTEXCOLOR
color *= vertColor;
#endif
#ifdef HAS_COLORMAP
color = texture2D(m_ColorMap,vec2(vertSizegl_PointCoord.x,vertSize*(1-gl_PointCoord.y)));
#endif
#ifdef HAS_COLOR
color *= m_Color;
#endif
#ifdef HAS_LIGHTMAP
#ifdef SEPARATE_TEXCOORD
color.rgb *= texture2D(m_LightMap, texCoord2).rgb;
#else
color.rgb *= texture2D(m_LightMap, texCoord1).rgb;
#endif
#endif
gl_FragColor = color;
}[/java]
When i execute the shader always a 0 is passed as size although i set a 1.0f in the size buffer.
Am i missing something?