summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorDave Parks <davep@lindenlab.com>2022-10-21 16:34:14 -0500
committerDave Parks <davep@lindenlab.com>2022-10-21 16:34:14 -0500
commit61967623baaa8988f4f8b48043f79be29452ca80 (patch)
treee35ef542a804e4acd11baa1d0bee989e97582989 /indra
parent24fb2f83362f3aaffed42360f750bc4c82037c39 (diff)
SL-18105 Clean up class1/deferred/materialF.glsl (merge cleanup), make override messaging LLSD where it ought to be and JSON where it ought to be.
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/materialF.glsl188
-rw-r--r--indra/newview/llgltfmateriallist.cpp72
-rw-r--r--indra/newview/llmaterialeditor.cpp40
3 files changed, 52 insertions, 248 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
index 70ae615d46..51a36935f2 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
@@ -23,6 +23,7 @@
* $/LicenseInfo$
*/
+
/*[EXTRA_CODE_HERE]*/
//class1/deferred/materialF.glsl
@@ -37,192 +38,15 @@ out vec4 frag_color;
out vec4 frag_data[4];
#endif
-#ifdef HAS_SUN_SHADOW
-float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);
-#endif
-
-uniform samplerCube environmentMap;
-uniform sampler2D lightFunc;
-
-// Inputs
-uniform vec4 morphFactor;
-uniform vec3 camPosLocal;
-uniform mat3 env_mat;
-
-uniform vec3 sun_dir;
-uniform vec3 moon_dir;
-VARYING vec2 vary_fragcoord;
-
-VARYING vec3 vary_position;
-
-uniform mat4 proj_mat;
-uniform mat4 inv_proj;
-uniform vec2 screen_res;
-
-uniform vec4 light_position[8];
-uniform vec3 light_direction[8];
-uniform vec4 light_attenuation[8];
-uniform vec3 light_diffuse[8];
-
-float getAmbientClamp();
-
-vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare, float ambiance)
-{
- // SL-14895 inverted attenuation work-around
- // This routine is tweaked to match deferred lighting, but previously used an inverted la value. To reconstruct
- // that previous value now that the inversion is corrected, we reverse the calculations in LLPipeline::setupHWLights()
- // to recover the `adjusted_radius` value previously being sent as la.
- float falloff_factor = (12.0 * fa) - 9.0;
- float inverted_la = falloff_factor / la;
- // Yes, it makes me want to cry as well. DJH
-
- vec3 col = vec3(0);
-
- //get light vector
- vec3 lv = lp.xyz - v;
-
- //get distance
- float dist = length(lv);
- float da = 1.0;
-
- dist /= inverted_la;
-
- if (dist > 0.0 && inverted_la > 0.0)
- {
- //normalize light vector
- lv = normalize(lv);
-
- //distance attenuation
- float dist_atten = clamp(1.0 - (dist - 1.0*(1.0 - fa)) / fa, 0.0, 1.0);
- dist_atten *= dist_atten;
- dist_atten *= 2.0f;
-
- if (dist_atten <= 0.0)
- {
- return col;
- }
-
- // spotlight coefficient.
- float spot = max(dot(-ln, lv), is_pointlight);
- da *= spot*spot; // GL_SPOT_EXPONENT=2
-
- //angular attenuation
- da *= dot(n, lv);
-
- float lit = 0.0f;
-
- float amb_da = ambiance;
- if (da >= 0)
- {
- lit = max(da * dist_atten, 0.0);
- col = lit * light_col * diffuse;
- amb_da += (da*0.5 + 0.5) * ambiance;
- }
- amb_da += (da*da*0.5 + 0.5) * ambiance;
- amb_da *= dist_atten;
- amb_da = min(amb_da, 1.0f - lit);
-
- // SL-10969 need to see why these are blown out
- //col.rgb += amb_da * light_col * diffuse;
-
- if (spec.a > 0.0)
- {
- //vec3 ref = dot(pos+lv, norm);
- vec3 h = normalize(lv + npos);
- float nh = dot(n, h);
- float nv = dot(n, npos);
- float vh = dot(npos, h);
- float sa = nh;
- float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5;
-
- float gtdenom = 2 * nh;
- float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
-
- if (nh > 0.0)
- {
- float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da);
- vec3 speccol = lit*scol*light_col.rgb*spec.rgb;
- speccol = clamp(speccol, vec3(0), vec3(1));
- col += speccol;
-
- float cur_glare = max(speccol.r, speccol.g);
- cur_glare = max(cur_glare, speccol.b);
- glare = max(glare, speccol.r);
- glare += max(cur_glare, 0.0);
- }
- }
- }
-
- return max(col, vec3(0.0, 0.0, 0.0));
-}
-
-#else
-#ifdef DEFINE_GL_FRAGCOLOR
-out vec4 frag_data[3];
-#else
-#define frag_data gl_FragData
-#endif
-#endif
-
-uniform sampler2D diffuseMap; //always in sRGB space
-
-#ifdef HAS_NORMAL_MAP
-uniform sampler2D bumpMap;
-#endif
-
-#ifdef HAS_SPECULAR_MAP
-uniform sampler2D specularMap;
-
-VARYING vec2 vary_texcoord2;
-#endif
-
-uniform float env_intensity;
-uniform vec4 specular_color; // specular color RGB and specular exponent (glossiness) in alpha
-
-#ifdef HAS_ALPHA_MASK
-uniform float minimum_alpha;
-#endif
-
-#ifdef HAS_NORMAL_MAP
-VARYING vec3 vary_mat0;
-VARYING vec3 vary_mat1;
-VARYING vec3 vary_mat2;
-VARYING vec2 vary_texcoord1;
-#else
-VARYING vec3 vary_normal;
-#endif
-
-VARYING vec4 vertex_color;
-VARYING vec2 vary_texcoord0;
-
-vec2 encode_normal(vec3 n);
-
void main()
{
- vec2 pos_screen = vary_texcoord0.xy;
-
- vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy);
- diffcol.rgb *= vertex_color.rgb;
-
-#ifdef HAS_ALPHA_MASK
-#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND
- if (diffcol.a*vertex_color.a < minimum_alpha)
-#else
- if (diffcol.a < minimum_alpha)
-#endif
- {
- discard;
- }
-#endif
-
#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
- frag_color = vec4(1,0,0,0.5);
+ frag_color = vec4(1, 0, 0, 0.5);
#else
// emissive red PBR material
- frag_data[0] = vec4(0,0,0,0);
- frag_data[1] = vec4(0,0,0,0);
- frag_data[2] = vec4(1,0,0,GBUFFER_FLAG_HAS_PBR);
- frag_data[3] = vec4(1,0,0,0);
+ frag_data[0] = vec4(0, 0, 0, 0);
+ frag_data[1] = vec4(0, 0, 0, 0);
+ frag_data[2] = vec4(1, 0, 0, GBUFFER_FLAG_HAS_PBR);
+ frag_data[3] = vec4(1, 0, 0, 0);
#endif
}
-
diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp
index 0a104d1db5..88923ba734 100644
--- a/indra/newview/llgltfmateriallist.cpp
+++ b/indra/newview/llgltfmateriallist.cpp
@@ -45,59 +45,57 @@
namespace
{
- class LLGLTFOverrideDispatchHandler : public LLDispatchHandler
+ class LLGLTFMaterialOverrideDispatchHandler : public LLDispatchHandler
{
- LOG_CLASS(LLGLTFOverrideDispatchHandler);
+ LOG_CLASS(LLGLTFMaterialOverrideDispatchHandler);
public:
- LLGLTFOverrideDispatchHandler() = default;
- ~LLGLTFOverrideDispatchHandler() override = default;
+ LLGLTFMaterialOverrideDispatchHandler() = default;
+ ~LLGLTFMaterialOverrideDispatchHandler() override = default;
bool operator()(const LLDispatcher* dispatcher, const std::string& key, const LLUUID& invoice, const sparam_t& strings) override
{
- // iterate over pairs of parameters
- int i;
- for (i = 0; i+1 < strings.size(); i += 2)
- {
- std::string params_json = strings[i];
- std::string override_json = strings[i+1];
+ // receive override data from simulator via LargeGenericMessage
+ // message should have:
+ // object_id - UUID of LLViewerObject
+ // side - S32 index of texture entry
+ // gltf_json - String of GLTF json for override data
+
- LL_DEBUGS() << "received override: " << params_json << " | " << override_json << LL_ENDL;
+ LLSD message;
- Json::Value params;
- Json::Reader reader;
- bool success = reader.parse(params_json, params);
- if (!success)
+ sparam_t::const_iterator it = strings.begin();
+ if (it != strings.end()) {
+ const std::string& llsdRaw = *it++;
+ std::istringstream llsdData(llsdRaw);
+ if (!LLSDSerialize::deserialize(message, llsdData, llsdRaw.length()))
{
- LL_WARNS() << "failed to parse override parameters. errors: " << reader.getFormatedErrorMessages() << LL_ENDL;
- break;
+ LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL;
}
-
- LLViewerObject * obj = gObjectList.findObject(LLUUID(params["object_id"].asString()));
- S32 side = params["side"].asInt();
-
- std::string warn_msg, error_msg;
- LLPointer<LLGLTFMaterial> override_data = new LLGLTFMaterial();
- success = override_data->fromJSON(override_json, warn_msg, error_msg);
-// if (!success)
-// {
-// LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL;
-// break;
-// }
-
- if(obj)
+ }
+
+ LLViewerObject * obj = gObjectList.findObject(message["object_id"].asUUID());
+ S32 side = message["side"].asInteger();
+ std::string gltf_json = message["gltf_json"].asString();
+
+ std::string warn_msg, error_msg;
+ LLPointer<LLGLTFMaterial> override_data = new LLGLTFMaterial();
+ bool success = override_data->fromJSON(gltf_json, warn_msg, error_msg);
+ if (!success)
+ {
+ LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL;
+ }
+ else
+ {
+ if (obj)
{
obj->setTEGLTFMaterialOverride(side, override_data);
}
-
- LL_DEBUGS() << "successfully parsed override: " << override_data->asJSON() << LL_ENDL;
}
- LL_WARNS_IF(i != strings.size()) << "parse error or unhandled mismatched odd number of parameters for material override" << LL_ENDL;
-
return true;
}
};
- LLGLTFOverrideDispatchHandler handle_gltf_override_message;
+ LLGLTFMaterialOverrideDispatchHandler handle_gltf_override_message;
}
LLGLTFMaterialList gGLTFMaterialList;
@@ -256,5 +254,5 @@ void LLGLTFMaterialList::flushMaterials()
// static
void LLGLTFMaterialList::registerCallbacks()
{
- gGenericDispatcher.addHandler("GLTF", &handle_gltf_override_message);
+ gGenericDispatcher.addHandler("GLTFMaterialOverride", &handle_gltf_override_message);
}
diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp
index c5cdb81d67..58894dbd69 100644
--- a/indra/newview/llmaterialeditor.cpp
+++ b/indra/newview/llmaterialeditor.cpp
@@ -1872,42 +1872,24 @@ public:
bool apply(LLViewerObject* objectp, S32 te) override
{
+ // post override from given object and te to the simulator
+ // requestData should have:
+ // object_id - UUID of LLViewerObject
+ // side - S32 index of texture entry
+ // gltf_json - String of GLTF json for override data
+
if (objectp && objectp->permModify() && objectp->getVolume())
{
- //LLVOVolume* vobjp = (LLVOVolume*)objectp;
- S32 local_id = objectp->getLocalID();
-
LLPointer<LLGLTFMaterial> material = new LLGLTFMaterial();
- LLPointer<LLGLTFMaterial> base;
+
mEditor->getGLTFMaterial(material);
- tinygltf::Model model_out;
-
- if(mAssetID != LLUUID::null)
- {
- base = gGLTFMaterialList.getMaterial(mAssetID);
- material->writeOverridesToModel(model_out, 0, base);
- }
- else
- {
- material->writeToModel(model_out, 0);
- }
-
- std::string overrides_json;
- {
- tinygltf::TinyGLTF gltf;
- std::ostringstream str;
-
- gltf.WriteGltfSceneToStream(&model_out, str, false, false);
-
- overrides_json = str.str();
- LL_DEBUGS() << "overrides_json " << overrides_json << LL_ENDL;
- }
-
+ std::string overrides_json = material->asJSON();
+
LLSD overrides = llsd::map(
- "local_id", local_id,
+ "object_id", objectp->getID(),
"side", te,
- "overrides", overrides_json
+ "gltf_json", overrides_json
);
LLCoros::instance().launch("modifyMaterialCoro", std::bind(&LLMaterialEditor::modifyMaterialCoro, mEditor, mCapUrl, overrides));
}