Lindor 438 Posted July 23, 2022 Author Share Posted July 23, 2022 Sorry, usually shader tweaking requires lots of tests because my head so often accidentally swappes things xD Link to comment
Vishanka 236 Posted July 23, 2022 Share Posted July 23, 2022 (edited) 13 minutes ago, Lindor said: Does it work with this? Unfortunately it's still white. This does not affect the leaves but the tree trunk and the one plant I put to the tree_Tree shader. Would it be possible to do all this with the tree_branch shader instead of changing the tree_Tree shader? The problem with the tree_Tree shader was that the plants became too dark at daytime, maybe the problem will be solved by your changes though, we'll see soon That's how the tree_Tree shader looks on the plants in its original state: Edit: Still white after the edit, always deleting shader cache too Edited July 23, 2022 by Vishanka 1 Link to comment
Lindor 438 Posted July 23, 2022 Author Share Posted July 23, 2022 Okay this time I tested myself. I know why it was white. Sould no longer happen with this: Spoiler #ifdef PS_TRUNK_SPASS_AMBDIF_20 #define VS_OUT_hposition #define VS_OUT_screenCoord #define VS_OUT_hpos //#define VS_OUT_camDist #define VS_OUT_lightDist #define VS_OUT_posInLight #define VS_OUT_depthFog #ifdef ENABLE_VERTEXLIGHTING #define VS_OUT_vertexLightData #endif struct pixdata { float4 hposition : POSITION; float4 texcoord0 : TEXCOORD0; float4 lightDist : TEXCOORD1; float4 screenCoord : TEXCOORD2; float4 hpos : TEXCOORD3; float4 posInLight : TEXCOORD4; float2 depthFog : TEXCOORD5; #ifdef VS_OUT_vertexLightData float4 vlColor : COLOR0; float4 vlNormal : TEXCOORD7; #endif }; fragout2 mainPS(pixdata I, float2 vPos : VPOS, uniform sampler2D texture0, uniform sampler2D texture1, uniform sampler2D texture2, uniform sampler2D texture3, uniform sampler2D shadow_texture, uniform sampler3D textureVolume, uniform sampler2D fog_texture, uniform sampler2D shadow_map, uniform sampler3D noise_map, uniform float4 shadow_data, uniform float4 fog_color, uniform float4 system_data, uniform float4 light_col_amb, uniform float4 light_col_diff, uniform float4 param) { fragout2 O; // get texture values s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); s2half4 tex1 = decode_normal(tex2D(texture1, I.texcoord0.xy)); s2half3 nrm = tex1.xyz; // get normal vector from bumpmap texture // s2half4 tex1 = tex2D(texture1, I.texcoord0.xy); // s2half3 nrm = normalize(tex1.xyz - s2half3(0.5, 0.5, 0.5)); #ifdef VS_OUT_vertexLightData light_col_amb += light_calc_heroLight(I.vlColor); light_col_amb += light_calc_vertexlighting(nrm,I.vlColor,normalize(I.vlNormal.xyz)); #endif // get shadow term from shadow texture #ifdef NO_SHADOWS s2half4 shadow = 1.0f; #else #ifdef TREE_HOLE s2half4 shadow = calcShadowSimple(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x); #else s2half4 shadow = tex2Dproj(shadow_texture, I.screenCoord); #endif #endif // lighting s2half3 l_dir = normalize(I.lightDist.xyz); // calc sun diffuse float3 sun_diff = light_col_diff.xyz * tex0.xyz * saturate(dot(l_dir, nrm)); // calc moon diffuse float3 moon_diff = light_col_amb.xyz * tex0.xyz * saturate(dot(l_dir, nrm)); float3 new_color = moon_diff + shadow.z * sun_diff; sTEnergy tenergy; calc_tenergy(tenergy,noise_map,texture2,texture3,I.texcoord0.xy,-I.texcoord0.y,system_data.x); #ifdef S2_FOG // calc fog fogDiffuse( new_color, fog_texture, I.depthFog, fog_color ); #endif // set output color O.col[0].rgb = new_color; O.col[0].a = 1; #if TREE_HOLE O.col[0].a = calcHoleAlpha(I.hpos,param.x); #endif O.col[1] = float4(0.0, 0.0, 0.0, 0.0); #ifdef USE_TENERGY // float tescale = pow(tex0.a,3); float tescale = tex0.a * tex0.a; O.col[0].xyz += tenergy.color0*tescale; O.col[1].xyz += tenergy.color1*tescale; #endif #ifdef SPASS_LIGHTNING // calc to-face-lightning float is2Lightning = step(0.2, dot(nrm, I.lightDist.xyz)); O.col[0] = float4(is2Lightning * light_col_amb.w * float3(1.0, 1.0, 1.0), 1.0); O.col[1] = float4(is2Lightning * light_col_amb.w * light_col_amb.xyz, 0.0); #endif #ifdef SIMPLECOLOR O.col[0] = float4(1,1,1,1); #endif return O; } #endif 13 minutes ago, Vishanka said: Would it be possible to do all this with the tree_branch shader instead of changing the tree_Tree shader? The problem with the tree_Tree shader was that the plants became too dark at daytime, maybe the problem will be solved by your changes though, we'll see soon Yes absolutely possible. I can make any changes you want. Or even script completely new shader and leave the old ones as they were. So you can use the new only for the plants you want to. But will be much work to find all surfaces which you want the new shaders to get apply, easier to just replace the old shader. Link to comment
Vishanka 236 Posted July 23, 2022 Share Posted July 23, 2022 (edited) 10 minutes ago, Lindor said: But will be much work to find all surfaces which you want the new shaders to get apply, easier to just replace the old shader. I don't think it's that much, there aren't that many plants in the textures folder and only the plants caught my eye because they absorb the light like a black hole... barrels and other stuff seem to light up normally. Which brings us to the topic: With the new attempt everything is black for me Edit: actually not blackblack, there are still some shades but it would seem like there's still a problem that the plants will come across darker than the treetrunk Edited July 23, 2022 by Vishanka Link to comment
Lindor 438 Posted July 23, 2022 Author Share Posted July 23, 2022 @Vishanka I believe the plants become too dark because of the shadow calculation. I would suggest to restore the shaders as they were used in Vanilla's surface.txt and just change the shaders. So I guess wanted the changes so far are: Trunk: Make Camera independent Decrease shadow intensity specular yes or no? Branch: Add hero light calculation Add shadow yes or no? specular yes or no? Leaves: Add hero light calculation Add shadow yes or no? specular yes or no? This is what "specular" means: You want that on tree trunks or not? Don't worry, it wouldn't be as white and not as extreme, it was already there in Vanilla tree trunks. Same question for leaves and branches: you want them to be shiny or not? By the way, specular will always be camera dependent. Link to comment
Vishanka 236 Posted July 23, 2022 Share Posted July 23, 2022 I'd say for the start it would be enough to just change the tree_branch shader. Add hero light calculation if that means that the object becomes lighter when my character has an increased light radius and is standing beside it. I think all the plants on the ground use the tree_branch shader so that could be enough to achieve the right effect. Specular on the tree_branch could add some visual complexity, I liked the effect much, but I'd say one step after another 16 minutes ago, Lindor said: Branch: Add hero light calculation Add shadow yes or no? What kind of shadow would be added to tree_branch? Link to comment
Lindor 438 Posted July 23, 2022 Author Share Posted July 23, 2022 The branches already have shadow, it is more the question of "keep/enable shadow yes or no?", actually. Enable because shadow calculation only happens under certain circumstances, I could make it so that it always happens. 16 minutes ago, Vishanka said: Add hero light calculation if that means that the object becomes lighter when my character has an increased light radius and is standing beside it. Yes that means it. This is my first attempt (no specular yet): Spoiler #ifdef PS_SPASS_AMBDIF_NONORMAL_20 #define VS_OUT_hposition #define VS_OUT_diffuse #define VS_OUT_hpos #define VS_OUT_screenCoord #define VS_OUT_depthFog #ifdef ENABLE_VERTEXLIGHTING #define VS_OUT_vertexLightData_nonrm #endif struct pixdata { float4 hposition : POSITION; float4 diffuse : COLOR0; float4 texcoord0 : TEXCOORD0; float4 hpos : TEXCOORD1; float4 screenCoord : TEXCOORD2; float2 depthFog : TEXCOORD3; #ifdef VS_OUT_vertexLightData_nonrm float4 vlColor : COLOR1; #endif }; fragout2 mainPS(pixdata I, uniform sampler2D texture0, uniform sampler2D shadow_map, uniform sampler3D textureVolume, uniform sampler2D shadow_texture, uniform sampler2D fog_texture, uniform int anzIterations, uniform float4 shadow_data, uniform float4 fog_color, uniform float4 light_col_amb, uniform float4 light_col_diff, uniform float4 param) { fragout2 O; // get texture values s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); #ifdef VS_OUT_vertexLightData light_col_amb += light_calc_heroLight(I.vlColor); #endif #ifdef VS_OUT_vertexLightData_nonrm light_col_amb.rgb += I.vlColor.rgb; light_col_amb += light_calc_heroLight(I.vlColor); #endif float4 deferred_tex = tex2Dproj(shadow_texture, I.screenCoord); // calc sun diffuse float3 sun_diff = I.diffuse.xyz * light_col_diff.xyz * tex0.xyz; // calc ambient float3 amb = light_col_amb.xyz * tex0.xyz; /* #ifndef NO_SHADOWS #ifdef PS_SIMPLESHADOW s2half shadow = calcShadowSimple(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x); #else s2half shadow = calcShadow(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x, anzIterations); #endif sun_diff *= shadow; #endif */ #ifndef NO_SHADOWS sun_diff *= deferred_tex.z; #endif float3 new_color = amb + sun_diff; #ifdef S2_FOG // calc fog fogDiffuse( new_color, fog_texture, I.depthFog, fog_color ); #endif // calc only diffuse O.col[0].xyz = new_color; O.col[0].a = tex0.a; #if TREE_HOLE O.col[0].a = calcHoleAlpha(I.hpos,param); #endif O.col[1] = float4(0.0, 0.0, 0.0, 0.0); #ifdef SIMPLECOLOR O.col[0] = tex0; O.col[1] = float4(0.0, 0.0, 0.0, 0.0); #endif return O; } #endif Hope everything goes right 1 Link to comment
Vishanka 236 Posted July 23, 2022 Share Posted July 23, 2022 (edited) 22 minutes ago, Lindor said: Hope everything goes right Let there be light Apart from the light aura just not looking good in general because of the missing shadows it's perfect for what it is now. The plants do not stay black and absorb the light anymore Thank you for your efforts! We could try to add some specular, just to see if it looks good or adds complexity, but it's not a must have. Edited July 23, 2022 by Vishanka Link to comment
Lindor 438 Posted July 23, 2022 Author Share Posted July 23, 2022 6 minutes ago, Vishanka said: Apart from the light aura just not looking good in general because of the missing shadows it's perfect for what it is now. The plants do not stay black and absorb the light anymore Thank you for your efforts! We could try to add some specular, just to see if it looks good or adds complexity, but it's not a must have. Glad it works! Will try specular later, but first is the tree trunk shadow issue. The shadow is always claculated from the sun direction, which doesn't work if the light comes from the hero character. Working on it. Link to comment
Vishanka 236 Posted July 23, 2022 Share Posted July 23, 2022 Take your time, it's bedtime for me first. It is now so pleasantly consistent in itself. Will have a look at daytime tomorrow, I only checked nighttime for now Thank you again, great work Link to comment
Lindor 438 Posted July 23, 2022 Author Share Posted July 23, 2022 Thanks again, feeling honored I couldn't fix the shadow problem. I don't know why, but I have one last suspicion. SM1_1 could mean shadow map 1_1. If that is so, maybe I can do something here. Big maybe. But at least the seraphim FX lighting now works Link to comment
Lindor 438 Posted July 24, 2022 Author Share Posted July 24, 2022 @Vishanka I have successfully implemented specular for plants/leaves. You'll have to replace two code chunks this time: Spoiler #ifdef PS_SPASS_AMBDIF_NONORMAL_20 #define VS_OUT_hposition #define VS_OUT_diffuse #define VS_OUT_hpos #define VS_OUT_screenCoord #define VS_OUT_depthFog #define VS_OUT_camDist #define VS_OUT_lightDist #define VS_OUT_NORMAL #ifdef ENABLE_VERTEXLIGHTING #define VS_OUT_vertexLightData_nonrm #endif struct pixdata { float4 hposition : POSITION; float4 diffuse : COLOR0; float4 texcoord0 : TEXCOORD0; float4 hpos : TEXCOORD1; float4 screenCoord : TEXCOORD2; float2 depthFog : TEXCOORD3; float4 camDist : TEXCOORD4; float4 lightDist : TEXCOORD5; float4 normal : TEXCOORD6; #ifdef VS_OUT_vertexLightData_nonrm float4 vlColor : COLOR1; #endif }; fragout2 mainPS(pixdata I, uniform sampler2D texture0, uniform sampler2D shadow_map, uniform sampler3D textureVolume, uniform sampler2D shadow_texture, uniform sampler2D fog_texture, uniform int anzIterations, uniform float4 shadow_data, uniform float4 fog_color, uniform float4 light_col_amb, uniform float4 light_col_diff, uniform float4 param) { fragout2 O; // get texture values s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); #ifdef VS_OUT_vertexLightData light_col_amb += light_calc_heroLight(I.vlColor); #endif #ifdef VS_OUT_vertexLightData_nonrm light_col_amb.rgb += I.vlColor.rgb; light_col_amb += light_calc_heroLight(I.vlColor); #endif s2half3 l_dir = normalize(I.lightDist.xyz); s2half3 c_dir = normalize(I.camDist.xyz); s2half3 nrm = normalize(I.normal.xyz); float specular = pow(dot(c_dir, ((2.0 * dot(nrm, l_dir) * nrm) - l_dir)), 20); float4 deferred_tex = tex2Dproj(shadow_texture, I.screenCoord); // calc sun diffuse float3 sun_diff = saturate(I.diffuse.xyz + float3(specular, specular, specular)) * saturate(light_col_diff.xyz + float3(specular, specular, specular)) * tex0.xyz; // calc ambient float3 amb = light_col_amb.xyz * tex0.xyz; /* #ifndef NO_SHADOWS #ifdef PS_SIMPLESHADOW s2half shadow = calcShadowSimple(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x); #else s2half shadow = calcShadow(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x, anzIterations); #endif sun_diff *= shadow; #endif */ #ifndef NO_SHADOWS sun_diff *= deferred_tex.z; #endif float3 new_color = amb + sun_diff; #ifdef S2_FOG // calc fog fogDiffuse( new_color, fog_texture, I.depthFog, fog_color ); #endif // calc only diffuse O.col[0].xyz = new_color; O.col[0].a = tex0.a; #if TREE_HOLE O.col[0].a = calcHoleAlpha(I.hpos,param); #endif O.col[1] = float4(0.0, 0.0, 0.0, 0.0); #ifdef SIMPLECOLOR O.col[0] = tex0; O.col[1] = float4(0.0, 0.0, 0.0, 0.0); #endif return O; } #endif Spoiler //////////////////////////////////////////////////////////////// //Unified Vertex shader used for all shader models //////////////////////////////////////////////////////////////// pixdata mainVS(appdata I, uniform float4 vtx_data_array[32], uniform float4x4 vtx_matrix_array[4], VS_PARAM_BLOCK) { pixdata O; EXTRACT_VERTEX_VALUES // apply wind and calc extreme (=1.0) position float4 wind_pos4 = mul(pos4, vtx_matrix_array[windidx]); // now interpolate between org pos and extr pos pos4 = lerp(pos4, wind_pos4, windLerpFact); #ifdef VS_IN_TREELEAFVERTEX float leaf_scale = param.z; // get vertex billboard offset from array and scale it by size float4 offs4 = data2.y * vtx_data_array[data2.x] * leaf_scale; // transform this offset backwards with inv objmat, so it is "billboarded" after next transform pos4 += mul(offs4, invWorldMatrix); #endif #ifdef VS_OUT_vertexLightData_nonrm O.vlColor = computeVertexLightingColor(pos4,nrm4); #endif #ifdef VS_OUT_vertexLightData computeVertexLightingColorNormal( O.vlColor, O.vlNormal,pos4); #endif // convert vertex pos from objspace to screen space float4 wvp_pos = mul(pos4, worldViewProjMatrix); float camSpaceZ = pos4.x*worldViewMatrix[0][2] + pos4.y*worldViewMatrix[1][2] + pos4.z*worldViewMatrix[2][2] + worldViewMatrix[3][2]; // convert vertex pos from objspace to worldspace float4 worldVertPos = mul(pos4, worldMatrix); float3 worldVertNormal = normalize(mul(nrm4.xyz, (float3x3) worldMatrix)); O.texcoord0 = uv0; #ifdef VS_OUT_depthFog O.depthFog = getFogTCs( wvp_pos.w, fog_data ); //O.depthFog.x = saturate( (wvp_pos.w - fog_data.x) * zfrustum_data.z ); //O.depthFog.y = fog_data.w; #endif #ifdef VS_OUT_hposition // vertex pos O.hposition = wvp_pos; #endif #ifdef VS_OUT_SM1_TEXCOORD1 O.texcoord1 = uv0; #endif #ifdef VS_OUT_depthUV O.depthUV = float4(0,0,0,-camSpaceZ*zfrustum_data.w); #endif #ifdef VS_OUT_posInLight // vertex pos in light-space O.posInLight = mul(pos4, lightMatrix); #endif #ifdef VS_OUT_li_to_pix_w // pass light-to-pixel to fragment shader O.li_to_pix_w = worldVertPos - light_pos; #endif // convert light pos from worldspace into objectspace float4 l_pos_obj = mul(light_pos, invWorldMatrix); // build vector from vertex pos to light pos float3 vertex_to_light = l_pos_obj.xyz - pos4.xyz; // convert cam pos from worldspace into objectspace float4 c_pos_obj = mul(camera_pos, invWorldMatrix); // build vector from vertex pos to cam pos #ifdef MINIMAPMODE float3 vertex_to_cam = c_pos_obj; #else float3 vertex_to_cam = c_pos_obj.xyz - pos4.xyz; #endif // convert light direction vector from worldspace to objectspace float4 l0_dir_obj = mul(light_pos, invWorldMatrix); // convert camera direction vector from worldspace to objectspace float4 c_dir_obj = mul(camera_pos, invWorldMatrix); #ifdef VERT_TREEVERTEX // build object-to-tangent space matrix float3x3 objToTangentSpace; objToTangentSpace[0] = -1.0 * tan3; objToTangentSpace[1] = -1.0 * bin3; objToTangentSpace[2] = nrm4.xyz; // convert vertex_to_light from objectspace to tangentspace float3 vertex_to_light_tan = mul(objToTangentSpace, vertex_to_light); // convert vertex_to_cam from objectspace to tangentspace float3 vertex_to_cam_tan = mul(objToTangentSpace, vertex_to_cam); // convert light direction vector from objectspace to tangentspace float3 l0_dir_tan = mul(objToTangentSpace, l0_dir_obj.xyz); // calc direction vector from vertex position to camera-position c_dir_obj -= pos4; // convert camera direction vector from objectspace to tangentspace float3 c_dir_tan = mul(objToTangentSpace, c_dir_obj.xyz); #ifdef VS_OUT_lightDist // store light vector O.lightDist = float4(l0_dir_tan, 0.0); #endif #ifdef VS_OUT_camDist // store camera vec in texcoord2 O.camDist = float4(c_dir_tan, 0.0); #endif #else #ifdef VS_OUT_lightDist // store light vector & dot O.lightDist = float4(l0_dir_obj.xyz, dot(nrm4.xyz, l0_dir_obj.xyz)); #endif #ifdef VS_OUT_camDist // store camera vec in texcoord2 O.camDist = float4(c_dir_obj.xyz, dot(nrm4.xyz, c_dir_obj.xyz)); #endif #endif #ifdef VS_OUT_vertexLightData O.vlNormal.xyz = mul(objToTangentSpace, O.vlNormal.xyz); #endif #ifdef VS_OUT_hpos // pass screenpos to fragment shader O.hpos = O.hposition; O.hpos.xy *= param.xy; #endif #ifdef VS_OUT_NORMAL // norma O.normal = nrm4; #endif #ifdef VS_OUT_screenCoord // vertex-position in screen space O.screenCoord = calcScreenToTexCoord(O.hposition); #endif #ifdef VS_OUT_SM1_LIGHTING O.diffuse = calcLight(worldVertPos, worldVertNormal, camera_pos, globLightData, O.specular); #endif #ifdef VS_OUT_diffuse // convert light direction vector from worldspace to objectspace float4 l0_dir = mul(light_pos, invWorldMatrix); float diffuse = saturate(dot(nrm4, l0_dir)); // prepare color O.diffuse = float4(diffuse, diffuse, diffuse, 1.0); #endif #ifdef VS_OUT_lowendFog O.fog = calcFog(O.hposition, fog_data); #endif // pass vertex to light to pixelshader, so it becomes pixel to light #ifdef VS_OUT_pix_to_li_T O.pix_to_li_t = float4(vertex_to_light_tan, 0.0); #endif #ifdef VS_OUT_pix_to_li_O O.pix_to_li_o = float4(vertex_to_light, 0.0); #endif #ifdef VS_OUT_pix_to_li // pass vertex to light to pixelshader, so it becomes pixel to light O.pix_to_li = float4(vertex_to_light, 0.0); #endif #ifdef VS_OUT_PIX_TO_C // pass vertex to cam to pixelshader, so it becomes pixel to cam O.pix_to_c = float4(vertex_to_cam_tan, 0.0); #endif return O; } The second one is the big chunk at the very bottom of the TreeShared.shader file. Specular is only really noticeable at daytime (at least that's how it should be). Link to comment
Lindor 438 Posted July 24, 2022 Author Share Posted July 24, 2022 @Vishanka Currently specular keeps the color and just increases brightness. I can make specular more White if you want to. Currently: More White: For the white version, you need to replace this (works cumulative on the old specular, not as standalone): Spoiler #ifdef PS_SPASS_AMBDIF_NONORMAL_20 #define VS_OUT_hposition #define VS_OUT_diffuse #define VS_OUT_hpos #define VS_OUT_screenCoord #define VS_OUT_depthFog #define VS_OUT_camDist #define VS_OUT_lightDist #define VS_OUT_NORMAL #ifdef ENABLE_VERTEXLIGHTING #define VS_OUT_vertexLightData_nonrm #endif struct pixdata { float4 hposition : POSITION; float4 diffuse : COLOR0; float4 texcoord0 : TEXCOORD0; float4 hpos : TEXCOORD1; float4 screenCoord : TEXCOORD2; float2 depthFog : TEXCOORD3; float4 camDist : TEXCOORD4; float4 lightDist : TEXCOORD5; float4 normal : TEXCOORD6; #ifdef VS_OUT_vertexLightData_nonrm float4 vlColor : COLOR1; #endif }; fragout2 mainPS(pixdata I, uniform sampler2D texture0, uniform sampler2D shadow_map, uniform sampler3D textureVolume, uniform sampler2D shadow_texture, uniform sampler2D fog_texture, uniform int anzIterations, uniform float4 shadow_data, uniform float4 fog_color, uniform float4 light_col_amb, uniform float4 light_col_diff, uniform float4 param) { fragout2 O; // get texture values s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); #ifdef VS_OUT_vertexLightData light_col_amb += light_calc_heroLight(I.vlColor); #endif #ifdef VS_OUT_vertexLightData_nonrm light_col_amb.rgb += I.vlColor.rgb; light_col_amb += light_calc_heroLight(I.vlColor); #endif s2half3 l_dir = normalize(I.lightDist.xyz); s2half3 c_dir = normalize(I.camDist.xyz); s2half3 nrm = normalize(I.normal.xyz); float4 deferred_tex = tex2Dproj(shadow_texture, I.screenCoord); // calc sun diffuse //white float3 specular = pow(dot(c_dir, ((2.0 * dot(nrm, l_dir) * nrm) - l_dir)), 20) * float3(1.0f, 1.0f, 1.0f); float3 sun_diff = I.diffuse.xyz * light_col_diff.xyz * saturate(tex0.xyz + specular.xyz); // calc ambient float3 amb = light_col_amb.xyz * tex0.xyz; /* #ifndef NO_SHADOWS #ifdef PS_SIMPLESHADOW s2half shadow = calcShadowSimple(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x); #else s2half shadow = calcShadow(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x, anzIterations); #endif sun_diff *= shadow; #endif */ #ifndef NO_SHADOWS sun_diff *= deferred_tex.z; #endif float3 new_color = amb + sun_diff; #ifdef S2_FOG // calc fog fogDiffuse( new_color, fog_texture, I.depthFog, fog_color ); #endif // calc only diffuse O.col[0].xyz = new_color; O.col[0].a = tex0.a; #if TREE_HOLE O.col[0].a = calcHoleAlpha(I.hpos,param); #endif O.col[1] = float4(0.0, 0.0, 0.0, 0.0); #ifdef SIMPLECOLOR O.col[0] = tex0; O.col[1] = float4(0.0, 0.0, 0.0, 0.0); #endif return O; } #endif Link to comment
Vishanka 236 Posted July 24, 2022 Share Posted July 24, 2022 6 hours ago, Lindor said: I have successfully implemented specular for plants/leaves. I'll test it soon - would it be possible to add the specular to just tree_branch or is that exactly what it already does? Link to comment
Lindor 438 Posted July 24, 2022 Author Share Posted July 24, 2022 (edited) 46 minutes ago, Vishanka said: I'll test it soon - would it be possible to add the specular to just tree_branch or is that exactly what it already does? tree_branch and tree_leaves use the same pixel shader. It's already added to tree_branch but also to tree_leaves. If you want the specular to only work for tree_branch and not tree_leaves, I'd have to script another pixel shader (which would totally be possible). I have experimented more and my personal taste, I think I've found the perfect balance. This time I'll post the whole file cause it's a lot of changes: Spoiler // speedTree tree z #include "lighting.shader" ///////////////////////////////////// // SPASS_G setup ///////////////////////////////////// #ifdef SPASS_G #if defined(SM1_1) #define PS_SPASS_G_11 #else #define PS_SPASS_G_20 #endif #endif ///////////////////////////////////// // SPASS_SHADOWMAP setup ///////////////////////////////////// #ifdef SPASS_SHADOWMAP #define PS_SPASS_SHADOWMAP #endif ///////////////////////////////////// // SPASS_CUBESHADOWMAP setup ///////////////////////////////////// #ifdef SPASS_CUBESHADOWMAP #if defined(SM1_1) #define PS_DUMMY_11 #else #define PS_SPASS_CUBESHADOWMAP_20 #endif #endif #ifdef LAYER_BIT1 #define USE_TENERGY #endif //Inputs: //vpos screen space position (-1 till 1) //param x=opacity, y=horz-shift float calcHoleAlpha(float4 vpos,float4 param) { float opacity = param.x; float horz_disp = param.y; vpos /= vpos.w; vpos.x -= horz_disp; float fact = vpos.x*vpos.x+vpos.y*vpos.y; fact = fact*fact*fact*fact; return fact + opacity; } //////////////////////////////////////////////////////////////// //SPASS_G pixel shader (>=SM2_0) //////////////////////////////////////////////////////////////// #ifdef PS_SPASS_G_20 struct pixdata { float4 hposition : POSITION; float4 texcoord0 : TEXCOORD0; float4 depthUV : TEXCOORD1; }; #define VS_OUT_depthUV #define VS_OUT_hposition fragout1 mainPS(pixdata I, float2 vPos : VPOS, uniform sampler2D texture0, uniform sampler2D shadow_map, uniform sampler3D textureVolume, uniform int anzIterations, uniform float4 shadow_data, uniform sampler2D gradient_texture) { fragout1 O; #ifndef IS_OPAQUE s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); clip(tex0.a-0.5f); #endif O.col = float4(I.depthUV.w,0,0,1); return O; } #endif //////////////////////////////////////////////////////////////// //SPASS_G pixel shader (SM1_1) //////////////////////////////////////////////////////////////// #ifdef PS_SPASS_G_11 struct pixdata { float4 hposition : POSITION; float4 texcoord0 : TEXCOORD0; float4 depthUV : TEXCOORD1; float4 posInLight : TEXCOORD2; float fog : FOG; }; #define VS_OUT_lowendFog #define VS_OUT_depthUV #define VS_OUT_posInLight #define VS_OUT_hposition fragout1 mainPS(pixdata I, uniform sampler2D texture0, uniform sampler2D shadow_map, uniform sampler3D textureVolume, uniform int anzIterations, uniform float4 shadow_data, uniform sampler2D gradient_texture) { fragout1 O; #ifdef IS_OPAQUE O.col = float4( 0,0,0,1 ); #else O.col = tex2D(texture0, I.texcoord0.xy); #endif return O; } #endif //////////////////////////////////////////////////////////////// //SPASS_SHADOWMAP pixel shader (unified) //////////////////////////////////////////////////////////////// #ifdef PS_SPASS_SHADOWMAP struct pixdata { float4 posInLight : POSITION; float4 texcoord0 : TEXCOORD0; }; #define VS_OUT_posInLight fragout1 mainPS(pixdata I, uniform sampler2D texture0, uniform float4 shadow_data) { fragout1 O; #if defined(SM1_1) s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); O.col.rgb = shadow_data.zzz; O.col.a = tex0.a; #else #ifdef IS_OPAQUE O.col = float4( 0,0,0,1 ); #else O.col = tex2D(texture0, I.texcoord0.xy); clip(O.col.a-0.5f); #endif #endif return O; } #endif //////////////////////////////////////////////////////////////// //SPASS_CUBEMAPSHADOW pixel shader (>=SM2_0) //////////////////////////////////////////////////////////////// #ifdef PS_SPASS_CUBESHADOWMAP_20 struct pixdata { float4 posInLight : POSITION; float4 texcoord0 : TEXCOORD0; float4 li_to_pix_w : TEXCOORD1; }; #define VS_OUT_li_to_pix_w #define VS_OUT_posInLight fragout1 mainPS(pixdata I, uniform sampler2D texture0, uniform float4 light_data) { fragout1 O; // need opacity-channel, since this is shadowmapping! float4 tex0 = tex2D(texture0, I.texcoord0.xy); // square distance of scaled float3 li_to_pix_w_s = light_data.z * I.li_to_pix_w.xyz; float sq_dist = saturate(dot(li_to_pix_w_s, li_to_pix_w_s)); // endcode it in rgb!! float3 depth_encoded = sq_dist * float3(1.0, 256.f, 256.f * 256.f); // do not put the .x component through the frac, this gives 0.0 for 1.0 -> ERRORs depth_encoded.yz = frac(depth_encoded.yz); // pass it to texture O.col = float4(depth_encoded, tex0.a); return O; } #endif ///////////////////////////////////////////////// //SPASS_AMBDIF pixel shader (SM1_1) ///////////////////////////////////////////////// #ifdef PS_SPASS_AMBDIF_NONORMAL_11 struct pixdata { float4 hposition : POSITION; float4 diffuse : COLOR0; float4 specular : COLOR1; float4 texcoord0 : TEXCOORD0; float fog : FOG; }; #define VS_OUT_lowendFog #define VS_OUT_hposition #define VS_OUT_SM1_LIGHTING fragout1 mainPS(pixdata I, uniform sampler2D texture0) { fragout1 O; // get texture values s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); O.col.rgb = tex0.rgb * I.diffuse.rgb; O.col.a = tex0.a; #if LAYER_BIT0 //O.col.a = tex0.a * calcHoleAlpha(I.hpos); #endif return O; } #endif// //#ifdef PS_SIMPLESHADOW // s2half shadow = calcShadowSimple(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x); //#else // s2half shadow = calcShadow(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x, anzIterations); //#endif ///////////////////////////////////////////////// //SPASS_AMBDIF pixel shader (>=SM2_0) ///////////////////////////////////////////////// #ifdef PS_SPASS_AMBDIF_NONORMAL_20 #define VS_OUT_hposition #define VS_OUT_diffuse #define VS_OUT_hpos #define VS_OUT_screenCoord #define VS_OUT_depthFog #define VS_OUT_camDist #define VS_OUT_lightDist #define VS_OUT_NORMAL #ifdef ENABLE_VERTEXLIGHTING #define VS_OUT_vertexLightData_nonrm #endif struct pixdata { float4 hposition : POSITION; float4 diffuse : COLOR0; float4 texcoord0 : TEXCOORD0; float4 hpos : TEXCOORD1; float4 screenCoord : TEXCOORD2; float2 depthFog : TEXCOORD3; float4 camDist : TEXCOORD4; float4 lightDist : TEXCOORD5; float4 normal : TEXCOORD6; #ifdef VS_OUT_vertexLightData_nonrm float4 vlColor : COLOR1; #endif }; fragout2 mainPS(pixdata I, uniform sampler2D texture0, uniform sampler2D shadow_map, uniform sampler3D textureVolume, uniform sampler2D shadow_texture, uniform sampler2D fog_texture, uniform int anzIterations, uniform float4 shadow_data, uniform float4 fog_color, uniform float4 light_col_amb, uniform float4 light_col_diff, uniform float4 param) { fragout2 O; // get texture values s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); #ifdef VS_OUT_vertexLightData light_col_amb += light_calc_heroLight(I.vlColor); #endif #ifdef VS_OUT_vertexLightData_nonrm light_col_amb.rgb += I.vlColor.rgb; light_col_amb += light_calc_heroLight(I.vlColor); light_col_amb = saturate(light_col_amb); #endif s2half3 l_dir = normalize(I.lightDist.xyz); s2half3 c_dir = normalize(I.camDist.xyz); s2half3 nrm = normalize(I.normal.xyz); float4 deferred_tex = tex2Dproj(shadow_texture, I.screenCoord); //calc sun diffuse float3 sun_diff = I.diffuse.xyz * light_col_diff.xyz * tex0.xyz; // calc moon diffuse float3 amb = light_col_amb.xyz * tex0.xyz; // calc specular float specular = pow(dot(c_dir, ((2.0 * dot(nrm, l_dir) * nrm) - l_dir)), 20); float3 specular_diff = light_col_diff.xyz; #ifdef VS_OUT_vertexLightData_nonrm specular_diff.xyz += I.vlColor.xyz; specular_diff += light_calc_heroLight(I.vlColor); specular_diff = saturate(specular_diff); #endif float3 spec = specular * dot(float3(0.2126, 0.7152, 0.0722), specular_diff.xyz) * max(dot(float3(0.2126, 0.7152, 0.0722), tex0.xyz), 0.33f) * sqrt(3) * normalize(specular_diff.xyz + tex0.xyz); /* #ifndef NO_SHADOWS #ifdef PS_SIMPLESHADOW s2half shadow = calcShadowSimple(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x); #else s2half shadow = calcShadow(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x, anzIterations); #endif sun_diff *= shadow; #endif */ #ifndef NO_SHADOWS sun_diff *= deferred_tex.z; #endif float3 new_color = float3(max(amb.x, max(sun_diff.x, spec.x)), max(amb.y, max(sun_diff.y, spec.y)), max(amb.z, max(sun_diff.z, spec.z))); #ifdef S2_FOG // calc fog fogDiffuse( new_color, fog_texture, I.depthFog, fog_color ); #endif // calc only diffuse O.col[0].xyz = new_color; O.col[0].a = tex0.a; #if TREE_HOLE O.col[0].a = calcHoleAlpha(I.hpos,param); #endif O.col[1] = float4(0.0, 0.0, 0.0, 0.0); #ifdef SIMPLECOLOR O.col[0] = tex0; O.col[1] = float4(0.0, 0.0, 0.0, 0.0); #endif return O; } #endif ///////////////////////////////////////////////// //SPASS_PNT pixel shader (>=SM2_0) ///////////////////////////////////////////////// #ifdef PS_SPASS_PNT_NONORMAL_20 struct pixdata { float4 hposition : POSITION; float4 texcoord0 : TEXCOORD0; float4 pix_to_li : TEXCOORD1; float4 normal : TEXCOORD2; float4 hpos : TEXCOORD3; float2 depthFog : TEXCOORD4; }; #define VS_OUT_hposition #define VS_OUT_pix_to_li #define VS_OUT_NORMAL #define VS_OUT_hpos #define VS_OUT_depthFog fragout2 mainPS(pixdata I, uniform sampler2D texture0, uniform sampler2D fog_texture, uniform float4 light_col_diff, uniform float4 light_data, uniform float4 param) { fragout2 O; // get texture values s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); // get normal vector from bumpmap texture s2half3 nrm = normalize(I.normal.xyz); // calc diffuse s2half3 l0_dir = normalize(I.pix_to_li.xyz); float4 diffuse = saturate(dot(l0_dir, nrm)) * light_col_diff; // calc distance of light float dist_to_light = dot(I.pix_to_li.xyz, I.pix_to_li.xyz); // build intensity from distance to light using light radius float temp_dist = saturate(dist_to_light * light_data.z * light_data.z); float intensity = (1.0 - temp_dist) * (1.0 - temp_dist); // 1.0 - sin(1.5708 * temp_dist); // multiply it by intensity of ight source intensity *= light_data.y; #ifdef S2_FOG // attenuate by fog fogPnt( intensity, fog_texture, I.depthFog ); //intensity *= (1.0 - tex2D( fog_texture, I.depthFog ).w); #endif #if TREE_HOLE intensity *= calcHoleAlpha(I.hpos,param); #endif O.col[0] = intensity * diffuse * tex0; O.col[0].a = tex0.a; O.col[1] = float4(0.0, 0.0, 0.0, 0.0); return O; } #endif ///////////////////////////////////////////////// //PS_SPASS_LIGHTNING pixel shader (>=SM2_0) ///////////////////////////////////////////////// #ifdef PS_SPASS_LIGHTNING_NONORMAL_20 struct pixdata { float4 hposition : POSITION; float4 texcoord0 : TEXCOORD0; float4 lightDist : TEXCOORD1; float2 depthFog : TEXCOORD2; }; #define VS_OUT_hposition #define VS_OUT_lightDist #define VS_OUT_depthFog fragout2 mainPS(pixdata I, uniform sampler2D texture0, uniform sampler2D fog_texture, uniform float4 light_col_amb, uniform float4 system_data) { fragout2 O; // get texture values s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); // calc to-face-lightning float is2Lightning = step(0.2, I.lightDist.w); O.col[0] = float4(is2Lightning * light_col_amb.w * float3(1.0, 1.0, 1.0), tex0.a); O.col[1] = float4(is2Lightning * light_col_amb.w * light_col_amb.xyz, 0.0); #ifdef S2_FOG // calc fog fogGlow( O.col[0].xyz, fog_texture, I.depthFog ); fogGlow( O.col[1].xyz, fog_texture, I.depthFog ); #endif return O; } #endif ///////////////////////////////////////////////// //PS_DUMMY_11 pixel shader (SM1_1) ///////////////////////////////////////////////// #ifdef PS_DUMMY_11 struct pixdata { float4 hposition : POSITION; float4 texcoord0 : TEXCOORD0; }; #define VS_OUT_hposition fragout1 mainPS(pixdata I, uniform sampler2D texture0) { fragout1 O; O.col = tex2D(texture0, I.texcoord.xy); return O; } #endif ///////////////////////////////////////////////// //PS_NULL_11 pixel shader (SM1_1) ///////////////////////////////////////////////// #ifdef PS_NULL_11 struct pixdata { float4 hposition : POSITION; float4 texcoord0 : TEXCOORD0; }; #define VS_OUT_hposition fragout1 mainPS(pixdata I) { fragout1 O; O.col = float4(0,0,0,0); return O; } #endif ///////////////////////////////////////////////// //PS_NULL_20 pixel shader (SM2_0) ///////////////////////////////////////////////// #ifdef PS_NULL_20 struct pixdata { float4 hposition : POSITION; float4 texcoord0 : TEXCOORD0; }; #define VS_OUT_hposition fragout2 mainPS(pixdata I) { fragout2 O; O.col[0] = float4(0,0,0,0); O.col[1] = float4(0,0,0,0); return O; } #endif ///////////////////////////////////////////////// //PASS_AMBDIF pixel shader (>=SM2_0) ///////////////////////////////////////////////// #ifdef PS_TRUNK_SPASS_AMBDIF_20 #define VS_OUT_hposition #define VS_OUT_screenCoord #define VS_OUT_hpos #define VS_OUT_camDist #define VS_OUT_lightDist #define VS_OUT_posInLight #define VS_OUT_depthFog #ifdef ENABLE_VERTEXLIGHTING #define VS_OUT_vertexLightData #endif struct pixdata { float4 hposition : POSITION; float4 texcoord0 : TEXCOORD0; float4 camDist : TEXCOORD1; float4 lightDist : TEXCOORD2; float4 screenCoord : TEXCOORD3; float4 hpos : TEXCOORD4; float4 posInLight : TEXCOORD5; float2 depthFog : TEXCOORD6; #ifdef VS_OUT_vertexLightData float4 vlColor : COLOR0; float4 vlNormal : TEXCOORD7; #endif }; fragout2 mainPS(pixdata I, float2 vPos : VPOS, uniform sampler2D texture0, uniform sampler2D texture1, uniform sampler2D texture2, uniform sampler2D texture3, uniform sampler2D shadow_texture, uniform sampler3D textureVolume, uniform sampler2D fog_texture, uniform sampler2D shadow_map, uniform sampler3D noise_map, uniform float4 shadow_data, uniform float4 fog_color, uniform float4 system_data, uniform float4 light_col_amb, uniform float4 light_col_diff, uniform float4 param) { fragout2 O; // get texture values s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); s2half4 tex1 = decode_normal(tex2D(texture1, I.texcoord0.xy)); s2half3 nrm = tex1.xyz; // get normal vector from bumpmap texture // s2half4 tex1 = tex2D(texture1, I.texcoord0.xy); // s2half3 nrm = normalize(tex1.xyz - s2half3(0.5, 0.5, 0.5)); float4 light_hero = light_col_amb; #ifdef VS_OUT_vertexLightData light_hero += light_calc_heroLight(I.vlColor) + light_calc_vertexlighting(nrm,I.vlColor,normalize(I.vlNormal.xyz)); #endif light_hero = saturate(light_hero); light_hero = light_hero - light_col_amb; // get shadow term from shadow texture #ifdef NO_SHADOWS s2half4 shadow = float4(1.0f, 1.0f, 1.0f, 1.0f); #else #ifdef TREE_HOLE s2half4 shadow = calcShadowSimple(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x); #else s2half4 shadow = tex2Dproj(shadow_texture, I.screenCoord); #endif #endif /* shadow *= (dot(light_hero.xyz, light_hero.xyz) / sqrt(3.0f)); float newshadow = saturate(shadow.z); newshadow = 1.0f - shadow; newshadow = pow(shadow, 5); newshadow = 1.0f - shadow; */ // lighting s2half3 l_dir = normalize(I.lightDist.xyz); s2half3 c_dir = normalize(I.camDist.xyz); float lightValueSun = saturate(dot(l_dir, nrm)); float lightValueMoon = saturate(dot(c_dir, nrm)); // calc sun diffuse float3 sun_diff = shadow.z * (light_col_diff.xyz + light_hero.xyz) * tex0.xyz * lightValueSun; //calc moon diffuse float3 moon_diff = (light_col_amb.xyz + light_hero.xyz) * tex0.xyz * lightValueMoon; // calc specular float specular = pow(dot(c_dir, ((2.0 * dot(nrm, l_dir) * nrm) - l_dir)), 20); float3 specular_diff = light_col_diff.xyz; #ifdef VS_OUT_vertexLightData float4 addvalue = light_calc_heroLight(I.vlColor) + light_calc_vertexlighting(nrm,I.vlColor,normalize(I.vlNormal.xyz)); specular_diff.xyz += addvalue.xyz; specular_diff = saturate(specular_diff); #endif float3 spec = shadow.z * specular * dot(float3(0.2126, 0.7152, 0.0722), specular_diff.xyz) * max(dot(float3(0.2126, 0.7152, 0.0722), tex0.xyz), 0.33f) * sqrt(3) * normalize(specular_diff.xyz + tex0.xyz); //compose float3 new_color = float3(max(moon_diff.x, max(sun_diff.x, spec.x)), max(moon_diff.y, max(sun_diff.y, spec.y)), max(moon_diff.z, max(sun_diff.z, spec.z))); //TEnergy sTEnergy tenergy; calc_tenergy(tenergy,noise_map,texture2,texture3,I.texcoord0.xy,-I.texcoord0.y,system_data.x); #ifdef S2_FOG // calc fog fogDiffuse( new_color, fog_texture, I.depthFog, fog_color ); #endif // set output color O.col[0].rgb = new_color; O.col[0].a = 1; #if TREE_HOLE O.col[0].a = calcHoleAlpha(I.hpos,param.x); #endif O.col[1] = float4(0.0, 0.0, 0.0, 0.0); #ifdef USE_TENERGY // float tescale = pow(tex0.a,3); float tescale = tex0.a * tex0.a; O.col[0].xyz += tenergy.color0*tescale; O.col[1].xyz += tenergy.color1*tescale; #endif #ifdef SPASS_LIGHTNING // calc to-face-lightning float is2Lightning = saturate(step(0.2, dot(nrm, I.lightDist.xyz)) + (dot(light_hero.xyz, light_hero.xyz) / sqrt(3.0f))); O.col[0] = float4(is2Lightning * light_col_amb.w * float3(1.0, 1.0, 1.0), 1.0); O.col[1] = float4(is2Lightning * light_col_amb.w * (light_col_amb.xyz + light_hero.xyz), 0.0); #endif #ifdef SIMPLECOLOR O.col[0] = float4(1,1,1,1); #endif return O; } #endif ///////////////////////////////////////////////// //PASS_PNT pixel shader (>=SM2_0) ///////////////////////////////////////////////// #ifdef PS_TRUNK_SPASS_PNT_20 struct pixdata { float4 hposition : POSITION; float4 texcoord0 : TEXCOORD0; float4 pix_to_li_t : TEXCOORD1; float4 pix_to_c : TEXCOORD2; float4 pix_to_li_o : TEXCOORD3; float2 depthFog : TEXCOORD4; }; #define VS_OUT_hposition #define VS_OUT_pix_to_li_T #define VS_OUT_pix_to_li_O #define VS_OUT_PIX_TO_C #define VS_OUT_depthFog fragout2 mainPS(pixdata I, uniform sampler2D texture0, uniform sampler2D texture1, uniform sampler2D fog_texture, uniform float4 light_col_diff, uniform float4 light_data) { fragout2 O; // get texture values s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); s2half4 tex1 = tex2D(texture1, I.texcoord0.xy); // get normal vector from bumpmap texture s2half3 nrm = normalize(tex1.xyz - s2half3(0.5, 0.5, 0.5)); // calc diffuse s2half3 l0_dir = normalize(I.pix_to_li_t.xyz); float4 diffuse = saturate(dot(l0_dir, nrm)) * light_col_diff; // calc specular s2half3 c_dir = normalize(I.pix_to_c.xyz); s2half3 half_vec = normalize(l0_dir + c_dir); float4 specular = pow(saturate(dot(half_vec, nrm)), 20.0) * tex1.w * light_col_diff; // calc distance of light float dist_to_light = dot(I.pix_to_li_o.xyz, I.pix_to_li_o.xyz); // build intensity from distance to light using light radius float temp_dist = saturate(dist_to_light * light_data.z * light_data.z); float intensity = (1.0 - temp_dist) * (1.0 - temp_dist); // 1.0 - sin(1.5708 * temp_dist); // multiply it by intensity of ight source intensity *= light_data.y; #ifdef S2_FOG // fog fogPnt( intensity, fog_texture, I.depthFog ); #endif O.col[0] = intensity * ((diffuse * tex0) + specular); O.col[0].a = tex0.a; O.col[1] = float4(0.0, 0.0, 0.0, 0.0); return O; } #endif DEFINE_VERTEX_DATA //////////////////////////////////////////////////////////////// //Unified Vertex shader used for all shader models //////////////////////////////////////////////////////////////// pixdata mainVS(appdata I, uniform float4 vtx_data_array[32], uniform float4x4 vtx_matrix_array[4], VS_PARAM_BLOCK) { pixdata O; EXTRACT_VERTEX_VALUES // apply wind and calc extreme (=1.0) position float4 wind_pos4 = mul(pos4, vtx_matrix_array[windidx]); // now interpolate between org pos and extr pos pos4 = lerp(pos4, wind_pos4, windLerpFact); #ifdef VS_IN_TREELEAFVERTEX float leaf_scale = param.z; // get vertex billboard offset from array and scale it by size float4 offs4 = data2.y * vtx_data_array[data2.x] * leaf_scale; // transform this offset backwards with inv objmat, so it is "billboarded" after next transform pos4 += mul(offs4, invWorldMatrix); #endif #ifdef VS_OUT_vertexLightData_nonrm O.vlColor = computeVertexLightingColor(pos4,nrm4); #endif #ifdef VS_OUT_vertexLightData computeVertexLightingColorNormal( O.vlColor, O.vlNormal,pos4); #endif // convert vertex pos from objspace to screen space float4 wvp_pos = mul(pos4, worldViewProjMatrix); float camSpaceZ = pos4.x*worldViewMatrix[0][2] + pos4.y*worldViewMatrix[1][2] + pos4.z*worldViewMatrix[2][2] + worldViewMatrix[3][2]; // convert vertex pos from objspace to worldspace float4 worldVertPos = mul(pos4, worldMatrix); float3 worldVertNormal = normalize(mul(nrm4.xyz, (float3x3) worldMatrix)); O.texcoord0 = uv0; #ifdef VS_OUT_depthFog O.depthFog = getFogTCs( wvp_pos.w, fog_data ); //O.depthFog.x = saturate( (wvp_pos.w - fog_data.x) * zfrustum_data.z ); //O.depthFog.y = fog_data.w; #endif #ifdef VS_OUT_hposition // vertex pos O.hposition = wvp_pos; #endif #ifdef VS_OUT_SM1_TEXCOORD1 O.texcoord1 = uv0; #endif #ifdef VS_OUT_depthUV O.depthUV = float4(0,0,0,-camSpaceZ*zfrustum_data.w); #endif #ifdef VS_OUT_posInLight // vertex pos in light-space O.posInLight = mul(pos4, lightMatrix); #endif #ifdef VS_OUT_li_to_pix_w // pass light-to-pixel to fragment shader O.li_to_pix_w = worldVertPos - light_pos; #endif // convert light pos from worldspace into objectspace float4 l_pos_obj = mul(light_pos, invWorldMatrix); // build vector from vertex pos to light pos float3 vertex_to_light = l_pos_obj.xyz - pos4.xyz; // convert cam pos from worldspace into objectspace float4 c_pos_obj = mul(camera_pos, invWorldMatrix); // build vector from vertex pos to cam pos #ifdef MINIMAPMODE float3 vertex_to_cam = c_pos_obj; #else float3 vertex_to_cam = c_pos_obj.xyz - pos4.xyz; #endif // convert light direction vector from worldspace to objectspace float4 l0_dir_obj = mul(light_pos, invWorldMatrix); // convert camera direction vector from worldspace to objectspace float4 c_dir_obj = mul(camera_pos, invWorldMatrix); #ifdef VERT_TREEVERTEX // build object-to-tangent space matrix float3x3 objToTangentSpace; objToTangentSpace[0] = -1.0 * tan3; objToTangentSpace[1] = -1.0 * bin3; objToTangentSpace[2] = nrm4.xyz; // convert vertex_to_light from objectspace to tangentspace float3 vertex_to_light_tan = mul(objToTangentSpace, vertex_to_light); // convert vertex_to_cam from objectspace to tangentspace float3 vertex_to_cam_tan = mul(objToTangentSpace, vertex_to_cam); // convert light direction vector from objectspace to tangentspace float3 l0_dir_tan = mul(objToTangentSpace, l0_dir_obj.xyz); // calc direction vector from vertex position to camera-position c_dir_obj -= pos4; // convert camera direction vector from objectspace to tangentspace float3 c_dir_tan = mul(objToTangentSpace, c_dir_obj.xyz); #ifdef VS_OUT_lightDist // store light vector O.lightDist = float4(l0_dir_tan, 0.0); #endif #ifdef VS_OUT_camDist // store camera vec in texcoord2 O.camDist = float4(c_dir_tan, 0.0); #endif #else #ifdef VS_OUT_lightDist // store light vector & dot O.lightDist = float4(l0_dir_obj.xyz, dot(nrm4.xyz, l0_dir_obj.xyz)); #endif #ifdef VS_OUT_camDist // store camera vec in texcoord2 O.camDist = float4(c_dir_obj.xyz, dot(nrm4.xyz, c_dir_obj.xyz)); #endif #endif #ifdef VS_OUT_vertexLightData O.vlNormal.xyz = mul(objToTangentSpace, O.vlNormal.xyz); #endif #ifdef VS_OUT_hpos // pass screenpos to fragment shader O.hpos = O.hposition; O.hpos.xy *= param.xy; #endif #ifdef VS_OUT_NORMAL // norma O.normal = nrm4; #endif #ifdef VS_OUT_screenCoord // vertex-position in screen space O.screenCoord = calcScreenToTexCoord(O.hposition); #endif #ifdef VS_OUT_SM1_LIGHTING O.diffuse = calcLight(worldVertPos, worldVertNormal, camera_pos, globLightData, O.specular); #endif #ifdef VS_OUT_diffuse // convert light direction vector from worldspace to objectspace float4 l0_dir = mul(light_pos, invWorldMatrix); float diffuse = saturate(dot(nrm4, l0_dir)); // prepare color O.diffuse = float4(diffuse, diffuse, diffuse, 1.0); #endif #ifdef VS_OUT_lowendFog O.fog = calcFog(O.hposition, fog_data); #endif // pass vertex to light to pixelshader, so it becomes pixel to light #ifdef VS_OUT_pix_to_li_T O.pix_to_li_t = float4(vertex_to_light_tan, 0.0); #endif #ifdef VS_OUT_pix_to_li_O O.pix_to_li_o = float4(vertex_to_light, 0.0); #endif #ifdef VS_OUT_pix_to_li // pass vertex to light to pixelshader, so it becomes pixel to light O.pix_to_li = float4(vertex_to_light, 0.0); #endif #ifdef VS_OUT_PIX_TO_C // pass vertex to cam to pixelshader, so it becomes pixel to cam O.pix_to_c = float4(vertex_to_cam_tan, 0.0); #endif return O; } Improvements like specular now also working for the hero light (seraphim light FX), color depending both on sunlight and texturelight, gamma correction and max amount of specular dimming from texture color are included. Most of these come from me experimenting with the fur shader. This is also the file which I'm going to use in my mod. With me you never know wether it's the final version or not Edited July 24, 2022 by Lindor Link to comment
Lindor 438 Posted July 24, 2022 Author Share Posted July 24, 2022 31 minutes ago, Lindor said: This is also the file which I'm going to use in my mod. With me you never know wether it's the final version or not The moment I wrote it and I had another idea for an improvement. Code in previous post has been updated. Link to comment
Vishanka 236 Posted July 25, 2022 Share Posted July 25, 2022 Tested the code now; the plants (tree_branch) get a grayish hue in some angles it's like they were made of shiny paper, would recommend to change that... the tree_tree shader did something alike but it looked different and more fitting, trying to get a video Link to comment
Vishanka 236 Posted July 25, 2022 Share Posted July 25, 2022 Here, the plants are too dark in general with tree_tree but when I tilt the camera it gets lighter and darker, I think that would be a nice effect to add for tree_branch There is a position where a for my taste unwanted white hue can be seen but its hard to get an angle to see it Link to comment
Vishanka 236 Posted July 25, 2022 Share Posted July 25, 2022 And one final request... a different topic but still shaders... Could you please do something with the hair at night and with light aura? It is not affected by light aura at all and it's getting too dark at night in general compared to the skin if you ask me The entry in surface.txt should be this one... hopefully I tried to just replace the shader with skin shader and even metal but it aint do nothin' so I'm not sure if I'm at the right spot. It's the only entry for that seraphim hair. newSurface = { name = "sera_hair1_surf", texture0Name = "maps/heroes/seraphim/sera_hair1_do.tga", texture2Name = "maps/heroes/seraphim/sera_hair1_sc.tga", flags = SURFACE_FLAG_MASKED, shader = obj_hair, } mgr.surfCreate(newSurface); Link to comment
Lindor 438 Posted July 25, 2022 Author Share Posted July 25, 2022 Sry I'm a little bit confused. When did you use what shader? My assumptions are: 54 minutes ago, Vishanka said: Tested the code now; the plants (tree_branch) get a grayish hue in some angles it's like they were made of shiny paper, would recommend to change that... the tree_tree shader did something alike but it looked different and more fitting, trying to get a video I think you used tree_Branch or tree_Leaves (doesn't matter, as I said both use the same pixel shader) for the plant? If that is so, then the only possibility I see is to completely remove the specular effect. It happens because in object space, the whole plant is flat to the camera angle so the whole plant is considered to be the middle of the specular reflection. 36 minutes ago, Vishanka said: There is a position where a for my taste unwanted white hue can be seen but its hard to get an angle to see it This is the specular effect. I made it so that at nighttime, it's only present if you have the hero light FX on. So it's a (camera-angle dependent) reflection from your hero character's light. Turn the buff off and there's no specular anymore. No idea which shader you used. I'm getting mixed feedback here. For the video you said you liked the effect, but here you say you don't like it? Or you mean that in general you like it, but you want it more dimmed? 38 minutes ago, Vishanka said: Here, the plants are too dark in general with tree_tree but when I tilt the camera it gets lighter and darker, I think that would be a nice effect to add for tree_branch So here I'm completely confused. Is this the same plant that got completely grey, but this time with tree_Tree shader? That should not happen. I have no idea why it works correctly when applying tree_Tree. The tree_Tree is calculating the normal vectors from a bumpmap, the normal map. But wasn't it so that this plant has no normal map? The question is, what is the surface.txt entry of this plant? If it has a normal map, then it is an exception that it works with tree_Tree. Then most plants won't work the same way, because they don't have a bumpmap. If it doesn't, then I have no idea why it works in the video. There is no way to detect from inside the shader wether a bumpmap is present or not, sadly. So either it's always calculating it from a bumpmap (and thus failing if it isn't present) or always in object space (and thus having the problem that 2d plants sometimes get lighted up because they're flat). 27 minutes ago, Vishanka said: And one final request... a different topic but still shaders... Could you please do something with the hair at night and with light aura? It is not affected by light aura at all and it's getting too dark at night in general compared to the skin if you ask me The entry in surface.txt should be this one... hopefully I tried to just replace the shader with skin shader and even metal but it aint do nothin' so I'm not sure if I'm at the right spot. It's the only entry for that seraphim hair. The obj_hair shader is a dummy shader: obj_hair = { diffusePnt = "null.shader", diffusePntShd = "null.shader", z = "object/hairZ.shader", shadowmap = "null.shader", cubeshadowmap = "null.shader", ambDiff = "null.shader", } Only z is defined. There exists unified/object/hair.shader though. Maybe if you're lucky, this is the shader used. If that is so, I can maybe add the hero lighting for the hair. Link to comment
Vishanka 236 Posted July 25, 2022 Share Posted July 25, 2022 (edited) 26 minutes ago, Lindor said: Sry I'm a little bit confused. When did you use what shader? When I replaced the treeShared.shader with your changes and got the grayish hue I did not make any additional changes. When I took the video I reverted treeShared.shader to original and replaced tree_Branch for that one plant with tree_Tree in surface.txt, nothing else. 26 minutes ago, Lindor said: This is the specular effect. I made it so that at nighttime, it's only present if you have the hero light FX on. So it's a (camera-angle dependent) reflection from your hero character's light. Turn the buff off and there's no specular anymore. No idea which shader you used. It's also present without the aura but weaker, and it does not look like the effect that tree_tree does. 26 minutes ago, Lindor said: I'm getting mixed feedback here. For the video you said you liked the effect, but here you say you don't like it? Or you mean that in general you like it, but you want it more dimmed? the tree_tree shader seems to do the light and shadow differently so not the whole plant gets covered with a gray layer, it's patchy and it keeps the saturation so it's just lighter (or maybe the shadows are responsible for the effect, not the light?) and when tilting or turning the camera that changes the lighting on the plant, that's what makes it look dynamic 26 minutes ago, Lindor said: The question is, what is the surface.txt entry of this plant it's still the arizona plant, I never used anything else newSurface = { name = "ArizonaBush_f", texture0Name = "maps/trees/ArizonaBush_l_do.tga", flags = SURFACE_FLAG_MASKED, shader = tree_Branch, } mgr.surfCreate(newSurface); when I revert everything to original and use the tree_tree that's the only change I make: newSurface = { name = "ArizonaBush_f", texture0Name = "maps/trees/ArizonaBush_l_do.tga", flags = SURFACE_FLAG_MASKED, shader = tree_Tree, } mgr.surfCreate(newSurface); Edited July 25, 2022 by Vishanka Link to comment
Lindor 438 Posted July 25, 2022 Author Share Posted July 25, 2022 23 minutes ago, Vishanka said: It's also present without the aura but weaker, and it does not look like the effect that tree_tree does. I think you confused something here? The image shows the whole plant getting desaturated issue, but I was writing about this: 1 hour ago, Vishanka said: There is a position where a for my taste unwanted white hue can be seen but its hard to get an angle to see it This is the specular effect. I don't see this in the other picture. It's not there at nighttime without the light CA. I'm trying to replicate the whole plant desaturation thing, so far no luck. Link to comment
Vishanka 236 Posted July 25, 2022 Share Posted July 25, 2022 (edited) 11 minutes ago, Lindor said: This is the specular effect. I don't see this in the other picture. It's not there at nighttime without the light CA. This is with the tree_Tree shader, if that white spot could be removed and the rest with the patchy lighting (or the patchy shadows or whatever it does) could be used on tree_branch it's what I would suggest to do to the plants, just not as dark as tree_tree does it. maybe that all comes from the specular but tree_tree definitely applies it differently somehow 11 minutes ago, Lindor said: I'm trying to replicate the whole plant desaturation thing, so far no luck. I'm curious, if that were possible I think it would look amazing that way Edited July 25, 2022 by Vishanka Link to comment
Lindor 438 Posted July 25, 2022 Author Share Posted July 25, 2022 By the way, that tree_Tree is too dark should not be the case anymore, it should be fixed. 7 minutes ago, Vishanka said: This is with the tree_Tree shader, if that white spot could be removed and the rest with the patchy lighting (or the patchy shadows or whatever it does) could be used on tree_branch it's what I would suggest to do to the plants, just not as dark as tree_tree does it. maybe that all comes from the specular but tree_tree definitely applies it differently somehow I think the white is the specular and the patches come from the shadow calculation. I'll see if I can add a more advanced shadow to branch/leaves and remove the specular. 18 minutes ago, Lindor said: I'm trying to replicate the whole plant desaturation thing, so far no luck. I could kinda replicate it: It is as I thought, it's an unfortunate combination of the specular effect and the plant's 2d-flatness. Maybe I can set a max amount of % saturation decrease. Link to comment
Lindor 438 Posted July 25, 2022 Author Share Posted July 25, 2022 3 minutes ago, Lindor said: I think the white is the specular and the patches come from the shadow calculation. I'll see if I can add a more advanced shadow to branch/leaves and remove the specular. actually there's no point in doing that over just removing specular from tree_Tree and using that for everything: Spoiler #ifdef PS_TRUNK_SPASS_AMBDIF_20 #define VS_OUT_hposition #define VS_OUT_screenCoord #define VS_OUT_hpos #define VS_OUT_camDist #define VS_OUT_lightDist #define VS_OUT_posInLight #define VS_OUT_depthFog #ifdef ENABLE_VERTEXLIGHTING #define VS_OUT_vertexLightData #endif struct pixdata { float4 hposition : POSITION; float4 texcoord0 : TEXCOORD0; float4 camDist : TEXCOORD1; float4 lightDist : TEXCOORD2; float4 screenCoord : TEXCOORD3; float4 hpos : TEXCOORD4; float4 posInLight : TEXCOORD5; float2 depthFog : TEXCOORD6; #ifdef VS_OUT_vertexLightData float4 vlColor : COLOR0; float4 vlNormal : TEXCOORD7; #endif }; fragout2 mainPS(pixdata I, float2 vPos : VPOS, uniform sampler2D texture0, uniform sampler2D texture1, uniform sampler2D texture2, uniform sampler2D texture3, uniform sampler2D shadow_texture, uniform sampler3D textureVolume, uniform sampler2D fog_texture, uniform sampler2D shadow_map, uniform sampler3D noise_map, uniform float4 shadow_data, uniform float4 fog_color, uniform float4 system_data, uniform float4 light_col_amb, uniform float4 light_col_diff, uniform float4 param) { fragout2 O; // get texture values s2half4 tex0 = tex2D(texture0, I.texcoord0.xy); s2half4 tex1 = decode_normal(tex2D(texture1, I.texcoord0.xy)); s2half3 nrm = tex1.xyz; // get normal vector from bumpmap texture // s2half4 tex1 = tex2D(texture1, I.texcoord0.xy); // s2half3 nrm = normalize(tex1.xyz - s2half3(0.5, 0.5, 0.5)); float4 light_hero = light_col_amb; #ifdef VS_OUT_vertexLightData light_hero += light_calc_heroLight(I.vlColor) + light_calc_vertexlighting(nrm,I.vlColor,normalize(I.vlNormal.xyz)); #endif light_hero = saturate(light_hero); light_hero = light_hero - light_col_amb; // get shadow term from shadow texture #ifdef NO_SHADOWS s2half4 shadow = float4(1.0f, 1.0f, 1.0f, 1.0f); #else #ifdef TREE_HOLE s2half4 shadow = calcShadowSimple(shadow_map, textureVolume, I.posInLight, vPos, shadow_data.y, shadow_data.x); #else s2half4 shadow = tex2Dproj(shadow_texture, I.screenCoord); #endif #endif /* shadow *= (dot(light_hero.xyz, light_hero.xyz) / sqrt(3.0f)); float newshadow = saturate(shadow.z); newshadow = 1.0f - shadow; newshadow = pow(shadow, 5); newshadow = 1.0f - shadow; */ // lighting s2half3 l_dir = normalize(I.lightDist.xyz); s2half3 c_dir = normalize(I.camDist.xyz); float lightValueSun = saturate(dot(l_dir, nrm)); float lightValueMoon = saturate(dot(c_dir, nrm)); // calc sun diffuse float3 sun_diff = shadow.z * (light_col_diff.xyz + light_hero.xyz) * tex0.xyz * lightValueSun; //calc moon diffuse float3 moon_diff = (light_col_amb.xyz + light_hero.xyz) * tex0.xyz * lightValueMoon; //compose float3 new_color = float3(max(moon_diff.x, sun_diff.x), max(moon_diff.y, sun_diff.y), max(moon_diff.z, sun_diff.z)); //TEnergy sTEnergy tenergy; calc_tenergy(tenergy,noise_map,texture2,texture3,I.texcoord0.xy,-I.texcoord0.y,system_data.x); #ifdef S2_FOG // calc fog fogDiffuse( new_color, fog_texture, I.depthFog, fog_color ); #endif // set output color O.col[0].rgb = new_color; O.col[0].a = 1; #if TREE_HOLE O.col[0].a = calcHoleAlpha(I.hpos,param.x); #endif O.col[1] = float4(0.0, 0.0, 0.0, 0.0); #ifdef USE_TENERGY // float tescale = pow(tex0.a,3); float tescale = tex0.a * tex0.a; O.col[0].xyz += tenergy.color0*tescale; O.col[1].xyz += tenergy.color1*tescale; #endif #ifdef SPASS_LIGHTNING // calc to-face-lightning float is2Lightning = saturate(step(0.2, dot(nrm, I.lightDist.xyz)) + (dot(light_hero.xyz, light_hero.xyz) / sqrt(3.0f))); O.col[0] = float4(is2Lightning * light_col_amb.w * float3(1.0, 1.0, 1.0), 1.0); O.col[1] = float4(is2Lightning * light_col_amb.w * (light_col_amb.xyz + light_hero.xyz), 0.0); #endif #ifdef SIMPLECOLOR O.col[0] = float4(1,1,1,1); #endif return O; } #endif With this code and using tree_Tree for the plants, does it look more like you want to? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now