It is currently Sat Aug 22, 2020 12:24 pm


All times are UTC




Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Shading the volume... I need help
PostPosted: Thu Nov 11, 2010 9:16 pm 

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
So I looked at this post:
viewtopic.php?p=450#p450
and then followed the tutorial:
http://www.ogre3d.org/tikiwiki/Getting+ ... +Materials
and so what I have is ColoredCubicVoxel.material
Code:
vertex_program ColouredCubicVoxelVP cg
{
    source ColouredCubicVoxel.cg
    entry_point ColouredCubicVoxelVP
    profiles vs_3_0 vs_2_x vs_2_0 vs_1_1 vp40 vp30 vp20 arbvp1

    default_params
    {
        param_named_auto world world_matrix
        param_named_auto viewProj viewproj_matrix
    }
}


fragment_program ColouredCubicVoxelFP cg
{
    source ColouredCubicVoxel.cg
    entry_point ColouredCubicVoxelFP
    profiles ps_3_x ps_3_0 ps_2_x ps_2_0 ps_1_4 ps_1_3 ps_1_2 ps_1_1 fp40 fp30 fp20 arbfp1

    default_params
    {
    }
}

material ColouredCubicVoxel
{
    technique
    {               
        pass
        {                   
            // Vertex program reference
            vertex_program_ref ColouredCubicVoxelVP
            {
            }

            // Fragment program
            fragment_program_ref ColouredCubicVoxelFP
            {
            }   

            texture_unit
            {
                texture Dirt.jpg 2d
                filtering anisotropic
                max_anisotropy 16
            }       
        }
    }
}


and ColouredCubicVoxel.cg
Code:
void ColouredCubicVoxelVP(
    float4 inPosition    : POSITION,
    float4 inNormal        : NORMAL,

    out float4 outClipPosition        : POSITION,
    out float4 outWorldPosition    : TEXCOORD0,
    out float4 outWorldNormal    : TEXCOORD1,

    uniform float4x4 world,
    uniform float4x4 viewProj
    )
{   
    //Compute the world space position
    outWorldPosition = mul(world, inPosition);   
   
    //Just pass though the normals without transforming them in any way. No rotation occurs.
    outWorldNormal = inNormal;

    //Compute the clip space position
    outClipPosition = mul(viewProj, outWorldPosition);
}

void ColouredCubicVoxelFP(
    float4 inPosition        : POSITION,
    float4 inWorldPosition    : TEXCOORD0,
    float4 inWorldNormal    : TEXCOORD1,

    uniform sampler2D heightMap : TEXUNIT0,
   
    out float4 result        : COLOR)
{   
    inWorldNormal = normalize(inWorldNormal);
   
    float3 col;
   
    //World position is used as texture coordinates. Choose which
    //two components of world position to use based on normal. Could
    //optionally use a different texture for each face here as well.
    if(inWorldNormal. x > 0.5)
    {
        col = tex2D(heightMap, inWorldPosition.yz);
    }
   
    if(inWorldNormal. x < -0.5)
    {
        col = tex2D(heightMap, inWorldPosition.yz);
    }
   
    if(inWorldNormal. y > 0.5)
    {
        col = tex2D(heightMap, inWorldPosition.xz);
    }
   
    if(inWorldNormal. y < -0.5)
    {
        col = tex2D(heightMap, inWorldPosition.xz);
    }
   
    if(inWorldNormal. z > 0.5)
    {
        col = tex2D(heightMap, inWorldPosition.xy);
    }
   
    if(inWorldNormal. z < -0.5)
    {
        col = tex2D(heightMap, inWorldPosition.xy);
    }
   
    result = float4(col, 1.0);
}


and I call it in my program with
Code:
PVWorld->convertToMesh(Ogre::String("Sphere"));
   Ogre::Entity* lEntity = mSceneMgr->createEntity(Ogre::String("Sphere"));
   Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
   lEntity->setMaterialName("ColouredCubicVoxel");
   node->attachObject(lEntity);


