2 registered members (VoroneTZ, TipmyPip),
1,333
guests, and 0
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
OP
Serious User
|
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
Expert
|
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: jumpman]
#467894
09/06/17 00:21
09/06/17 00:21
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
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
OP
Serious User
|
OP
Serious User
Joined: Apr 2002
Posts: 1,246
ny
|
|
|
|
|