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 Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Shading the volume... I need help
PostPosted: Fri Nov 12, 2010 4:03 pm 

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
AndiNo wrote:
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.


No, I scaled my manuel object so it is "big enough" in my world. I want to scale UV cordinates so that every 16 units in world space is 1 unit in texture space -> I want to divide my inWorldPosition.xy / xz/ yz by 16. Ideally I would pass that into the shader at runtime instead of hard coding a 16 (pass a value scale into my ColouredCubicVoxelFP somehow) that way if I change scale in my program, it automatically changes in my shader. Unfortunately while I believe this is possible, I have absolutely no idea how to do it.

Quote:
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.


This worked perfectly, thank you! After I did it, it seemed so obvious... *sigh*

Quote:
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


The problem I'm having with this is that it seems when reading stuff nothing comes in bite size chunks, it feels like every tutorial and every example is just the whole bloody thing - and starting from the beginning isn't what I want either (because that would take forever and I only want to do a few things with shaders and then pretty much leave them alone until EVERYTHING else is done (afterall what is the point of cool effects if there is no game) . Anyways I appreciate the refrence, I'm still hoping to find the hidden cg API in a format similar to Javas : ) wouldn't that be nice... I'm dreaming now.

Quote:
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.


This is precisely what causes my error. I'm really wondering how in the heck you did it. I've read EVERY post in the top 7 most current posts on this forum at least 3-4 times, it's not a matter of I haven't tried to figure it out on my own, I promise.

David's solution of dividing by 100 (for me would be 16) straight up crashes me. It gives me that error X6077 telling me I can't modify the crap in the if statement (I'm not using any other conditionals or looping). What it really means is that for some damn reason I cannot have the 2nd parameter of inWorldPosition be any derivitive of inWorldPosition. It doesn't matter if I try and make a temporary variable, and set tmp = iWP/16 and then use tmp.XX it still has same error.

What I can do is make a static float2 and use it as the 2nd parameter in tex2D (for instance one time I made 1 face always use the bottom right pixel of my texture by makeing a float2 tmp = {1, 1}; and then saying col = tex2D(heightMap, tmp); One thing that just occured to me is to try and scale that value and see if that also crashs the program... Anyways, it is the most frusterating thing to be spending time on, because it seems like it should be so fking simple, and without changing it everything looks horrible. Also there is no way for me to start on the texture atlas side of things if I can't get 1 image showing up on 1 face at the scale of my choosing :?.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Fri Nov 12, 2010 5:07 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
I can't write much because i'm at work, but try doing the scaling outside of the 'if' statement if you are not already. Create a new variable outside the if, scale it, and then use it inside the if.

I'll give more help later...


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

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
David Williams wrote:
try doing the scaling outside of the 'if' statement if you are not already. Create a new variable outside the if, scale it, and then use it inside the if.


I have, in every combination I can think of, from making a temporary variable and setting it equal to inWorldPosition / 16, to making inWorldPosition = inWorldPosition / 16...

Oh wait: SUCCESS... for some reason, doing the division at the end worked. For anyone interested in the future, this works.
Code:
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.
   float2 tmp;
    if(inWorldNormal.x > 0.5)
    {
        tmp = inWorldPosition.yz;
    }
   
    if(inWorldNormal.x < -0.5)
    {
        tmp = inWorldPosition.yz;
    }
   
    if(inWorldNormal.y > 0.5)
    {
        tmp = inWorldPosition.xz;
    }
   
    if(inWorldNormal.y < -0.5)
    {
        tmp = inWorldPosition.xz;
    }
   
    if(inWorldNormal.z > 0.5)
    {
        tmp = inWorldPosition.xy;
    }
   
    if(inWorldNormal.z < -0.5)
    {
        tmp = inWorldPosition.xy;
    }
   
   col = tex2D(heightMap, (tmp/16) + 0.5);
    result = float4(col, 1.0);
}


David, if you happen to know, can you tell me how to pass my scale value into the shader from my c++ code as a parameter? AKA this line
Code:
PVWorld->begin("ColouredCubicVoxel", Ogre::RenderOperation::OT_TRIANGLE_LIST);

would ideally be this line
Code:
PVWorld->begin("ColouredCubicVoxel(16)", Ogre::RenderOperation::OT_TRIANGLE_LIST);

or something to that effect... And any tips on getting started with using a texture atlas (although I have yet to start reading on that, so I probably have quite a bit of work to go there before I have anything going. Thanks a ton.


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

Joined: Sun Oct 03, 2010 10:13 pm
Posts: 73
paycheck wrote:
I'm still hoping to find the hidden cg API in a format similar to Javas : )
For nearly everything I had to do this (or the related pages) sufficed for me:
http://msdn.microsoft.com/en-us/library/ff471376%28v=VS.85%29.aspx

Use the search function in the Ogre forums if you want to pass a parameter to a shader. I think it's not easy but I remember reading a thread about this when searching for something similar.


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

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
most important to me now is how to get an atlas working - how do I figure out my voxel's Material data inside of the cg shader? this is pretty much all I would need to use an atlas right?


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

Joined: Sun Oct 03, 2010 10:13 pm
Posts: 73
That's not so easy. You have to store the material value in a way that it can be read by the shader. I do this by setting the vertex colour in the ManualObject to the voxel material value.


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

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
Hmm... I thought in minecraft they use the vertex color for lighting - I guess you could do both but it would be tricky. is the vertex color a float4 type object? Could I use the .x for material information and .y for lighting?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Fri Nov 12, 2010 8:43 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
paycheck wrote:
David, if you happen to know, can you tell me how to pass my scale value into the shader from my c++ code as a parameter? AKA this line
Code:
PVWorld->begin("ColouredCubicVoxel", Ogre::RenderOperation::OT_TRIANGLE_LIST);

would ideally be this line
Code:
PVWorld->begin("ColouredCubicVoxel(16)", Ogre::RenderOperation::OT_TRIANGLE_LIST);

or something to that effect...


I don't know the exact Ogre syntax (in my case it's always the same and is written into the shader code) but basically you want to pass it in as a 'uniform parameter'. You will have to set this on the shader/material rather than the ManualObject, I would imagine. Sorry I can't be more specific, but if you can't find anything in the Ogre docs/forums then I'll have a look for you.

paycheck wrote:
And any tips on getting started with using a texture atlas (although I have yet to start reading on that, so I probably have quite a bit of work to go there before I have anything going. Thanks a ton.


Have a look at AndiNo's thread on the Ogre forums, and maybe here as well.

AndiNo wrote:
paycheck wrote:
I'm still hoping to find the hidden cg API in a format similar to Javas : )
For nearly everything I had to do this (or the related pages) sufficed for me:
http://msdn.microsoft.com/en-us/library/ff471376%28v=VS.85%29.aspx


As well as the above, the NVidia documentation is here: http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter01.html

There is a reference section in the appendices.

As for passing the material though to the shaders you have several options, such as using a vertex colour or a texture coordinate. In Thermite I'm actually using the 'w' component of the vertex position, but I don't recommend this unless you understand the implications ;-)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Mon Nov 15, 2010 2:07 am 

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
So, I'm getting to the point where I finally feel like I "understand" shader code.

My new question is can I get an alpha value straight out of my png using a tex2d call?

what I want to do is this

Code:
result = tex2D(textureAtlas, uv);


instead of

Code:
float3 col;
   col = tex2D(textureAtlas, tmp);
    result = float4(col, 1.0);


And have it use the alpha of the png... is this possible?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Shading the volume... I need help
PostPosted: Mon Nov 15, 2010 3:49 am 

Joined: Sat Sep 18, 2010 9:45 pm
Posts: 189
Yes that will work. tex2d should return a float 4, which one can treat as an RGBA value.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  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