Hello all,

On 11/29/2012 12:02 PM, Alexander Lang wrote:
> it would help if you could specify your problem. Do you have a concrete
> issue with your application using OpenSG? Do you want to port an
> application from OpenGL 1.x to modern OpenGL using OpenSG?
>
> The light states you mentioned are part of the fixed-function pipeline.
> With shaders you are entirely free to do whatever you want, the downside
> is that your host code and therefore OpenSG cannot know anything about it.
> So if you want to work with these light states in your shader you have to
> define them as uniforms by yourself, AFAIK OpenSG does not pre-define
> these anywhere.

we have the information which lights are active as built in uniforms 
('OSGActiveLightsMask' or 'OSGLight?Active' with ? = 0,...,7), see below.

> The uniforms OpenSG does predefine are 'OSGWorldMatrix' and 'OSGViewMatrix'.
> Once added, they are set by OpenSG and can be accessed in your GLSL code.
> Unfortunately, OpenSG does not pre-define the projection matrix as generic
> uniform. That means you need to use GLSL compatibility mode (as in e.g.
> #version 330 compatibility) to access the projection matrix as
> gl_ProjectionMatrix in your GLSL code.

there is 'OSGProjectionMatrix', which should contain the projection. For 
the full list of OpenSG 'built in' uniforms see: 
Source/System/State/Shader/Variables/OSGShaderVariableOSG.{h,cpp}.

> Also, custom attributes are available if you enable vertexattribfuncs in
> your build. For example:
>
> vertexShader->setProgramAttribute(OSG::ShaderConstants::PositionsIndex,
> "vertexPos");
>
> Then you can access "vertexPos" in your shader code like this:
>
> in vec3 vertexPos;
> int main()
> {
>    //transform vertexPos;
>    //write to gl_Position
> }

ha, neat, I did not know that works now :)

> The problem is when you do anything beyond standard model-view-projection
> transformation, things like intersection tests or frustum culling as
> provided by OpenSG won't work as expected anymore, since OpenSG is
> naturally unaware of these transformations.
>
> The texture parameters GL_REPLACE, GL_MODULATE, etc. can be set within
> OpenSG with OSG::TextureEnvChunk.

yes, although when running a shader it is up to the shader how it 
combines texture information with e.g. lighting or per-vertex colors, so 
that texture state only applies to fixed-function texturing.

> Uniforms are added with
> OSGShaderProgram::addUniformVariable(<name>, <value>);
> where <value> can be any primitive type, OSGMatrices and -Vectors, and
> multi-fields thereof.

I *think* structures works the same way as in pure OpenGL: from the 
application side you set the members of a structure individually. So if 
your shader has (I actually don't know the right GLSL syntax for this, 
but hopefully the idea is clear):

struct LightData
{
    vec4 position;
    vec4 color;
};

uniform LightData ld;

Then your application would set uniforms with these names:

"ld.position"
"ld.color"

and you'd just use addUniformVariable("ld.position", OSG::Vec4(0.f, 
0.2f, 0.2f, 0.f)); However, I have not tried this, so this is really 
just a guess.

        Cheers,
                Carsten

------------------------------------------------------------------------------
Keep yourself connected to Go Parallel: 
VERIFY Test and improve your parallel project with help from experts 
and peers. http://goparallel.sourceforge.net
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to