1 registered members (AndrewAMD),
1,135
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
The ultimate tree shader?
#426104
07/16/13 16:34
07/16/13 16:34
|
Joined: Jul 2013
Posts: 22
Stratego
OP
Newbie
|
OP
Newbie
Joined: Jul 2013
Posts: 22
|
Okay so what I’m looking to do here is have, as the title says, the ultimate tree shader. I’m relatively new to this, but I am fairly competent when it comes to scripting / programming. What I want the shader to do: Be affected by the sun and dynamic lights, have normal bump with specular, move verts like in the animTree.fx, and have shadow map support so I can bake occlusion. So the tree would have 2 sets of UVs, one for color and one for shadow. It would have 3 textures, one with color in RGB and transparency in alpha, one with normal map in RGB and specular map map in alpha, and one with a shadow map. Shadow is the most important, because baked occlusion (on trees modeled correctly) would look great. I modeled the tree below to demonstrate the affect of just occlusion (the tree isn't done yet, but you get the picture). It’s not common for a tree to be upside down, so the lighting should almost always look good. The reason I’m posting is to see if this is possible. An expert may be out there thinking: “You can’t mix X with Y!” So I figured before I started diving in I’d ask to see what people think.
Last edited by Stratego; 07/16/13 16:59.
|
|
|
Re: The ultimate tree shader?
[Re: Stratego]
#426112
07/16/13 17:02
07/16/13 17:02
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
Well... I'm not an expert but what you want to do should be possible without any problems. Little tip: for normalmapping you only need x and y (r and g) of the normalmap, the other two can be used as specular exponent (glossiness) and factor. (that's what I usually do) If you need any further help feel free to ask. EDIT: I didn't see that you want to use 2 UV sets ... this shouldn't be a problem but I've never worked with multiple UVs before so this could be something I can't solve. (the coordinate stuff only)
POTATO-MAN saves the day! - Random
|
|
|
Re: The ultimate tree shader?
[Re: Stratego]
#426139
07/17/13 06:28
07/17/13 06:28
|
Joined: Mar 2011
Posts: 3,150 Budapest
sivan
Expert
|
Expert
Joined: Mar 2011
Posts: 3,150
Budapest
|
hi, I have little experience in writing shaders, but about 2 weeks ago I wrote a tree shader for shade-c that handles ambient, diffuse, specular, 8 dynamic lights, and the dynamic shadowmapping of shade-c. it was easier than I expected. I simpply used the basic tree anim shader and the sample shaders from shader workshops, and the lines from shade-c corresponding to its shadowmapping. this way you could do it what you need, there is a normalmapping shader in shader workshops too. I'm not sure baked occlusion is good or bad when you use a proper dynamic shadowmapping that supports self shadows on alpha textures, but can be useful sometimes. maybe the 2nd UV set works like in case of level entities, that utilizes texcoord1 as input to the vertex shader, and entSkin2 for a sampler to be used in the pixel shader. somebody could verify it. it's new to me that normalmapping requires only r and g values of the normalmap, porbably it has a reason I should read about
|
|
|
Re: The ultimate tree shader?
[Re: sivan]
#426143
07/17/13 07:12
07/17/13 07:12
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
@sivan: normalmapping works like this (when using precomputed tangents): Normal = normalize(In.Normal + (Normal.r * In.Tangent + Normal.g * In.Binormal) * NormalmappingStrength); ...and as you can see, the blue channes isn't needed.
POTATO-MAN saves the day! - Random
|
|
|
Re: The ultimate tree shader?
[Re: Kartoffel]
#426144
07/17/13 07:48
07/17/13 07:48
|
Joined: Mar 2011
Posts: 3,150 Budapest
sivan
Expert
|
Expert
Joined: Mar 2011
Posts: 3,150
Budapest
|
thanks, it is useful for me. I worked only within shade-c with normalmapping where it is done in a compex way, but finally I can see it. moreover, in shader workshops in.Normal is not used, so another good point a question: is it faster to add and normalize than lerp 2 vectors? what I still don't really understsand is why there are more methods for specular calculations, which have different final appearance. in shader workshops (and in another tutorial at rastertek.com) a reflection vector is calculated producing imo bad results, I found better to use the halfway vector method.
Last edited by sivan; 07/17/13 07:50.
|
|
|
Re: The ultimate tree shader?
[Re: Kartoffel]
#426148
07/17/13 10:04
07/17/13 10:04
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
@sivan: normalmapping works like this (when using precomputed tangents): Normal = normalize(In.Normal + (Normal.r * In.Tangent + Normal.g * In.Binormal) * NormalmappingStrength); ...and as you can see, the blue channes isn't needed. That is a valid simplification/approximation when you don't mind its inaccuracy that is quite noticeable on lowpoly models with hard edges. Geometrically, a correct coordinate system transportation totally needs the multiply of the In.Normal vector by the blue channel. Moreover, you have to normalize the three vectors since the proportional arithmetic averages passed from the vertex shader are not unit vectors. Normal = (Normal.r * normalize(In.Tangent)) + (Normal.g * normalize(In.Binormal)) + (Normal.b * normalize(In.Normal)); The result of this operation is a vector with same length of Normal vector so there is no need of its normalization. sorry for the offtopic xP
Last edited by txesmi; 07/17/13 11:27. Reason: explanatory image
|
|
|
Re: The ultimate tree shader?
[Re: sivan]
#426171
07/17/13 13:53
07/17/13 13:53
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
what I still don't really understsand is why there are more methods for specular calculations, which have different final appearance. in shader workshops (and in another tutorial at rastertek.com) a reflection vector is calculated producing imo bad results, I found better to use the halfway vector method. Yeah, there are different methods which have different results. I prefer blinn-phong specular lighting (looks nice and it's not very expensive). (in case you want a couple of spec-algorithms:)
#define Specular_Phong(normal, view, light, materialPower) pow(saturate(dot(reflect(-light, normal), view)), materialPower) // Phong Reflection Model
#define Specular_BlinnPhong(normal, view, light, materialPower) pow(saturate(dot(normal, normalize(light + view))), materialPower * 4) // Blinn (Phong) Reflection Model
#define Specular_TorranceSparrow(normal, view, light, materialPower) exp(-2 * materialPower * pow(acos(saturate(dot(normal, normalize(light + view)))), 2)) // Blinn (Torrance-Sparrow/Gauss) Reflection Model
#define Specular_TrowbridgeReitz(normal, view, light, materialPower) pow(1 / (1 + (1 - pow(saturate(dot(normal, normalize(light + view))), 2)) * materialPower), 2) // Blinn (Trowbridge-Reitz) Reflection Model
#define Specular_Lyon(normal, view, light, materialPower) pow(1 - saturate(dot(normalize(light + view) - normal, normalize(light + view) - normal) * materialPower / 2), 3) // Lyon/Blinn halfway method
normal = surface normal; view = direction vec from the fragment pos to the camera; light = direction vec from the fragment pos to the light; material power = glossiness / spec exponent (needs to be modified a bit) (all vectors have to be normalized) Edit: @txesmi: oops, I didn't know that However, calculating the blue channel shouldn't be a problem ;P (I think this works: z = sqrt(1 - x * x - y * y);)
Last edited by Kartoffel; 07/17/13 15:22.
POTATO-MAN saves the day! - Random
|
|
|
|