Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Imhotep), 567 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Image sampling in a shader, RGB values #467885
09/05/17 19:31
09/05/17 19:31
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Hello!

Ive made a shader that has a cubic reflection based on the Alpha of a texture thats stored in the model. If the alpha has white, the model is more reflective there, and if its black, the model isnt reflective there.

So once I was able to sample the Alpha value of a model's second entity texture, i naturally started calling for the RGB values for other shader effects. For example, the specularity strength would use the Red value of the image, another effect uses the Green value of the image.

So if my model has 1 diffuse + 3 textures, and the shader is looking up the RGBA values of each of these 3 textures to determine the strengths of each shading component, is that giving the GPU more work to do? I obviously cannot have every model have cubic mapping + normal + specular + rim + etc. But once you call a texture as a sampler, and Float4, all the information is there already right? Does going into the RGBA values each give more work to the GPU?

Re: Image sampling in a shader, RGB values [Re: jumpman] #467887
09/05/17 21:15
09/05/17 21:15
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Your question is a bit weirdly phrased. Do you mean that if you do a texture lookup but only use let's say the alpha component of the returned float4 it gets cheaper? if so, highly doubtful, since the function returns a float4 and you merely discard parts of the return value. Since all modern shader compilers are SSA based you could potentially argue that if the ISA supports it the compiler could optimize it to a specific single channel fetch, but I don't think any vendor does that.

In any case, a texture lookup is incredibly cheap, especially once the texture is in the GPU cache. You can totally get away with two texture fetches per fragment in order to do your effects. That's pretty much what the whole industry does anyway.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Image sampling in a shader, RGB values [Re: WretchedSid] #467892
09/05/17 22:43
09/05/17 22:43
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
So once you declare a sampler;

Texture entskin2; //uses the stored entskin image 2

Sampler reflective
{...}

...

Float 4 reflective_pixels tex2d(reflective,...)

Specular_strength = reflective_pixels.r; //looking up the red channel
specular_falloff = reflective_pixels.g; //looking up the green channel
Specular_bounce = reflective_pixels.b; //looking up the blue channel
Cubic_strength = reflective_pixels.a; //looking up the alpha channel

Does it uses more gpu processing time to go through each RGBA value? Compared to

Float reflective_pixels tex2d(reflective...). // a single float
Specular_strength = reflective_pixels;

Re: Image sampling in a shader, RGB values [Re: jumpman] #467894
09/06/17 00:21
09/06/17 00:21
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
It's not tied to the sampler. You can declare a sampler all day long, if you don't use it, the compiler will optimize it out. But the tex2d() lookup will have the same cost no matter what you use of the returned components. Accessing them isn't the expensive part, getting the values in the first place is. But you pay that price one way or another.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Image sampling in a shader, RGB values [Re: WretchedSid] #467895
09/06/17 03:47
09/06/17 03:47
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
thank you friend!


Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1