Multiply two textures via Shader

General questions about Indigo, the scene format, rendering etc...
User avatar
delle
Posts: 175
Joined: Fri Apr 13, 2007 11:32 pm
Location: Italy

Multiply two textures via Shader

Post by delle » Tue Dec 16, 2008 10:53 pm

Hi, I'm trying to multiply the colors of two textures via Indigo Shading Language, but I'm not able to find a solution...

What I need to obtain is:

Code: Select all

result.red = Texture0.red * Texture1.red
result.green = Texture0.green * Texture1.green
result.blue= Texture0.blue* Texture1.blue
I can only obtain a mix of the two (50% Texture0+ 50% Texture1) but is not what I want... :cry:

Code: Select all

<albedo>
          <shader>
            <shader>
              <![CDATA[
                def eval(vec3 pos) vec3 : lerp(sample2DTextureVec3(0,getTexCoords(0)),sample2DTextureVec3(1,getTexCoords(0)),0.5)
              ]]>
            </shader>
          </shader>
        </albedo>
Please help

Delle

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Post by fused » Tue Dec 16, 2008 11:09 pm

have a look at doti() dotj() and dotk().

they give you access to the x,y,z components of a vec3.

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Thu Dec 18, 2008 5:16 am

just before you're doing that: you want things getting darker? 'cause multiplying in the range of 0->1 makes things either smaller (darker) or doesn't change them.
0*0 = 0
1*1 = 1
(the only two cases where things stay the same)
and
0.5*0.5=0.25
etc... ^^
Last edited by Kram1032 on Thu Dec 18, 2008 6:52 am, edited 1 time in total.

User avatar
PureSpider
Posts: 1459
Joined: Tue Apr 08, 2008 9:37 am
Location: Karlsruhe, BW, Germany
Contact:

Post by PureSpider » Thu Dec 18, 2008 5:32 am

Kram1032 wrote:0.5*0.5=0.5
Interesting... 1+1=3, right?

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Thu Dec 18, 2008 6:52 am

I'm sure, I hit the 2... probably hanged or so :?

User avatar
delle
Posts: 175
Joined: Fri Apr 13, 2007 11:32 pm
Location: Italy

Post by delle » Thu Dec 18, 2008 10:00 pm

What I have to do is to multiply the color of two textures and/or multiply one solid color by a grayscale texture (such as RedColor * GrayTexure).

So I have to do two tasks:
  • OutColor = ColorTexture * ColorTexture
    OutColor = SolidColor * GrayscaleTexture
I know... I can do it offline and then to pass the computed texture to Indigo, but since we have shaders ... why don't use them... :wink:

Any suggestion?

Delle

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Post by fused » Thu Dec 18, 2008 10:36 pm

delle wrote:What I have to do is to multiply the color of two textures and/or multiply one solid color by a grayscale texture (such as RedColor * GrayTexure).

So I have to do two tasks:
  • OutColor = ColorTexture * ColorTexture
    OutColor = SolidColor * GrayscaleTexture
I know... I can do it offline and then to pass the computed texture to Indigo, but since we have shaders ... why don't use them... :wink:

Any suggestion?

Delle
try this (multipies each component of color1 with the component of color2):

Code: Select all

<albedo>
          <shader>
            <shader>
              <![CDATA[
                def multiplyColor(vec3 col1, vec3 col2) vec3:
                vec3(
                    mul(doti(col1),doti(col2)),
                    mul(dotj(col1),dotj(col2)),
                    mul(dotk(col1),dotk(col2)))
                
                def eval(vec3 pos) vec3 :
                multiplyColor(sample2DTextureVec3(0,getTexCoords(0)),sample2DTextureVec3(1,getTexCoords(0)))
              ]]>
            </shader>
          </shader>
        </albedo> 
not tested :)

User avatar
delle
Posts: 175
Joined: Fri Apr 13, 2007 11:32 pm
Location: Italy

Indigo Shader Bug?

Post by delle » Fri Dec 19, 2008 5:24 am

With this Scene (GLEditor.zip) I get this error:
Shader runtime error: No texture with index 0
But the texture "0" is present

I think that this might be an Indigo error... :roll:

Indigo: 1.1.15
Exporter: Custom exporter

Delle
Attachments
IndigoError.PNG
IndigoError.PNG (8.47 KiB) Viewed 4002 times
GLEditor.zip
(105.87 KiB) Downloaded 178 times

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Post by fused » Fri Dec 19, 2008 6:52 am

didnt have a look at your scene, but make sure that your textures are defined before the albedo element.

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Post by fused » Fri Dec 19, 2008 7:29 am

