Skip to content

V3.3 material examples #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: v3.3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions show-material/assets/effects/bluex-rt.effect
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Effect Syntax Guide: https://github.com/cocos-creator/docs-3d/blob/master/zh/material-system/effect-syntax.md

CCEffect %{
techniques:
- name: opaque
passes:
- vert: general-vs:vert # builtin header
frag: unlit-fs:frag
properties: &props
mainTexture: { value: white }
mainColor: { value: [1, 1, 1, 1], editor: { type: color } }
blurColor: { value: [1, 1, 1, 1] }
- name: transparent
passes:
- vert: general-vs:vert # builtin header
frag: unlit-fs:frag
blendState:
targets:
- blend: true
blendSrc: src_alpha
blendDst: one_minus_src_alpha
blendSrcAlpha: src_alpha
blendDstAlpha: one_minus_src_alpha
properties: *props
}%

CCProgram unlit-fs %{
precision highp float;
#include <output>
#include <cc-fog-fs>


in vec2 v_uv;
uniform sampler2D mainTexture;

uniform Constant {
vec4 mainColor;
vec4 blurColor;

};

vec4 frag () {

vec2 pixelSize;

pixelSize.x = 1.0/blurColor.x;
pixelSize.y = 1.0/blurColor.y;

float pixW = pixelSize.x, pixH = pixelSize.y;


vec2 vTexcoord = v_uv;

float weight3[7];
weight3[0] = 0.0;
weight3[1] = 0.0;
weight3[2] = 1.0;
weight3[3] = 2.0;
weight3[4] = 1.0;
weight3[5] = 0.0;
weight3[6] = 0.0;



float weight2[7];
weight2[0] = 0.0;
weight2[1] = 3.0;
weight2[2] = 13.0;
weight2[3] = 22.0;
weight2[4] = 13.0;
weight2[5] = 3.0;
weight2[6] = 0.0;

float weight1[7];
weight1[0] = 1.0;
weight1[1] = 13.0;
weight1[2] = 59.0;
weight1[3] = 97.0;
weight1[4] = 59.0;
weight1[5] = 13.0;
weight1[6] = 1.0;

float weight0[7];
weight0[0] = 2.0;
weight0[1] = 22.0;
weight0[2] = 97.0;
weight0[3] = 159.0;
weight0[4] = 97.0;
weight0[5] = 22.0;
weight0[6] = 2.0;



vec4 sum = mainColor * texture(mainTexture, vTexcoord);

#if gaussian

sum = mainColor * texture(mainTexture, vTexcoord) * 0.0;
float weightsum = 0.0;
for (int j = -3;j <= 3; j++ ){

sum += texture(mainTexture, vTexcoord + vec2(pixW * float(-3), pixH * float(j))) * weight3[j+3];
sum += texture(mainTexture, vTexcoord + vec2(pixW * float(-2), pixH * float(j))) * weight2[j+3];
sum += texture(mainTexture, vTexcoord + vec2(pixW * float(-1), pixH * float(j))) * weight1[j+3];
sum += texture(mainTexture, vTexcoord + vec2(pixW * float(0), pixH * float(j))) * weight0[j+3];
sum += texture(mainTexture, vTexcoord + vec2(pixW * float(1), pixH * float(j))) * weight1[j+3];
sum += texture(mainTexture, vTexcoord + vec2(pixW * float(2), pixH * float(j))) * weight2[j+3];
sum += texture(mainTexture, vTexcoord + vec2(pixW * float(3), pixH * float(j))) * weight3[j+3];

weightsum += weight3[j+3];
weightsum += weight2[j+3];
weightsum += weight1[j+3];
weightsum += weight0[j+3];
weightsum += weight1[j+3];
weightsum += weight2[j+3];
weightsum += weight3[j+3];
}


sum /= weightsum;

#endif



CC_APPLY_FOG(sum);
return CCFragOutput(sum);






}
}%
11 changes: 11 additions & 0 deletions show-material/assets/effects/bluex-rt.effect.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ver": "1.4.6",
"importer": "effect",
"imported": true,
"uuid": "f99a30bd-fc3f-4eb5-a229-12f3d921a662",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}
12 changes: 11 additions & 1 deletion show-material/assets/effects/maorong0fresnel.effect.meta
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
{"ver":"1.4.6","importer":"effect","imported":true,"uuid":"71a2c447-e2a0-4fa5-94ab-c79f9152c2b0","files":[".json"],"subMetas":{},"userData":{}}
{
"ver": "1.4.6",
"importer": "effect",
"imported": true,
"uuid": "71a2c447-e2a0-4fa5-94ab-c79f9152c2b0",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}
114 changes: 114 additions & 0 deletions show-material/assets/effects/shading-standard-base-jelly2-blurx.chunk
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
// reference: 'moving frostbite to pbr' & UE4 BRDF.usf

