Shader position in view

Software: Away3D 4.x

3dNewb, Sr. Member
Posted: 13 November 2012 07:03 AM   Total Posts: 105

Hi!

Is there a way for me to get the view-relative x,y position of the pixel into the shader code?

   

Avatar
GoroMatsumoto, Sr. Member
Posted: 13 November 2012 02:22 PM   Total Posts: 166   [ # 1 ]

Hi 3dNewb.

What do you want to do with that?

I understand the coords of the view size and AGAL fragment(v0)
like following,

x in AS(0 ... view.width) : v0.x in AGAL(0 ... 1)
y in AS(0 ... view.height) : v0.y in AGAL(0 ... 1)

So, you can access arbitrary coord of view in AGAL,
eg: the coords is (100.0, 200.0)

x=1.0/view.width*100.0;
y=1.0/view.height*200.0

I put these in constant registers.
and maybe you should test linear or nearest sampling.

If anybody know more easy or smart way,
I wanna know too.

 

   

3dNewb, Sr. Member
Posted: 13 November 2012 02:42 PM   Total Posts: 105   [ # 2 ]

I want to “fake” some material effects by making the material lighter near the center of the view. For this I need the position of the fragment pixel in the view.

From your example I don’t understand what register I need to get the x,y position from…

 

   

Avatar
GoroMatsumoto, Sr. Member
Posted: 13 November 2012 03:19 PM   Total Posts: 166   [ # 3 ]

center pos is (0.5, 0.5) in v0.

At first, I convert coords,

//newCoords = coords - 0.5;
sub ft0.xy v0.xy fc0.x
//newCoords = newCoords * 2.0;
mul ft0.xy ft0.xy fc0.y
abs ft0
.xy ft0.xy 

Now you can access the center pos as (0, 0).
(start pos is (1, 1) and end pos is (1, 1).)

And you use these num as effect power.

If you want make center pixels bright,

//tempEffectPower = newCoords * effectPower
mul ft0.z ft0.x fc0.//fc0.z = effectPower
mul ft0.w ft0.y fc0.z

//tempEffectPower = newCoords - tempEffectPower;
sub ft1.xy fc0.z ft0.zw
    
//lastEffectPower = (tempEffectPower.x + tempEffectPower.y) *0.5;
add ft1.x ft1.x ft1.y
div ft1
.x ft1.x fc0.//fc0.w=0.5
    
//get current pixel, and add lastEffectPower
tex ft2 v0 fs0<2d,clamp,linear>
add ft2 ft2.xyz ft1.x
    
//output
mov oc ft2 

Tested capture:

 

   

3dNewb, Sr. Member
Posted: 13 November 2012 04:21 PM   Total Posts: 105   [ # 4 ]

Awesome, thanks so much for this, really appreciate it.

 

   

3dNewb, Sr. Member
Posted: 13 November 2012 06:33 PM   Total Posts: 105   [ # 5 ]

the v0 register seems like what I need, however, it only works if I don’t move the camera or the object. Should it not update every frame?

 

   

Avatar
GoroMatsumoto, Sr. Member
Posted: 14 November 2012 12:40 AM   Total Posts: 166   [ # 6 ]

Sorry, I dont know what you want to do…

Is first image correct?
How about rotating the cube with the light pos?

Non shaded cube?(like attached?)

 

File Attachments
SimpleAwayTest.swf  (File Size: 178KB - Downloads: 243)
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X