and I get massive massive errors, that I have no idea what they mean. The only thing that means anything to me is invalidparametersexception, but I don't see where I'm supposed to be putting stuff in


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Thu Nov 11, 2010 9:23 pm 

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
Also, just having those 2 files being loaded causes the error these are the errors when the .material and .cg are being loaded in
Code:
First-chance exception at 0x7613b727 in OgreProject.exe: Microsoft C++ exception: Ogre::InvalidParametersException at memory location 0x0034ea14..
First-chance exception at 0x7613b727 in OgreProject.exe: Microsoft C++ exception: Ogre::InvalidParametersException at memory location 0x0034eb58..
First-chance exception at 0x7613b727 in OgreProject.exe: Microsoft C++ exception: Ogre::InternalErrorException at memory location 0x0034cb80..
'OgreProject.exe': Loaded 'C:\Windows\SysWOW64\hid.dll', Cannot find or open the PDB file
'OgreProject.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
First-chance exception at 0x5cd7e797 in OgreProject.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x5cd7e797 in OgreProject.exe: 0xC0000005: Access violation reading location 0x00000000.


if I take them out of the scripts folder, then I only get this error (but the program still runs, no crash or anything, just my big white sphere)
Code:
First-chance exception at 0x7613b727 in OgreProject.exe: Microsoft C++ exception: Ogre::InvalidParametersException at memory location 0x0047f158..
First-chance exception at 0x7613b727 in OgreProject.exe: Microsoft C++ exception: Ogre::InvalidParametersException at memory location 0x0047f29c..
First-chance exception at 0x7613b727 in OgreProject.exe: Microsoft C++ exception: Ogre::InternalErrorException at memory location 0x0047d2c4..


I really am at a complete loss, I have to go to a meeting right now, but I'll be back in an hour or two... if anyone could help out that would be amazing. Thanks.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Thu Nov 11, 2010 9:26 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
What do the errors say? You can also try cutting down the shader/material to make it as simple as you can, so that hopefully you can see where it's going wrong.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Thu Nov 11, 2010 10:00 pm 

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
You must have started your post right before I posted my 2nd part... the errors are in my 2nd post. I'm going to try and run exactly the tutorial and then modify my way up to your shaders.. but really it is all 100% new to me so it is kind of a guess and check style way of doing things.

By the way on a side note, is there a reason you guys could guess that it takes like 20 seconds for the tutorial framework application to go from the black screen to rendering? Is it jsut all the resources i'm loading - should I cut down on that by a lot? (it makes testing things kind of a pain when starting the program up takes 25-30 seconds a shot : /)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Thu Nov 11, 2010 10:06 pm 

Joined: Sun Oct 03, 2010 10:13 pm
Posts: 73
As I copied over the shaders from David's post and used them unmodified without any problem (if I remember correctly) maybe it's a problem with your system. Just guessing here, but maybe you should update your video card drivers? Or you need a graphics card with a higher shader version support (might depend on what you write in the Ogre materials)? I think Ogre would give you an error about this, though...

Made this post while you were posting, but I think it could still be right. It seems to be more of a general Ogre or software/hardware problem than anything with PolyVox. Maybe you're better off asking in the Ogre forums?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Thu Nov 11, 2010 10:20 pm 

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
I really don't know, did I put the 2 files together properly as far as you can tell? I'm running through the tutorial on the ogrewiki, but am getting a blank white screen : / I'm pretty sure my problem is with the actual texture.png part not being found correctly, and I don't really know how to solve that, but that probably is a question for ogre. I'll keep fiddling with it for the next few hours, I'm stuck at work anyways. I'm pretty much doing everything twice once at work and once at home, which is good because then the 2nd time I actually get to put it together super fast because I understand whats going on... but man its a total b figuring it out the first time lol.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Thu Nov 11, 2010 10:22 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Ok, a few points...

Firstly, you may find it easier to work with a debug build rather than a release build. That way when it crashes you'll have more chance to see what is going on. Messages such as 'Cannot find or open the PDB file' imply you are in release mode (though I could be wrong).