#include <cc-global>
#include <common>
#include <gamma>
#include <cc-shadow-map-base>

#if CC_USE_IBL
#include <cc-environment>
#include <unpack>
#include <texture-lod>
#endif

float GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {
vec3 NxH = cross(N, H);
float OneMinusNoHSqr = dot(NxH, NxH);
float a = roughness * roughness;
float n = NoH * a;
float p = a / (OneMinusNoHSqr + n * n);
return p * p;
}

float CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {
return (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);
}

vec3 BRDFApprox (vec3 specular, float roughness, float NoV) {
const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);
const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);
vec4 r = roughness * c0 + c1;
float a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;
vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;
AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);
return specular * AB.x + AB.y;
}

struct StandardSurface {
// albedo
vec4 albedo;
// these two need to be in the same coordinate system
vec3 position;
vec3 normal;
// emissive
vec3 emissive;
// light map
vec3 lightmap;
float lightmap_test;
// PBR params
float roughness;
float metallic;
float occlusion;
float IBL;
};

vec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {
// Calculate diffuse & specular
vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);
vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);

vec3 N = normalize(s.normal);
vec3 V = normalize(cc_cameraPos.xyz - s.position);

float NV = max(abs(dot(N, V)), 0.001);
specular = BRDFApprox(specular, s.roughness, NV);

vec3 L = normalize(-cc_mainLitDir.xyz);
vec3 H = normalize(L + V);
float NH = max(dot(N, H), 0.0);
float NL = max(dot(N, L), 0.001);
vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;
vec3 diffuseContrib = diffuse;

#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD
if (s.lightmap_test > 0.0001) {
finalColor = s.lightmap.rgb;
}
#else
diffuseContrib /= PI;
#endif

// Cook-Torrance Microfacet Specular BRDF
vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);

finalColor *= (diffuseContrib);// + specularContrib);

float fAmb = 0.5 - N.y * 0.5;
vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;
finalColor += (ambDiff.rgb * diffuse);

// #if CC_USE_IBL
// vec3 R = normalize(reflect(-V, N));
// vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);
// #if CC_USE_IBL == IBL_RGBE
// vec3 env = unpackRGBE(envmap);
// #else
// vec3 env = SRGBToLinear(envmap.rgb);
// #endif
// finalColor += env * cc_ambientSky.w * specular * s.IBL;
// #endif

// finalColor = finalColor * s.occlusion;

// #if CC_USE_HDR
// s.emissive *= cc_exposure.w;
// #endif
// finalColor += s.emissive;

#if CC_RECEIVE_SHADOW
CC_SHADOW_FACTOR_BASE(finalColor, NL, shadowPos, L, N);
#endif

return vec4(finalColor, s.albedo.a);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ver": "1.0.0",
"importer": "effect-header",
"imported": true,
"uuid": "2eee4ea5-2cbc-40f9-bce4-35e2485e0fa9",
"files": [],
"subMetas": {},
"userData": {}
}
Loading