It is currently Sat Aug 22, 2020 3:44 pm


All times are UTC




Post new topic Reply to topic  [ 15 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Mapping Position to texture coordinates
PostPosted: Thu Aug 11, 2011 8:24 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Ok, the following code is untested and may not compile... but hopefully you get the idea :-)

Code:
void MyFragmentShader1(float4 position : POSITION,
                       float4 worldPosition : TEXCOORD0,
                       out float4 color: COLOR)
{
   color = tex2D(texture, WorldPosition.xy / 10.0f);
  //color = float4(1.0f, 0.0f, 0.0f, 1.0f); //Can try this line for testing
}

void MyVertexShader1(float4 position : POSITION,
                     out float4 oPosition : POSITION,
                     out float4 worldPosition : TEXCOORD0,
                     uniform float4x4 worldViewMatrix,
                     uniform float4x4 world)
{
  worldPosition = mul(world, position);
  oPosition = mul(worldViewMatrix, position);
}


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Mapping Position to texture coordinates
PostPosted: Fri Aug 12, 2011 4:32 am 
User avatar

Joined: Tue Feb 22, 2011 8:04 am
Posts: 101
Alright I misinterpreted a previous post to mean I didn't need a vertex shader. The code you provided was very similar to what I had before I removed my vertex shader.

Here is what the cg program looked like before that. Almost like the one you gave me. I assume I have to pass in the texture in order for the program to use it. That is the only difference I am aware of.

However Ogre keeps informing me that my fragment shader will not compile. Everything looks right. Unfortunatly I don't know the subtle syntax differences between CG and C.

Could it be that texture coordinates may not be of float4 type?

I think they are supposed to be float2.

Code:
void MyFragmentShader1(float4 position : POSITION,
                       float4 worldPosition : TEXCOORD0,
                       out float4 color : COLOR,
                       uniform sampler2D texture)
{
   color = tex2D(texture, WorldPosition.xy / 10.0f);
}

void MyVertexShader1(float4 position : POSITION,
                     out float4 oPosition : POSITION,
                     out float4 worldPosition : TEXCOORD0,
                     uniform float4x4 worldViewMatrix,
                     uniform float4x4 world)
{
  worldPosition = mul(world, position);
  oPosition = mul(worldViewMatrix, position);
}

_________________
--Real Programmers use a magnetized needle and a steady hand.
--xkcd--


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Mapping Position to texture coordinates
PostPosted: Fri Aug 12, 2011 4:45 am 
User avatar

Joined: Tue Feb 22, 2011 8:04 am
Posts: 101
Ok, that was a stupid mistake. one of the worldPosition variables had been accidently capitalized.

So now I see a texture, but it looks terribly stretched along one axis. instead of grass I see long green lines.

Its late and my adjustments are getting me nowhere. However I have never been so excited to see a badly skewed green texture.

Let me know if you know what mistake I could be making.

Thank you for the help.

_________________
--Real Programmers use a magnetized needle and a steady hand.
--xkcd--


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Mapping Position to texture coordinates
PostPosted: Sat Aug 13, 2011 12:38 am 

Joined: Sat Sep 18, 2010 9:45 pm
Posts: 189
One advice is to look at ogre.log when sometimes doesn't work. Especially if texture is showing up as black.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Mapping Position to texture coordinates
PostPosted: Sat Aug 13, 2011 8:50 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
GM_Riscvul wrote:
So now I see a texture, but it looks terribly stretched along one axis. instead of grass I see long green lines.


The code is only correct for triangles facing along the z axis. Try flying around the mesh and looking at it from differnt angles and you should see what I mean.

If they are facing along a diffent axis then you can try:

Code:
color = tex2D(texture, WorldPosition.xz / 10.0f);


or

Code:
color = tex2D(texture, WorldPosition.yz / 10.0f);


Obviously you eventually want a solution which works for all directions, which is where triplanar texturing comes in.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 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