update image material to support cubemaps
This commit is contained in:
@@ -5,6 +5,10 @@ material {
|
|||||||
type : sampler2d,
|
type : sampler2d,
|
||||||
name : image
|
name : image
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type : samplerCubemap,
|
||||||
|
name : cubeMap
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type : mat4,
|
type : mat4,
|
||||||
name : transform,
|
name : transform,
|
||||||
@@ -17,6 +21,14 @@ material {
|
|||||||
{
|
{
|
||||||
type : int,
|
type : int,
|
||||||
name : showImage
|
name : showImage
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type : int,
|
||||||
|
name : isCubeMap
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type : int,
|
||||||
|
name : cubeMapFace
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
variables : [
|
variables : [
|
||||||
@@ -36,14 +48,45 @@ vertex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fragment {
|
fragment {
|
||||||
|
vec3 getDirectionForCubeFace(int face, vec2 uv) {
|
||||||
|
vec2 st = uv * 2.0 - 1.0; // Convert [0,1] to [-1,1]
|
||||||
|
|
||||||
|
if (face == 0) { // +X
|
||||||
|
return normalize(vec3(1.0, -st.y, -st.x));
|
||||||
|
} else if (face == 1) { // -X
|
||||||
|
return normalize(vec3(-1.0, -st.y, st.x));
|
||||||
|
} else if (face == 2) { // +Y
|
||||||
|
return normalize(vec3(st.x, 1.0, st.y));
|
||||||
|
} else if (face == 3) { // -Y
|
||||||
|
return normalize(vec3(st.x, -1.0, -st.y));
|
||||||
|
} else if (face == 4) { // +Z
|
||||||
|
return normalize(vec3(st.x, -st.y, 1.0));
|
||||||
|
} else { // -Z (face == 5)
|
||||||
|
return normalize(vec3(-st.x, -st.y, -1.0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void material(inout MaterialInputs material) {
|
void material(inout MaterialInputs material) {
|
||||||
prepareMaterial(material);
|
prepareMaterial(material);
|
||||||
highp vec2 uv = (materialParams.transform * vec4(saturate(variable_imageUV.st), 1.0, 1.0)).st;
|
highp vec2 uv = (materialParams.transform * vec4(saturate(variable_imageUV.st), 1.0, 1.0)).st;
|
||||||
|
|
||||||
if (materialParams.showImage == 0 || uv.s > 1.0 || uv.s < 0.0 || uv.t < 0.0 || uv.t > 1.0) {
|
if (materialParams.showImage == 0 || uv.s > 1.0 || uv.s < 0.0 || uv.t < 0.0 || uv.t > 1.0) {
|
||||||
material.baseColor = materialParams.backgroundColor;
|
material.baseColor = materialParams.backgroundColor;
|
||||||
} else {
|
} else {
|
||||||
uv.t = 1.0 - uv.t;
|
vec4 color;
|
||||||
vec4 color = max(texture(materialParams_image, uv.st), 0.0);
|
|
||||||
|
if (materialParams.isCubeMap != 0) {
|
||||||
|
// Sample cubemap using direction vector for specified face
|
||||||
|
vec2 cubeUv = uv;
|
||||||
|
cubeUv.t = 1.0 - cubeUv.t; // Flip V coordinate
|
||||||
|
vec3 direction = getDirectionForCubeFace(materialParams.cubeMapFace, cubeUv);
|
||||||
|
color = max(texture(materialParams_cubeMap, direction), 0.0);
|
||||||
|
} else {
|
||||||
|
// Regular 2D texture sampling
|
||||||
|
uv.t = 1.0 - uv.t;
|
||||||
|
color = max(texture(materialParams_image, uv.st), 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
color.rgb *= color.a;
|
color.rgb *= color.a;
|
||||||
// Manual, pre-multiplied srcOver with opaque destination optimization
|
// Manual, pre-multiplied srcOver with opaque destination optimization
|
||||||
material.baseColor.rgb = color.rgb + materialParams.backgroundColor.rgb * (1.0 - color.a);
|
material.baseColor.rgb = color.rgb + materialParams.backgroundColor.rgb * (1.0 - color.a);
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ IMAGE_PACKAGE:
|
|||||||
IMAGE_IMAGE_OFFSET:
|
IMAGE_IMAGE_OFFSET:
|
||||||
.int 0
|
.int 0
|
||||||
IMAGE_IMAGE_SIZE:
|
IMAGE_IMAGE_SIZE:
|
||||||
.int 63850
|
.int 78666
|
||||||
|
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ _IMAGE_PACKAGE:
|
|||||||
_IMAGE_IMAGE_OFFSET:
|
_IMAGE_IMAGE_OFFSET:
|
||||||
.int 0
|
.int 0
|
||||||
_IMAGE_IMAGE_SIZE:
|
_IMAGE_IMAGE_SIZE:
|
||||||
.int 63850
|
.int 78666
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user