works fine here :)
Attachments
im1229627375.JPG
im1229627375.JPG (227.93 KiB) Viewed 3974 times

User avatar
delle
Posts: 175
Joined: Fri Apr 13, 2007 11:32 pm
Location: Italy

Post by delle » Fri Dec 19, 2008 10:05 pm

Hi Fused, I've restricted the problem....

This Material works...

Code: Select all

<material> 
      <name>Material_4</name>
      <diffuse>
        <texture>
          <uv_set>default</uv_set>
          <path>.\GLEditor\ASHWOOD_IMG1_V1.bmp</path>
          <exponent>2.2</exponent>
          <b>1</b>
          <c>0</c>
        </texture>
        <albedo>
          <shader>
            <shader>
              <![CDATA[
                def multiplyColor(vec3 col1, vec3 col2) vec3: vec3(mul(doti(col1),doti(col2)),mul(dotj(col1),dotj(col2)),mul(dotk(col1),dotk(col2)))
                def eval(vec3 pos) vec3 : multiplyColor(sample2DTextureVec3(0,getTexCoords(0)),vec3(0.301961,0.149020,0.000000))
              ]]>
            </shader>
          </shader>
        </albedo>
      </diffuse>
    </material>
This does not work (same texture plus little blending between diffuse and phong sub-materials)

Code: Select all

<material> 
      <name>Material_4_Diffuse</name>
      <diffuse>
        <texture>
          <uv_set>default</uv_set>
          <path>.\GLEditor\ASHWOOD_IMG1_V1.bmp</path>
          <exponent>2.2</exponent>
          <b>1</b>
          <c>0</c>
        </texture>
        <albedo>
          <shader>
            <shader>
              <![CDATA[
                def multiplyColor(vec3 col1, vec3 col2) vec3: vec3(mul(doti(col1),doti(col2)),mul(dotj(col1),dotj(col2)),mul(dotk(col1),dotk(col2)))
                def eval(vec3 pos) vec3 : multiplyColor(sample2DTextureVec3(0,getTexCoords(0)),vec3(0.301961,0.149020,0.000000))
              ]]>
            </shader>
          </shader>
        </albedo>
      </diffuse>
    </material>

    <material> 
      <name>Material_4_Specular</name>
      <phong>
        <texture>
          <uv_set>default</uv_set>
          <path>.\GLEditor\ASHWOOD_IMG1_V1.bmp</path>
          <exponent>2.2</exponent>
          <b>1</b>
          <c>0</c>
        </texture>
        <diffuse_albedo>
          <shader>
            <shader>
              <![CDATA[
                def multiplyColor(vec3 col1, vec3 col2) vec3: vec3(mul(doti(col1),doti(col2)),mul(dotj(col1),dotj(col2)),mul(dotk(col1),dotk(col2)))
                def eval(vec3 pos) vec3 : multiplyColor(sample2DTextureVec3(0,getTexCoords(0)),vec3(0.301961,0.149020,0.000000))
              ]]>
            </shader>
          </shader>
        </diffuse_albedo>
        <ior>1.550000</ior>
        <exponent><constant>70.250000</constant></exponent>
        <fresnel_scale>1.0</fresnel_scale>
      </phong>
    </material>

    <material>
      <name>Material_4</name>
      <blend>
        <a_name>Material_4_Diffuse</a_name>
        <b_name>Material_4_Specular</b_name>
        <blend>
          <constant>0.650000</constant>
        </blend>
      </blend>
    </material>
Can you help me?

Thank you

Delle

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Post by fused » Fri Dec 19, 2008 10:17 pm

i cant test it right now, but it seems to be correct.
you are aware that those two shaders are identical and blending the materials will do pretty much nothing? is there an error message?

oh... and throw out the <fresnel_scale> element. it has no effect.
Last edited by fused on Fri Dec 19, 2008 11:42 pm, edited 1 time in total.

User avatar
delle
Posts: 175
Joined: Fri Apr 13, 2007 11:32 pm
Location: Italy

Post by delle » Fri Dec 19, 2008 11:28 pm

Code: Select all

...are aware that those two shaders are identical...
Yes I know, but with the blend, the problem appears... :roll:

Delle

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Post by fused » Fri Dec 19, 2008 11:41 pm

then, whats the problem? :)

User avatar
delle
Posts: 175
Joined: Fri Apr 13, 2007 11:32 pm
Location: Italy

Post by delle » Fri Dec 19, 2008 11:44 pm

The problem is that I must blend diffuse and phong material...

:wink:

Post Reply
23 posts

Who is online

Users browsing this forum: No registered users and 7 guests