Secondly, the errors you have posted are from the output window and not that useful... what you really want to do is to find the Ogre.log file that Ogre creates. This will be far more specific about what went wrong.

Lastly, I actually had three files (.material, .cg, .program). You've combined two of them into one... maybe this is fine but I can't say for sure ;-)

paycheck wrote:
By the way on a side note, is there a reason you guys could guess that it takes like 20 seconds for the tutorial framework application to go from the black screen to rendering? Is it jsut all the resources i'm loading - should I cut down on that by a lot? (it makes testing things kind of a pain when starting the program up takes 25-30 seconds a shot : /)


You mean the Ogre tutorial framework? As AndiNo says, you might be better off asking that on the Ogre forums.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Thu Nov 11, 2010 11:24 pm 

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
Well, I did several things... I
a) split the files into 3 (not sure if this did anything, but w/e it is probably more correct)
b) ran in debug -> omg it worked (sort of, the sphere doesn't map barely anything, so then I added a plane, it maps perfectly on the plane, if I'm below the plane and look at the sphere the sphere goes crazy, if I'm above the plane and can see both then the sphere is solid but still crazy)
c) ran in release -> still get crazy errors.

So, I compared the logs between release and debug (after checking the .cfg files because I thought maybe there was some difference there which was being a bugger, but there wasn't anything different). The only difference in the log files, relating to colouredCubicVoxel is this:

Code:
15:53:07: Attempted to load Cg program 'ColouredCubicVoxelFP', but no suported profile was found.


I did the ogre google on this and found out that this is usually a driver based problem (funny that games don't have any issues on this comp though...? Also funny that it works in debug...) and I'm just going to lay it to rest on this comp till I try it at home. Also it crashes in openGL on debug, so yea, who the heck knows, I'll test on another machine.

Attachment:
below.jpg
below.jpg [ 177.86 KiB | Viewed 7012 times ]

Attachment:
abovewithsomepromise.jpg
abovewithsomepromise.jpg [ 189.14 KiB | Viewed 7011 times ]


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Fri Nov 12, 2010 12:24 am 

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
Attachment:
almostthere.jpg
almostthere.jpg [ 206.11 KiB | Viewed 6997 times ]
After 4+ hours of fiddling around I got to the point that andiNo got where I have it showing 16 times per face. My main problem was normals, which I can't figure out how to compute in the shader (I don't know where to stick the two lines...) Also, I seem to be completely unable to scale inWorldPosition.XX because no matter what I do (creating a new vector, dividing by a vector, etc, I litterally tried like 15 work arounds and all of them ended up giving me this error) error X6077: texld/texldb/texldp/dsx/dsy instructions with r# as source cannot be used inside dynamic conditional 'if' blocks etc...

Well, I'm about completely blocked here, I'm trying to figure out what the cg api is, but I haven't been able to find a complete one... I'm looking for a function that scales a float2 by a... scaler? float1 I imagine. Anyways, yea I just need to know how to scale that value, would be awesome.. Thanks!


Attachments:
stillbroken.jpg
stillbroken.jpg [ 121.95 KiB | Viewed 7005 times ]
Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Fri Nov 12, 2010 2:32 pm 

Joined: Sun Oct 03, 2010 10:13 pm
Posts: 73
If I understand correctly what you want to do you just have to scale your ManualObject in Ogre, not in the shader. Everything else related to this texture-multiple-times-on-face problem has been discussed in the "PolyVox and Ogre3D" thread.

Computing the normals in the shader:
The two lines mentioned by David in another thread are the very first thing in my ColouredCubicVoxelFP fragment/pixel shader. Of course you then have to delete any reference to things like "inNormal" etc because you are now using your calculated normals.

Cg is nearly the same as HLSL. Whenever you search for something specific just Google "HLSL yoursearch". I looked here for info very often: http://msdn.microsoft.com/en-us/library/bb509561%28VS.85%29.aspx

Scaling:
Usually when you multiply a float4 with 2 for example every component of that float4 is multiplied by 2. This should apply to all other "arrays" like float2 etc.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net