SkepticalFox 1,425 #449637 Posted February 5, 2019 (edited) хорошо бы научиться строить шейдеры для 3d max'а ... хочется как в Qt3D - через графы шейдеры писать надо на питоне написать утилитку для этого... Edited February 6, 2019 by SkepticalFox 2 Quote Share this post Link to post Short link Share on other sites
Pavel3333 1,147 #449646 Posted February 6, 2019 6 часов назад, SkepticalFox сказал: через графы шейдеры писать IDA Pro напомнило :) Quote Share this post Link to post Short link Share on other sites
SkepticalFox 1,425 #449659 Posted February 6, 2019 @Pavel3333 скорее анрил энжин Quote Share this post Link to post Short link Share on other sites
Pavel3333 1,147 #464350 Posted July 25, 2019 Quote Share this post Link to post Short link Share on other sites
SkepticalFox 1,425 #500350 Posted April 11, 2021 (edited) https://github.com/Unity-Technologies/HLSLcc Quote This library takes DirectX bytecode as input, and translates it into the following languages: GLSL (OpenGL 3.2 and later) GLSL WOT.zip Edited April 11, 2021 by SkepticalFox 2 Quote Share this post Link to post Short link Share on other sites
Monstrofil 60 #534749 Posted May 11 Когда-то давно натыкался на ошибочно запакованные в файлы клиента сорсы шейдеров салолётиков, сегодня случайно наткнулся повторно. Закину сюда в тему, может пригодится кому-нибудь. #include "stdinclude.fxh" #define DUAL_UV 1 #if SKINNED #include "skinned_effect_include.fxh" #else #include "unskinned_effect_include.fxh" #endif // BW_DIFFUSE_LIGHTING BW_SPECULAR_LIGHTING BW_ARTIST_EDITABLE_DOUBLE_SIDED BW_ARTIST_EDITABLE_DIFFUSE_MAP BW_ARTIST_EDITABLE_NORMAL_MAP texture reflectionMap : EnvMap; BW_ARTIST_EDITABLE_REFLECTION_AMOUNT BW_ARTIST_EDITABLE_ALPHA_TEST BW_ARTIST_EDITABLE_ADDRESS_MODE(BW_WRAP) sampler reflectionSampler = BW_SAMPLER(reflectionMap, WRAP) samplerCUBE reflectionCubeSampler = BW_SAMPLER_NON_MIPMAP_BIASED( reflectionMap, CLAMP ) //samplerCUBE reflectionCubeSampler = BW_SAMPLER( reflectionMap, CLAMP ) BW_ARTIST_EDITABLE_FRESNEL #include "common.fxh" texture specularPowerMap < bool artistEditable = true; string UIName = "Specular Parameters Map"; string UIDesc = "The specular and other parameters"; >; #ifndef AIRCRAFT_OBJECT texture camuflageMap : CamuflageMap; texture decals : DecalMap; texture selfShadowMap : SelfShadow; #endif float glossinessOffset : GlossinessOffset; #if defined(AIRCRAFT_OBJECT) float4 bottomColor : BottomColor; #endif // TODO #include "normalmap_chrome.fxh" OR "material_helpers.fxh" instead of the "materialSpecular" declaration /* float materialSpecular < bool artistEditable = true; string UIName = "Not used"; string UIDesc = "Not used"; > = 0.0; */ float4 materialSpecular\ < \ bool artistEditable = true;\ string UIWidget = "Color"; \ string UIName = "Specular Colour";\ string UIDesc = "The specular colour for the material";\ float UIMin = 0;\ float UIMax = 2;\ int UIDigits = 1;\ > = {1,1,1,1}; float selfIllumination < bool artistEditable = true; string UIName = "Not used"; string UIDesc = "Not used"; > = 0.0; /* float specularPower < bool artistEditable = true; string UIName = "Not used"; string UIDesc = "Not used"; > = 0.0; */ /* float glossiness_shift < bool artistEditable = true; string UIName = "Not used"; string UIDesc = "Not used"; > = 0; */ float normalmap_weight < bool artistEditable = true; string UIName = "Normalmap Weight"; string UIDesc = "Normalmap Weight"; float UIMin = 0; float UIMax = 1; int UIDigits = 2; > = 1.0; bool gloss_const_enabled < bool artistEditable = true; string UIName = "Glossiness Constant Enabled"; string UIDesc = "Whether to use the constant value for glossiness"; > = false; float gloss_const < bool artistEditable = true; string UIName = "Not used"; string UIDesc = "Not used"; > = 0.5; /* float gloss_const_weight < bool artistEditable = true; string UIName = "Not used"; string UIDesc = "Not used"; > = 0; */ /* float cubemap_saturation < bool artistEditable = true; string UIName = "Not used"; string UIDesc = "Not used"; > = 0; */ sampler diffuseSampler = BW_SAMPLER(diffuseMap, BW_TEX_ADDRESS_MODE) sampler normalSampler = BW_SAMPLER(normalMap, BW_TEX_ADDRESS_MODE) sampler specularPowerSampler = BW_SAMPLER(specularPowerMap, BW_TEX_ADDRESS_MODE) #ifndef AIRCRAFT_OBJECT sampler camuflageSampler = BW_SAMPLER(camuflageMap, BW_TEX_ADDRESS_MODE) sampler decalSampler = BW_SAMPLER(decals, BW_TEX_ADDRESS_MODE) #ifndef AIRCRAFT_NO_SELFSHADOW sampler selfShadowSampler = BW_SAMPLER(selfShadowMap, BW_TEX_ADDRESS_MODE) #endif #endif float4x4 worldViewProj : WorldViewProjection; float4x4 worldView : WorldView; struct PS_INPUT { float4 pos : POSITION; float2 tc : TEXCOORD0; float3 wPos : TEXCOORD1; float3 vPos : TEXCOORD2; float3 vBinormal : TEXCOORD3; float3 vTangent : TEXCOORD4; float3 vNormal : TEXCOORD5; float2 tc2: TEXCOORD8; }; #if SKINNED PS_INPUT vs_main_uv1(VertexXYZNUVIIIWWTB i) #else PS_INPUT vs_main_uv1(VertexXYZNUVTB i) #endif { PS_INPUT o=(PS_INPUT)0; PROJECT_POSITION( o.pos ) o.tc = i.tc; o.tc2 = float2(0,0); o.wPos = worldPos.xyz; o.vPos = mul(float4(worldPos.xyz, 1.0f), g_viewMat); // // // #if SKINNED CALCULATE_TS_MATRIX float3 vBinormal = normalize(mul(tsMatrix[1], g_viewMat)).xyz; float3 vTangent = normalize(mul(tsMatrix[0], g_viewMat)).xyz; float3 vNormal = normalize(mul(tsMatrix[2], g_viewMat)).xyz; #else float3 vBinormal = normalize(mul(i.binormal, worldView)).xyz; float3 vTangent = normalize(mul(i.tangent, worldView)).xyz; float3 vNormal = normalize(mul(i.normal, worldView)).xyz; #endif o.vBinormal = vBinormal; o.vTangent = vTangent; o.vNormal = vNormal; return o; }; PS_INPUT vs_main_uv2(BUMPED_VERTEX_FORMAT i) { PS_INPUT o=(PS_INPUT)0; PROJECT_POSITION( o.pos ) o.tc = i.tc; o.tc2 = i.tc2; o.wPos = worldPos.xyz; o.vPos = mul(float4(worldPos.xyz, 1.0f), g_viewMat); // // // #if SKINNED CALCULATE_TS_MATRIX float3 vBinormal = normalize(mul(tsMatrix[1], g_viewMat)).xyz; float3 vTangent = normalize(mul(tsMatrix[0], g_viewMat)).xyz; float3 vNormal = normalize(mul(tsMatrix[2], g_viewMat)).xyz; #else float3 vBinormal = normalize(mul(i.binormal, worldView)).xyz; float3 vTangent = normalize(mul(i.tangent, worldView)).xyz; float3 vNormal = normalize(mul(i.normal, worldView)).xyz; #endif o.vBinormal = vBinormal; o.vTangent = vTangent; o.vNormal = vNormal; return o; }; float4 ps_main(PS_INPUT i, uniform bool useUV2, uniform bool reflection, uniform bool lighting, uniform bool normalmapping, float face : VFACE) : COLOR0 { // // albedo // float4 albedo = tex2D(diffuseSampler, i.tc); #ifndef AIRCRAFT_OBJECT float4 camuflageMap = tex2D( camuflageSampler, i.tc ); float4 decals = 0; if(useUV2) { decals = tex2D( decalSampler, i.tc2.xy ) * max( face, 0.0 ); } albedo.rgb = lerp( lerp( camuflageMap.rgb, decals.rgb, decals.w ), albedo.rgb, albedo.w ); #else albedo.rgb = lerp( bottomColor.rgb, albedo.rgb, albedo.w); #endif // else // { // decals = 0; // } albedo = gamma_to_linear_4(albedo); // // TBN // float3 vTangent = normalize(i.vTangent); float3 vBinormal = normalize(i.vBinormal); float3 vNormal = normalize(i.vNormal); // // normal // if( normalmapping ) { float2 normalMapValue = tex2D( normalSampler, i.tc ).xy; normalMapValue.xy = normalMapValue.xy * (255.0 / 256.0) * 2.0 - 1.0; // 128 - normalmap zero value float3 tNormal = normalize(float3(normalMapValue.xy, 1.0)); tNormal = lerp(float3(0, 0, 1.0), tNormal, normalmap_weight); vNormal = float3( dot(tNormal, float3(vTangent.x, vBinormal.x, vNormal.x)), dot(tNormal, float3(vTangent.y, vBinormal.y, vNormal.y)), dot(tNormal, float3(vTangent.z, vBinormal.z, vNormal.z))); vNormal = normalize( vNormal ); } float3 wNormal = normalize(mul(float4(vNormal, 0), g_invViewMat).xyz); // // view vectors // float3 wViewVec = i.wPos - g_cameraPos; float3 vViewVec = normalize(i.vPos); float dist = length(wViewVec); wViewVec /= dist; // // fresnel term // float fresnelExp_ = 5.0; float fresnelConstant_ = 0.04; float fresnel_out = fresnel(-vViewVec, vNormal, fresnelExp_, fresnelConstant_); //TODO //float fresnel_in = fresnel(i.vLightVec.xyz, vNormal, fresnelExp, fresnelConstant); // // shadowmapping // #ifndef AIRCRAFT_OBJECT #ifdef AIRCRAFT_NO_SELFSHADOW float shadowing = 1; #else float shadowing = tex2D(selfShadowSampler, i.tc).a; #endif #else float shadowing = 1; #endif // // lighting // //materialProps - x - specular multiplier, y - glossiness (specular power), z - alpha test value, w - nonmetal parameter float4 materialProps = tex2D(specularPowerSampler, i.tc); float glossiness = materialProps.y; float glossiness_corrected = glossiness; if (glossinessOffset > 0) { glossiness_corrected = lerp(glossiness, 1.0, glossinessOffset); } else { glossiness_corrected = lerp(0, glossiness, 1.0 + glossinessOffset); } glossiness = lerp(glossiness_corrected, glossiness, albedo.w); glossiness = (gloss_const_enabled) ? gloss_const : glossiness; /* float ags = 0.9 * abs(glossiness_shift); // float glossiness_shift_power = pow(2, 2.0 * -sign(glossiness_shift) * ags / (1.0 - ags)); float glossiness_shift_power = exp(-sign(glossiness_shift) * ags / (1.0 - ags)); float gloss_remap_val = 0.7; // remap texture range glossiness = pow(glossiness, gloss_remap_val * glossiness_shift_power); */ glossiness = glossiness * 0.9999 + 0.0001; /* { float gloss_remap_val = 0.7; // remap texture range glossiness = pow(glossiness, gloss_remap_val); } */ // remap gloss texture { float gloss_remap = 0.2; float a = sqrt(0.25 + 1 / gloss_remap); glossiness = -1.0 / (gloss_remap * (glossiness + a - 0.5)) + a + 0.5; } // float specular_absorbtion = pow(glossiness, 0.5); // float specular_absorbtion = 1.0 - pow(1.0 - glossiness, 4); float NdotV = dot(wNormal, -wViewVec); // float specular_absorbtion = 1.0 - pow(1.0 - glossiness, 2.0 + 2.0 * NdotL); float invgloss = 1.0 - glossiness; float invgloss2 = invgloss * invgloss; float invgloss4 = invgloss2 * invgloss2; float invgloss8 = invgloss4 * invgloss4; float specular_absorbtion = 1.0 - lerp(invgloss2, invgloss8, NdotV); // // metalliness // // float nonmetal = camuflageMap.a * materialProps.w; #if !defined(AIRCRAFT_OBJECT) float nonmetal = (1.0 - (1.0 - camuflageMap.a) * (1.0 - decals.w)) * materialProps.w; #else // float nonmetal = materialProps.w * bottomColor.a; float nonmetal = materialProps.w * lerp(bottomColor.a, 1.0, albedo.w); #endif // nonmetal = gamma_to_linear_1(nonmetal); // float4 fresnel_complex = lerp(albedo, fresnel_out, nonmetal); // metal color defined by diffuse textures // float4 fresnel_complex = lerp(1.0, fresnel_out * specular_absorbtion, nonmetal); // metal color is 1 float4 fresnel_complex = lerp(float4(materialSpecular.xyz, 1.0), fresnel_out * specular_absorbtion, nonmetal); // metal color defined by material specular color // // lighting // float3 diffuse = 0; float3 specular = 0; if(lighting) { for (int light = 0; light < nPointLights; light++) { float3 wL = normalize( pointLights[light].position - i.wPos ); float distance = dot( pointLights[light].position - i.wPos, wL ); float attenuation = saturate((-distance + pointLights[light].attenuation.x) * pointLights[light].attenuation.y); float fresnel_in = fresnel(wL, wNormal, fresnelExp_, fresnelConstant_); attenuation *= blinn_phong_mod( wNormal, -wViewVec, normalize(pointLights[light].position - i.wPos), glossiness ).x; diffuse += pointLights[light].colour.rgb * attenuation * (1.0 - fresnel_in * specular_absorbtion); } for (int light = 0; light < nSpecularPointLights; light++) { float3 wL = normalize( specularPointLights[light].position - i.wPos ); float distance = dot( specularPointLights[light].position - i.wPos, wL ); float attenuation = saturate((-distance + specularPointLights[light].attenuation.x) * specularPointLights[light].attenuation.y); float fresnel_in = fresnel(wL, wNormal, fresnelExp_, fresnelConstant_); attenuation *= blinn_phong_mod( wNormal, -wViewVec, normalize(specularPointLights[light].position - i.wPos), glossiness ).y; specular += specularPointLights[light].colour.rgb * attenuation; } for (int light = 0; light < nSpotLights; light++) { float3 wL = normalize( spotLights[light].position - i.wPos ); float distance = dot( spotLights[light].position - i.wPos, wL ); float fresnel_in = fresnel(wL, wNormal, fresnelExp_, fresnelConstant_); float attenuation = ((-distance + spotLights[light].attenuation.x) * spotLights[light].attenuation.y) * //distance attenuation (dot( -spotLights[light].direction, wL ) -spotLights[light].attenuation.z) / (1.0 - spotLights[light].attenuation.z); //cone angle attenuation attenuation = saturate(attenuation); float4 lightLevels = blinn_phong_mod( wNormal, -wViewVec, normalize(spotLights[light].position - i.wPos), glossiness ); lightLevels *= attenuation; lightLevels.x *= (1.0 - fresnel_in * specular_absorbtion); diffuse += spotLights[light].colour.rgb * lightLevels.x; specular += spotLights[light].colour.rgb * lightLevels.y; } } // // cubemap // float4 reflectionColour = 0; if(reflection) { float3 wReflVec = reflect(wViewVec, wNormal); wReflVec = lerp(wReflVec, wNormal, invgloss8); // reflectionColour = texCUBElod(reflectionCubeSampler, float4(wReflVec, (1.0 - glossiness) * 7.0)); // reflectionColour = texCUBElod(reflectionCubeSampler, float4(wReflVec, pow((1.0 - glossiness), 1.2) * 6.0)); // reflectionColour = texCUBElod(reflectionCubeSampler, float4(wReflVec, pow((1.0 - glossiness), 1) * 4.0)); reflectionColour = texCUBElod(reflectionCubeSampler, float4(wReflVec, (1.0 - glossiness) * 6.0)); // reflectionColour.rgb = color_saturation(reflectionColour.rgb, cubemap_saturation); } //specular float reflectionMask = materialProps.x; //add reflection specular += reflectionColour.rgb; // // combine everything // float3 ambient = nonmetal * ambientColour * albedo.rgb; // TODO leave just arrived ambient light if(reflection) { // ambient = texCUBElod(reflectionCubeSampler, float4(wNormal, 5.0)) * nonmetal * albedo.rgb; // ambient = color_saturation(texCUBElod(reflectionCubeSampler, float4(wNormal, 5.0)), cubemap_saturation) * nonmetal * albedo.rgb; ambient = texCUBElod(reflectionCubeSampler, float4(wNormal, 5.0)) * nonmetal * albedo.rgb; } // float4 colour = float4( (nonmetal * albedo.rgb * diffuse + specular.rgb * reflectionMask * fresnel_complex/* * reflectionAmount*/) * shadowing + ambient, albedo.w); float4 colour = float4((nonmetal * albedo.rgb * diffuse + specular.rgb * reflectionMask * fresnel_complex) * shadowing + ambient, albedo.w); float3 fogColour = skyDomeColor(skyDomeSampler, wViewVec, -directionalLights[0].direction); float fog = opticalDepth(dist); colour.rgb = lerp(colour.rgb, fogColour, fog); #ifdef DAMAGE_TEXTURE //make holes colour.a = materialProps.z; #endif return pack_hdr_value(colour); }; #ifndef AIRCRAFT_OBJECT technique AircraftHangarHigh < bool dualUV = true; #if SKINNED bool skinned = true; #endif > { pass Pass_0 { #ifdef DAMAGE_TEXTURE ALPHATESTENABLE = TRUE; ALPHAREF = 128;//TODO REMOVE THIS( must be removed in all materials ) #else ALPHATESTENABLE = FALSE; #endif ZENABLE = TRUE; ZWRITEENABLE = TRUE; ALPHABLENDENABLE = FALSE; BW_FOG FOGENABLE = TRUE; FOGTABLEMODE = NONE; FOGVERTEXMODE = LINEAR; CULLMODE = None; VertexShader = compile vs_3_0 vs_main_uv2(); PixelShader = compile ps_3_0 ps_main(true,true,true,true); } } #endif technique AircraftHangarHigh_UV2_fallback < string link_fallback = "AircraftHangarHigh"; #if SKINNED bool skinned = true; #endif > { pass Pass_0 { #ifdef DAMAGE_TEXTURE ALPHATESTENABLE = TRUE; ALPHAREF = 128;//TODO REMOVE THIS( must be removed in all materials ) #else ALPHATESTENABLE = FALSE; #endif ZENABLE = TRUE; ZWRITEENABLE = TRUE; ALPHABLENDENABLE = FALSE; BW_FOG FOGENABLE = TRUE; FOGTABLEMODE = NONE; FOGVERTEXMODE = LINEAR; CULLMODE = None; VertexShader = compile vs_3_0 vs_main_uv1(); PixelShader = compile ps_3_0 ps_main(false,true,true,true); } } shaders.zip 2 Quote Share this post Link to post Short link Share on other sites